I got a switch for my water pump, and i’d like to monitor it on the Dashboard, showing the duration of the running pump. I managed to update it every minute using:
{% set t = states.sensor.time %}
{{ (as_timestamp(now()) - as_timestamp(states.switch.garage_pumpe.last_changed))|int }} seconds
Unfortunatelly, this does only update every minute - is there a way to get a bit more responsive feeling by updating this sensor every second?
Do you really need that? That will be a lot of data that will be written for, what I suppose, no reason.
I believe the workaround would be to create a counter that you increment with an automation, and another automation to reset it when the pump runs.
Then using the counter value create a sensor that makes it in HH:MM:SS format.
I don’t understand why either.
I monitor my Heating system using the history integration, which gives me a h:m:s output on the dashboard.
- platform: history_stats
name: Heating Run Time Today
entity_id: switch.house_boiler
state: "on"
type: time
start: "{{ now().replace(hour=0,minute=0,second=0) }}"
end: "{{ now() }}"
Your posted code -
{% set t = states.sensor.time %}
{{ (as_timestamp(now()) - as_timestamp(states.switch.garage_pumpe.last_changed))|int }} seconds
Does not make sense to me, because you aren’t checking the state of the switch - just how long ago the state last changed. And you can do that directly in the dashboard by setting the secondary attribute to last changed?
No I understand that, I was just saying I don’t understand the need to update it every second, especially given that it is only tracking the state change, but not when it last changed to a specific state.