Hello,
I am setting up an automation to disable thermostats if their sensors go offline. It will check the time since last sensor publication, and also check if the thermostat automation to turn on is active (so as to avoid repeated messages if I decided to leave something off for a period of time):
- id: '1604262839559'
alias: 'Stale sensor: Pip''s Room'
description: ''
trigger:
- at: 00:00
platform: time
condition:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(states.sensor.pip_temperature.last_changed))/(60*60)
> 12 }}'
- condition: state
entity_id: automation.turn_pip_s_heating_on
state: 'on'
action:
- data: {}
entity_id: automation.turn_pip_s_heating_on
service: automation.turn_off
- data:
message: Disabling Pip Heating
title: 'Stale sensor: pip'
service: notify.mobile_app_pixel_2
mode: single
In the developer tools section I’ve tested
{{ (as_timestamp(now()) - as_timestamp(states.sensor.pip_temperature.last_changed))/(60*60)
> 12 }}
which returns False
(Result type: string) yet the action fires. I looked for casting to a boolean but couldn’t see anything.
I tried encapsulating both conditions in an AND
statement (even though I read conditions are AND by default) and it still fires:
- id: '1604262839559'
alias: 'Stale sensor: Pip''s Room'
description: ''
trigger:
- at: 00:00
platform: time
condition:
- condition: and
conditions:
- condition: template
value_template: '{{ (as_timestamp(now()) - as_timestamp(states.sensor.pip_temperature.last_changed))/(60*60)
> 12 }}'
- condition: state
entity_id: automation.turn_pip_s_heating_on
state: 'on'
action:
- data: {}
entity_id: automation.turn_pip_s_heating_on
service: automation.turn_off
- data:
message: Disabling Pip Heating
title: 'Stale sensor: pip'
service: notify.mobile_app_pixel_2
mode: single
I’m probably missing something basic but I’ve trawled the forums and can’t see anything.
Many thanks in advance!
Amadeus