I have a challenge, I’m trying to capture an incremental power usage value every 24hrs (eg at midnight) and display this value as a daily sensor value which is only updated once a day (so the value shows the previous days 24 hr usage).
I have a the configuration setup to display the cumulative power usage throughout the day as a dynamic value, but I want to capture a static value every 24hrs. Below is the configuration to grab the dynamic HS110 cumulative power consumption (reset every 24hrs)
I’m thinking i need to use an automation job to fire off at a designated time which is fine. But i want the action to update a variable or a template sensor value with the switch attribute or a sensor value which im unsure of.
If anyone has any advice on how to store a variable so that it can be displayed and referenced in calculations that would be much appreciated.
Cheers metbril, I’ve scoured the forums, but I’ll do another check for ‘cumulative’ and see what turns up.
Essentially I am just trying to get the switch attribute at 23:59, but i want to lock that away as a value to do calculations from etc and display that as a separate value to be updated at 23:59 every day. So it’s a lil bit different than just displaying the current switch attribute in real time (currently doing that fine).
I’ve started building a automation task to run at 23:59, the challenge i have is that an automation action is largely to do something with a service (e.g. turn something on, turn something off). Whereas I just want to update a switch attribute value. So I’m unsure whether I can update an existing switch attribute using an automation action, and thats the stumbling block.
Not sure if you’ve used automation tasks in this way and whether you have any advice?
The easiest way to do this is to create a (hidden) input_number sensor whose value can be set with an automation that runs at 23:59. Something like this:
input_number:
todayenergy:
name: PC Powerpoint Today Energy
unit_of_measurement: "KWh"
min: 0
max: 9999
initial: 0
icon: mdi:flash
automation:
- alias: Save End Of Day Total Energy
trigger:
- platform: time
at: '23:59:30'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.todayenergy
value: "{{ states.sensor.todayenery.state }}"
You could also build an automation that monitors the value of sensor.todayenergy changing to 0 (zero). If so, you can use the trigger.from_state.state to populate the input_select.
Big thanks to @metbril for this. Works great and I’m using this to keep daily measures for total energy, grid electricity, solar yield and self-sufficiency percentage. Very easy and elegant solution!
You could also create a ‘daily’ utility meter helper. That will record today’s usage, but also has an attribute for ‘previous period’, which in this case would be yesterday.