Condition ignoring value template "False"

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

How are you testing this automation? By waiting for it to trigger at a specified time or by manually triggering it?

When you manually trigger an automation (for example, by clicking the EXECUTE button in Configuration > Automations or by calling the automation.trigger service in Developer Tools > Services) it will skip the automation’s trigger and its condition and simply execute its action.

1 Like

And there is the obvious part - I was indeed manually executing. Thank you!

1 Like