Hello everyone, unfortunately, I'm not making progress with my plan. I want to display the current runtime of a switch on the dashboard and, after deactivating the switch, the time should be reset. However, I always get a message that the sensor is not available when I activate the desired switch 'bewaesserung_haustuer'. What did I do wrong in the code? Can someone help me?
#Problem: display actual runtime of a activated switch
1 messages · Page 1 of 1 (latest)
platform: template
sensors:
schalter_zeit2222:
unique_id: sensor.schalter_zeit2222
friendly_name: 'Laufende Zeit für Schalter'
icon_template: mdi:clock-outline
unit_of_measurement: 'sec'
value_template: >
{% if is_state('switch.bewaesserung_haustuer', 'on') %}
{% set schalter_zeit2222 = (as_timestamp(now()) - as_timestamp(states('sensor.start_time_sensor'))) %}
{{ schalter_zeit2222 | round(0) }}
{% else %}
Schalter ist aus
{% endif %}
this is my code. i have this sensor i a separate .yaml file.