I want to show the remaining time of a timer - as an attribute to a binary sensor. I think I’ve got a solution, but I’m struggling to understand templating (and I must say, I find the HA docs on templating totally baffling!!)…
This does work, but it feels ‘wrong’. The rest of the package work fine - binary sensor turns to on when power meter goes above 1W, automation to start/cancel the timer as/when the dishwasher starts/stops, automation for notification, and displaying this in a glance/markdown card on the frontend… I’m mainly looking to improve my understanding…
template:
- binary_sensor:
...
attributes:
remaining_time: >-
{% set seconds = as_timestamp(state_attr('timer.dishwasher','finishes_at')) - as_timestamp(now()) %}
{{ seconds | timestamp_custom('%R', 0) }}
I was a bit unsure why this didn’t work, among adding float/int in a few times (which I don’t really understand…):
{{ as_timestamp(state_attr('timer.dishwasher','finishes_at')) - as_timestamp(now()) | timestamp_custom('%R', 0) }}