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

Total Daily Energy - Feature Request #36

Open
rwoldberg opened this issue Dec 29, 2022 · 6 comments
Open

Total Daily Energy - Feature Request #36

rwoldberg opened this issue Dec 29, 2022 · 6 comments

Comments

@rwoldberg
Copy link

I am wondering if it would be possible to add total daily energy sensor to the power sensors. I have not looked at the source code yet either plugins yet, but the ESPHome plugin has the ability to do this via the total_daily_energy platform. I only mention ESPHome as it is an example of how it can be done. I would like this so that I can track the energy usage of each outlet in HA.

@brettonw
Copy link
Contributor

brettonw commented Dec 29, 2022

If you are a sophisticated user, you can add it through HA.

I use the packages feature, so in my configuration.yaml I have:

...
scene: !include scenes.yaml

# include files from the packages directory
homeassistant:
  packages: !include_dir_named packages

In my packages, I have a file called aquarium.yaml, and I put a sumation sensor in there. I think HA has added a helper you can use to do this since I did it, so maybe there's an easier way. Anyway, here's what mine looks like:

template:
  sensor:
    - name: "Aquarium Power"
      unique_id: "aquarium_power_w"
      unit_of_measurement: "W"
      device_class: "power"
      state: >
        {% set w1 = (states('sensor.apex_light1_2_1w') | float) %}
        {% set w2 = (states('sensor.apex_light2_2_2w') | float) %}
        {% set w3 = (states('sensor.apex_retpump_2_3w') | float) %}
        {% set w4 = (states('sensor.apex_reflight_2_4w') | float) %}
        {% set w5 = (states('sensor.apex_skimmer_2_5w') | float) %}
        {% set w6 = (states('sensor.apex_dos_2_6w') | float) %}
        {% set w7 = (states('sensor.apex_heater_2_7w') | float) %}
        {% set w8 = (states('sensor.apex_pwrhead_2_8w') | float) %}
        {{ w1 + w2 + w3 + w4 + w5 + w6 + w7 + w8 }}

On the dashboard, under Settings->Devices&Services->Helpers, I clicked "+ Create Helper", and chose "Integration - Riemann sum integral sensor":

Screenshot 2022-12-29 at 12 57 32 PM

I named mine sensor.aquarium_kwh (friendly name: Aquarium kWh). Choose the "Left Riemann sum" option. The trapezoid rule will give an average number between readings which will be wrong if your reporting period is large. I also check the "K" prefix option, but that's up to you.

Screenshot 2022-12-29 at 12 59 00 PM

Then you can add that sensor directly to the energy dashboard as an individual device. From the dashboard home, Settings->Dashboards->Energy, then add an Individual Device:

Screenshot 2022-12-29 at 1 06 56 PM

Once the Energy dashboard starts collecting, it will show under the Monitor Individual Devices section of the Energy tab:

Screenshot 2022-12-29 at 1 08 31 PM

I also created another helper from it, called the Aquarium Utility Meter, which will give you exactly that daily report with a pretty graph I think you want...

Screenshot 2022-12-29 at 1 03 30 PM

@brettonw
Copy link
Contributor

brettonw commented Dec 29, 2022

Indeed, there is now a HA Helper for summing the states of individual sensors, so you can do this without coding at all:

https://www.home-assistant.io/integrations/min_max/

Screenshot 2022-12-29 at 1 15 24 PM

@rwoldberg
Copy link
Author

Thanks, I'll take a look at doing this.

@rwoldberg
Copy link
Author

That works nicely. However, there is one issue, and I am not sure what component is responsible. If the wattage does not change for a plug on the apex, i.e. something is always on, the helper entity remains in an unknown state. If all of the outputs are aggregated together this is probably not an issue, but adding them individually it is. Again, I am not sure if this is in your component or the helper component.

@brettonw
Copy link
Contributor

If you're using the Helper to sum the wattages, I can't help because I haven't done that, but it's not surprising that there's an error like that in an edge case. I think the problem you are running into is a HA situation where they just don't record an input if a new value is the same as the last one. They don't seem to comprehend that an updated steady state is useful information. Can you toggle the switch outlet to force it to pick up data?

@rwoldberg
Copy link
Author

I suspect you are correct this is a HA issue. That is exactly what I had to do, toggle the outputs off/on then they showed up. Thanks for all the work you have put in to this.

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

No branches or pull requests

2 participants