Hey, I want a boiler that I turn on it by timer
I want to create a countdown timer, and I have a few questions:
This is the first try, but the seconds are stuck at 59 seconds, and only the minutes changed
- platform: template
sensors:
countdown_timer:
friendly_name: "Countdown Timer"
value_template: >-
{% set remaining_seconds = (as_timestamp(now().replace(hour=state_attr('input_datetime.countdown_timer', 'hour'), minute=state_attr('input_datetime.countdown_timer', 'minute'))) - as_timestamp(now()) | timestamp_custom("%-I:%H %p") ) | int %}
{% set remaining_minutes = ((remaining_seconds // 60) % 60) %}
{% set remaining_hours = ((remaining_seconds // 60) // 60) %}
{% set remaining_days = (remaining_seconds // (60 * 60 * 24)) %}
{% set remaining_seconds = remaining_seconds % 60 %}
{% set remaining_time = "%02d:%02d:%02d" % (remaining_hours, remaining_minutes, remaining_seconds) %}
{% if remaining_seconds <= 0 %}
Expired
{% else %}
{{ remaining_time }}
{% endif %}
And the second code is:
{% set remaining_seconds = (states.input_datetime.countdown_timer.attributes.timestamp - as_timestamp(now())) | int %}
{% set remaining_minutes = ((remaining_seconds // 60) % 60) %}
{% set remaining_hours = ((remaining_seconds // 60) // 60) %}
{% set remaining_days = (remaining_seconds // (60 * 60 * 24)) %}
{% set remaining_seconds = remaining_seconds % 60 %}
{% set remaining_time = "%02d:%02d:%02d" % (remaining_hours, remaining_minutes, remaining_seconds) %}
{% if remaining_seconds <= 0 %}
Expired
{% else %}
{{ remaining_time }}
{% endif %}
but here, the time still counts after the time that I set in input_datetime
think is needed to fix this function:
{% set remaining_seconds = (states.input_datetime.countdown_timer.attributes.timestamp - as_timestamp(now())) | int %}
These are the value of the input_datetime returns:
And I update the sensor every second:
- alias: 'Update Countdown Timer'
trigger:
platform: time_pattern
seconds: '/1'
action:
service: homeassistant.update_entity
entity_id: sensor.countdown_timer
I would love to get help. Many thanks!