SonoffLAN icon indicating copy to clipboard operation
SonoffLAN copied to clipboard

Consumption history data SonoffLAN

Open caitotheonlypotato opened this issue 4 years ago • 26 comments

Hi.

Until recently I have always been able to extract historic consumption data in kWh from practiacally any SONOFF device with power monitoring with the following code.

today_consumption_shed_breaker_1_1: friendly_name: Today consumption shed Breaker 1 unit_of_measurement: kWh value_template: "{{ state_attr('switch.sonoff_yournumberhere', 'consumption').0 | round(1) }}" month_consumption_shed_breaker_1_1: friendly_name: 30 days consumption shed Breaker 1 unit_of_measurement: kWh value_template: "{% set p=state_attr('switch.yournumberhere', 'consumption') %}{{ p[:30]|sum if p }}"

I also used to be able to view the history in a list in developer options, it no longer shows. I'm unsure as to whether this is an issue with the integration or the HA core.

I'm happy to raise it there if that's indeed the right place to start :)

regards Greg

caitotheonlypotato avatar May 06 '22 06:05 caitotheonlypotato

image

caitotheonlypotato avatar May 06 '22 06:05 caitotheonlypotato

Hi Alex , I am having the same issue. Historical Power consumption in kwh as attribute is no longer there on latest integration version.

Update: I noticed there is no sonoff.update_consumption service anymore. I used to call this service every 10 minutes to fetch historical data from cloud but now it is failing as service not found. My most of the template sensors depends on this. Please enable this again.

Furthermore, I found one new sensor/attribute with name xxxx_energy. It was hidden, I enabled it and it shows only todays energy, I read from docs that " Energy data loads from cloud every hour" . Is there a way to make it configurable ?

The main benifit of historical consumption (I think 100 days) was to have energy history without increasing the size of mysql/mariadb, and the KWh calculated at hardware device level is more accurate than creating a meter component or using a integration template at HA level, let suppose if HA is off for 3 hours then you will lost the 3 hours consumption, but at device level it keep accumulating even the internet is not available and once the internet is available it updates to cloud. I hope you will think about to restore the previous consumption history feature.

Thanks alot.

alidsd avatar May 06 '22 18:05 alidsd

