#Hey Phil Hawthorne3390 i just listened
1 messages · Page 1 of 1 (latest)
Oooh you're right!
But for me, my last_reset was over 3 days ago, which means the value is the cost for 3 days, not just today 😦
That must be related to statistics I guess 🤷♂️
hmm unsure. When I go to the energy dashboard, it knows I have spent $6 today on energy. But my total_consumed_cost sensor is over $20 (as its been counting since my last reboot of Home Assistant)
I now see it does that for me as well. Guess somehow we need to lookup begin of today value and subtract it from current value.
Yeah guess we could use an automation and helper.
Automation executes at midnight and sets a counter/text input to 0 and another helper to the current cost value
Every 15 minutes, the current_cost - cost_at_midnight value is added to another helper, which gives us "todays cost".
I might actually implement this now (its 1 hour till midnight here) and see how it goes
Maybe a template sensor? My template sensor is rusty tho.
Yeah I think a combination of a few types. Let me code something up now and share it
works pretty nicely! Its a couple of cents off, but might be more accurate tomorrow with the full figures
automation:
- id: electricity_cost_reset
alias: Reset Electricity Cost at Midnight
description: Sets the input_text helper to record the electricity cost as it was at midnight
trigger:
- platform: time
at: "00:00:00"
action:
- alias: "Set input text to current cost value"
service: input_text.set_value
target:
entity_id: input_text.electricity_cost_midnight
data:
value: "{{ states('sensor.electricity_consumed_cost') }}"
That resets the sensor to the current electricity cost at midnight
input_text:
electricity_cost_midnight:
name: Electricity Cost at Midnight
This of course is the helper we need to store that value
Finally we need a template sensor. This one updates every 5 minutes, or when the input_text value changes.
Depending how often your electricity cost sensor updates, you could hook into that instead of polling every 5 minutes
template:
- trigger:
- platform: time_pattern
minutes: "/5"
- platform: state
entity_id: input_text.electricity_cost_midnight
sensor:
- name: "Electricity Cost Today"
state: >
{{ states('sensor.electricity_consumed_cost') | float - states('input_text.electricity_cost_midnight') | float }}
device_class: monetary
Now I can add this to my dashboard ❤️
and....it's alive!
Thanks @cold flax !
I was more thinking of setting the value of that input to a history lookup ('this input always has the value of the first history value for today') , instead of a timed reset, but I admit, that's mostly because I've never done something in that manner, so it's new 😂
a history lookup? Can you see and set a value from an entities previous value?
interesting