StyraHem / ShellyForHASS

Shelly smart home platform for Home Assistant
MIT License
615 stars 110 forks source link

[BUG] Wrong total consumption #638

Open TheCherry opened 2 years ago

TheCherry commented 2 years ago

Environment

I use a Shelly Plus 1PM with FW 0.9.1. The "Total consumption" in HASS is totaly wrong, I have the Shelly running since few days by 1165 W and the total consumption shows only 0.81 kWh.

image

danygi79 commented 2 years ago

I have same problem at Shelly Pro 4PM. all other device show this value correct.

mdzmdz commented 2 years ago

I have the same issue, also Shelly Pro 4PM.

MaxRink commented 2 years ago

I can also see thais behaviour on all my "plus" devices, the consuption is off by a huge factor image doesnt match with image

mdzmdz commented 2 years ago

I used MQTT explorer to monitor the traffic between HA and MQTT server The results are strange: {"id":0, "source":"MQTT", "output":true, "apower":9.1, "voltage":229.9, "current":0.198, "pf":-0.51, "aenergy":{"total":8711.160,"by_minute":[15.500,23.776,23.250],"minute_ts":1647977137},"temperature":{"tC":32.0, "tF":89.6}}

Power 9,1W and voltage 229,9 implies current 0,03958A, not 0.198. Power and voltage are as expected, so the current must be wrong. Also, the total consumption seems to be wrong. I calculated difference in the 20min interval. {"id":0, "source":"MQTT", "output":true, "apower":8.9, "voltage":230.5, "current":0.198, "pf":0.00, "aenergy":{"total":8711.669,"by_minute":[15.894,25.089,24.170],"minute_ts":1647978340},"temperature":{"tC":31.5, "tF":88.8}} It should be about 3Wh, but the difference is only 0,509. It is not a minute value, because the aenergy value is increasing.

mdzmdz commented 2 years ago

MQTT sends correct data in terms of total consumption. I approved this with several independent meter. I do not know why integration incorrectly calculates the result, but it seems that some changes to const.py could help. I am working on it.

mdzmdz commented 2 years ago

Fixed using native Shelly integration. configuration.yaml must be edited.

switch:

sensor:

mlq commented 2 years ago

I think the root cause of this issue is that pyShelly divides the obtained data by 60 and, thus, converting from Wh to Wm. ShellyForHass assumes that the unit is Wh.

I have written a small patch for pyShelly that changes this behavior for Gen 2 devices and the values look more plausible. However, I am not experienced with this code base. While all the reports here suggest that it only affects Gen 2, I would assume that it might apply to the previous generation as well but I don't have any device to test that. Maybe someone can verify this and we can send the patch as a pull request.

mdzmdz commented 2 years ago

I think the root cause of this issue is that pyShelly divides the obtained data by 60 and, thus, converting from Wh to Wm. ShellyForHass assumes that the unit is Wh.

I have written a small patch for pyShelly that changes this behavior for Gen 2 devices and the values look more plausible. However, I am not experienced with this code base. While all the reports here suggest that it only affects Gen 2, I would assume that it might apply to the previous generation as well but I don't have any device to test that. Maybe someone can verify this and we can send the patch as a pull request.

It is not Shelly for HASS, it is e different integration. Is it correct?

mlq commented 2 years ago

ShellyForHASS is using pyShelly as a dependency to communicate with the devices.

In my installation, version 0.3.5 is installed to /usr/local/lib/python3.9/site-packages/pyShelly but a local installation can be set with the debug_local_py_shelly configuration option for ShellyForHASS.

andrepcg commented 2 years ago

I think the root cause of this issue is that pyShelly divides the obtained data by 60 and, thus, converting from Wh to Wm. ShellyForHass assumes that the unit is Wh.

I have written a small patch for pyShelly that changes this behavior for Gen 2 devices and the values look more plausible. However, I am not experienced with this code base. While all the reports here suggest that it only affects Gen 2, I would assume that it might apply to the previous generation as well but I don't have any device to test that. Maybe someone can verify this and we can send the patch as a pull request.

I believe this is exactly what's happening. I divided the reported total consumption in HA by 60 and now it matches the aenergy.total attribute

pstzh commented 2 years ago

Possible and simple solution - Specific device setting in configuration.yaml for the affected devices: settings: total_consumption: { decimals: 2, div: 16.66667, unit: 'kWh' }

mlq commented 2 years ago

The pull request has been merged and should be included in tomorrow's release.

hakana commented 2 years ago

Possible and simple solution - Specific device setting in configuration.yaml for the affected devices: settings: total_consumption: { decimals: 2, div: 16.66667, unit: 'kWh' }

Better to install new release now ;)