Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a Total energy sensor that is restored after reboot #1693

Open
niklerus opened this issue Apr 5, 2022 · 6 comments
Open

Make a Total energy sensor that is restored after reboot #1693

niklerus opened this issue Apr 5, 2022 · 6 comments
Assignees

Comments

@niklerus
Copy link

niklerus commented Apr 5, 2022

Describe the problem you have/What new integration you would like
There's a "Total Daily Energy" sensor that persists through reboots but it would be even more usable if there was a "Total energy" sensor that was persistant as well.

Please describe your use case for this integration and alternatives you've tried:
There's a Power Consumption application (https://github.com/klaasnicolaas/home-assistant-glow ) that works great but if you reboot the ESP32 the total energy number is lost but the daily is preserved. Would make sense to be able to preserve the total as well. (probably more useful than saving the daily consumption)

Additional context

@dz0ny
Copy link

dz0ny commented Apr 11, 2022

This can be done via https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/memory-types.html#noinit-dram

  on_boot:
    priority: 800.0
    then:
    - lambda: |-
        __NOINIT_ATTR uint32_t my_data;
        id(some_value_sensor).publish_state(my_data);
sensor:
    ...
    id: some_value_sensor
    on_value:
        then:
        - lambda: |-
            __NOINIT_ATTR uint32_t my_data;
           my_data = x;

@jumping2000
Copy link

the total energy sensor would be very useful 👍

@Bert-R
Copy link

Bert-R commented Nov 22, 2022

It would indeed be useful if this would be available out of the box. For as long as it isn't, you can build it yourself, rather easily. I made a PR on the Athom smart plug configuration that does it: athom-tech/athom-configs#22

@Roving-Ronin
Copy link

+1 should have a 'Total Energy Daily' (as exists now) and a 'Total Energy' (i.e. lifetime / at least time between firmware updates of device). Bert-R's on athom v2 plug works great.

@nkinnan
Copy link

nkinnan commented Sep 9, 2024

This is now natively supported, I added a section to the doc explaining how to use it: https://esphome.io/components/sensor/total_daily_energy.html#lifetime-instead-of-daily

@Roving-Ronin
Copy link

This only shows the Daily Energy, based upon @dentra's work, I use the following that provides a breakdown for Today / Yesterday / Week / Month / Year usage.

https://github.com/Roving-Ronin/myHomeAssistant/tree/main/components/energy_statistics

Example of its usage in Athom plugs, is this module that is loaded by the 'overall' yaml for those type plugs: https://github.com/Roving-Ronin/myHomeAssistant/blob/main/esphome/sensors/athom-power-plugs.yaml

In webserver v3 interface, it looks like:

image

Note: 'NA' is not an error for year, the sensors start showing data come the next Monday / 1st of Month / 1st Jan etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants