Hi
I’m looking how to monitor the most recent usage of my boiler/heating.
It controlled with switch component and I can successfully monitor the total usage (for example) of the recent day by using sensor.history_stats
For example if my boiler worked last time today between 13:00-13:45, there’s what I want is to get:
- For how long it was ‘on’ until it turned ‘off’ (for example “45 minutes”)
- When it went last time from ‘on’ to ‘off’ (for example “today, 13:45”)
Thanks!
Nobody answered, so digged a bit by myself, here’s the solution:
- alias: "Update Last Boiler On"
initial_state: 'on'
trigger:
- platform: state
entity_id: switch.boiler
from: 'off'
to: 'on'
action:
- service: variable.set_variable
data:
variable: last_boiler
attributes_template: >
{
"last_on": "{{ states.switch.boiler.last_changed }}",
"last_off": ""
}
value_template: "{{ relative_time(now()) }}"
- alias: "Update Last Boiler Off"
initial_state: 'on'
trigger:
- platform: state
entity_id: switch.boiler
from: 'on'
to: 'off'
action:
- service: variable.set_variable
data:
variable: last_boiler
attributes_template: >
{
"last_off": "{{states.switch.boiler.last_changed }}"
}
- service: variable.set_variable
data:
variable: last_boiler
value_template: '{{((as_timestamp(now()) - (as_timestamp(states.variable.last_boiler.attributes.last_on))) /60 ) | int }} minutes'
- alias: "Update Boiler Use Ongoing"
initial_state: 'on'
trigger:
- platform: time
seconds: '/5'
condition:
condition: state
entity_id: switch.boiler
state: 'on'
action:
- service: variable.set_variable
data:
variable: last_boiler
value_template: '{{((as_timestamp(now()) - (as_timestamp(states.variable.last_boiler.attributes.last_on))) /60 ) | int }} minutes'
1 Like
Just what i was looking for, thank you.
@radinsky, noticed the last usage and ongoing isn’t getting updated as of last HA update . Do you know what changed ?
I’m still on 117.6, which version are you running?
Update : Resolved, started working after a reboot, removed the “template” as mentioned in the post.
ah ok, im on 0.118.1 . somehow the timers keeps running without stopping, found there has been a change in the way template is used , but still fails
trying to seek solution on another thread.