Help with 24 hour power usage

Hey Everyone,

i’m using a youless energie meter to measure my energy used. this gives me sensor.youless_meter that will tell me total power consumed (12345w. i want to record the output of that sensor on 00:00 and subtract that any time with the current usage. so it will tell me how much i’ve used that day.

how do i go about creating such a script?

thanks :slight_smile:

I would create something like an input_number.power_at_midnight and another one called input_number.power_today; then create two automations:

  1. that pushes the value from your sensor.youless_meter to input_number.power_at_midnight every day at midight

and

  1. that regularly subtracts the input_number.power_at_midnight from your sensor.youless_meter, e.g. every 5 minutes.

Or you could create a template sensor that does the 2. action continuously.

Similar to the approach of storing the value in an input_number field, you could use MQTT to store values and template sensors to show the cumulative values. I’ve got hourly, daily and monthly usage being show this way. This was my inspiration…

There are two components with open pull requests that seem to meet your need exactly. Hopefully they are accepted and merged for the next release:

https://github.com/home-assistant/home-assistant/pull/19703 -
Sometimes a device only provides power information (measured in W or kW).
This sensor does an integration of Power and time in order to measure energy consumed in kWh (standard energy measurement unit)

and

https://github.com/home-assistant/home-assistant/pull/19718 -
A utility meter sensor provides functionality to track consumptions of various utilities (e.g. energy, gaz, water, heating). From a User perspective utility meters operate in cycles (usually monthly) for billing purposes, this sensor will automatically reset the counter based on the configured cycle. On a reset an attribute will store the previous counter, providing the means for comparison operations (“did I spend more or less this month?”)

If you are feeling adventurous, you could pull the code from either (or both) of these and use them as custom components probably; until they get merged.