I have the same issue. Consumption attribute is not available anymore:(

msemenkin avatar May 07 '22 02:05 msemenkin

Adds history data to latest master-version. Will be in next release https://github.com/AlexxIT/SonoffLAN#sonoff-pow

AlexxIT avatar May 08 '22 05:05 AlexxIT

Hi Alex, Updated to latest update (3.0.5), after refresh/restart, I am unable to find the consumption history as attribute (100 days comma separated values), Before it used to display in bottom of Power dialog. maybe I am missing something.

image

It used to working fine before, but even after the recent update, it is not working because 'consumption' as sensor's attribute (for Pow R2) has been removed.

    value_template: >
        {% set val = state_attr('switch.sonoff_1000cfb3f8', 'consumption') %}
        {{ val[:100] |sum |default(0.00) |float |round(2) if val!=None else 0.00 }}

alidsd avatar May 11 '22 19:05 alidsd

@alidsd by default history disabled https://github.com/AlexxIT/SonoffLAN#sonoff-pow

AlexxIT avatar May 12 '22 20:05 AlexxIT

Hi Alex, It is already there and enabled (sorry I forgot to mention this), but there is no 'attributes' dropdown where daily consumption history used to be shown as comma seperated string. here is my config.

sonoff:
  username: !secret sonoff_usr
  password: !secret sonoff_pwd
  #mode: auto
  reload: always
  sensors: [power, current, voltage]
  force_update: [power, current, voltage]
  scan_interval: '00:05:00'  # (optional) default 5 minutes
  energy: [300, 15]  # update interval (seconds), history size (days)

alidsd avatar May 12 '22 20:05 alidsd

I don't use this YAML config any more, I configured mine through the integration iteslf, and commented the old code off, I do concur however that I am unable to view daily historic data as per previous, is that what you are referring to @alidsd

caitotheonlypotato avatar May 13 '22 01:05 caitotheonlypotato

@alidsd your config wrong

AlexxIT avatar May 13 '22 03:05 AlexxIT

This code for me returns historic consumption for 10 days as a single total, not a day by day breakdown. Does that help you @alidsd

image

caitotheonlypotato avatar May 13 '22 03:05 caitotheonlypotato

This code for me returns historic consumption for 10 days as a single total, not a day by day breakdown. Does that help you @alidsd

image

Hi @caitotheonlypotato , I assume that old YAML config is still supported because there is no error produced. Secondly even if I configure through integration and put energy: [3600, 10] in YAML, then It is not what was a few release ago. Having total energy in single variable is not as previous. Previously it used to have Attribute dropdown where along with all properties, a consumption with comma separated values for 100 days was there. It used to give breakdown of each day consumed energy that can be used in graphs, template and integration sensors. Having total of either 10 or 30 days in a single total is not I needed. Previous feature was fantastic. I request Alex to enable that feature again for pow devices. Thanks.

alidsd avatar May 13 '22 10:05 alidsd

Feature supported. Your config wrong.

AlexxIT avatar May 13 '22 11:05 AlexxIT

This code for me returns historic consumption for 10 days as a single total, not a day by day breakdown. Does that help you @alidsd image

Hi @caitotheonlypotato , I assume that old YAML config is still supported because there is no error produced. Secondly even if I configure through integration and put energy: [3600, 10] in YAML, then It is not what was a few release ago. Having total energy in single variable is not as previous. Previously it used to have Attribute dropdown where along with all properties, a consumption with comma separated values for 100 days was there. It used to give breakdown of each day consumed energy that can be used in graphs, template and integration sensors. Having total of either 10 or 30 days in a single total is not I needed. Previous feature was fantastic. I request Alex to enable that feature again for pow devices. Thanks.

Hi @alidsd

If you drop the legacy YAML which is now configurable in the integration and follow the code precisely, you should see this result in developer options, which I presume you can adapt to suit your needs, the daily totals are not comma separated in the output, there is a line break instead.

Here is the code I used to generate the output in developer options, by using the _energy compnent of the entity eg for this code, the entity in developer options was "sensor.sonoff_10012c4e9b_energy"

sonoff:
  devices:
    10012c4e9b:
      reporting:
        energy: [3600, 30]  # update interval (seconds), history size (days)
- sensor:
    - name: "House Solar Breaker 1 of 3, 30 days consumption"
      unit_of_measurement: "kWh"
      state: "{{ states('sensor.sonoff_10012c4e9b_energy') | float(0) | round(1) }}"

image

caitotheonlypotato avatar May 13 '22 13:05 caitotheonlypotato

HI @AlexxIT & @caitotheonlypotato , Really appreciate you help and guidance, Now it is solved but thanks for pointer. I am an old user of Alex sonoff integration so thats why having old way to configure this integration, When Alex was saying that your configuration is wrong then I was not able to understand that what was wrong because all the other things were working except consumption history. But now it is there. So yes I entirely removed config from Yaml , deleted integration from Hacs, restarted HA, and then again added from Hacs and only put the relevant energy attribute (with device id) in Yaml, and it started working. Now I am back to future again as my lot of automation and calculation depends on it. I really appreciate the time and effort that were spent by Alex on this integration, I wish that I could contribute in coding and in new features but due to extremely busy in multiple projects , I can not .

Thanks.

image

Update: Integration working flawlessly just like before.

image

alidsd avatar May 13 '22 14:05 alidsd

Hi Guys,

I am still struggling with this issue, I have tried all the suggestions described here, and can find the problem, I can not get the consumption data from the pow switches. Here is what I get. image image

This is my configuration:

image image

Any idea?

Thanks a lot.

fariddergal avatar May 15 '22 16:05 fariddergal

Hi , Consumption history is only available under the energy entity. First you need to enable it, then you will be able to see it and its attributes in dev screen. By default, this entity is hidden, you need to enable it from Devices page.

image

Hi Guys,

I am still struggling with this issue, I have tried all the suggestions described here, and can find the problem, I can not get the consumption data from the pow switches. Here is what I get. image image

This is my configuration:

image image

Any idea?

Thanks a lot.

alidsd avatar May 15 '22 19:05 alidsd

Thank you, I made it, it was unabled, I think this is hiden and was i little difficult to find, Thanks a lot

fariddergal avatar May 16 '22 01:05 fariddergal

HI @AlexxIT & @caitotheonlypotato , Really appreciate you help and guidance, Now it is solved but thanks for pointer. I am an old user of Alex sonoff integration so thats why having old way to configure this integration, When Alex was saying that your configuration is wrong then I was not able to understand that what was wrong because all the other things were working except consumption history. But now it is there. So yes I entirely removed config from Yaml , deleted integration from Hacs, restarted HA, and then again added from Hacs and only put the relevant energy attribute (with device id) in Yaml, and it started working. Now I am back to future again as my lot of automation and calculation depends on it. I really appreciate the time and effort that were spent by Alex on this integration, I wish that I could contribute in coding and in new features but due to extremely busy in multiple projects , I can not .

Thanks.

image

Update: Integration working flawlessly just like before.

image

Hi alidsd

Would it be possible to share your code to pull the data to generate the info in the image.

Thanks in advance

debug7878 avatar May 16 '22 13:05 debug7878

Please let me know which image code you are referring to .

alidsd avatar May 16 '22 14:05 alidsd

Please let me know which image code you are referring to .

Hi The image below.

image

debug7878 avatar May 16 '22 14:05 debug7878