Hello,
I have a problem with wrong value in energy dashboard after restart HA. Value is increased by 100%. It is probably due to sensor report zero value after restart. Data is read from wattrouter via modbus. All sensors have state_class total_increasing. I will be very grateful for advice on how to treat the sensor to show no zero value. There are several topics with similar problem but without clear solutions
- unique_id: wattrouter_grid_consumption_nt #spotřeva energie ze sítě NT aktuální den
name: "Wattrouter spotřeba ze sítě NT"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: "{{ (states('sensor.wattrouter1_statistic_1')) | int(0) / 1000 | round(2, default=0) }}"
I too come across this same issue from time to time. You can manually adjust the statistics values for specific entities.
Go to Developer Tools > Statistics, then search for your specific entity that is showing the incorrect value, then on the far right side of the row look for
Click that icon to open the ‘adjust a statistic’ dialog, then you can find the offending value for the specific date/time that you see in the energy dashboard.
Hi David, I use more sensor from same device (wattrouter) via modbus. All sensors have same problem. Problem was appear itself several weeks ago. I guess after some update HA. Not sure. Sensors are reset by device at the midnight. I guess problem is due to sensors have wrong value before modbus connection is created. I have inserted delay for modbus communication but no success. I attached graph of two sensors in the range of 3 days. You can see several wrong values (drop to zero)
Hmm, I was looking through the code but it looks the native value is set initially to none (which means Unknown). I guess you’ll need to raise a github issue so someone more familiar with the integration code can take a look.
I guess when modbus start to communicate sensor has state undefined, unavailable etc. But I do not have this state treated and change it direct to zero by round function (default=0)
Ah I see, so that showed sensor is not directly from the integration but yours.
So exactly that rounding w/ default to 0 is causing you the issue.
But it worked before without problem
You could have been just lucky but it doesn’t change the fact that your template is wrong and you shouldn’t have done it that way. Remove that default and you will be good.
I have done some changes in code and it looks good. Problem disappeared.
Before:
- unique_id: wattrouter_grid_consumption_nt #spotřeva energie ze sítě NT aktuální den
name: "Wattrouter spotřeba ze sítě NT"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: "{{ (states('sensor.wattrouter1_statistic_1')) | int(0) / 1000 | round(2, default=0) }}"
after:
- unique_id: wattrouter_grid_consumption_nt #spotřeva energie ze sítě NT aktuální den
name: "Wattrouter spotřeba ze sítě NT"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: "{{ (states('sensor.wattrouter1_statistic_1')) | int(0) / 1000 | round(2) }}"
availability: "{{ is_number(states('sensor.wattrouter1_statistic_1')) }}"
Also I found the problem with wrong value arise immediately before restart. Not after reboot. Probably modbus integration is shutdown earlier than rest of HA. At least I think so because problem disappeared only after second restart of HA.