I am trying to build an automation where within a certain timeframe, I want the bathroom fan turned on with the bathroom light turning on and depending on how long the bathroom light stays on, I want two paths:
- Path1: more than 10 seconds, turn the fan off 15 minutes after the light goes off.
- Path2: (default): less than 10 seconds, turn the fan off when the light goes off.
I’ve tried building this automation using the GUI editor but I’m not getting desired behavior as automation always goes the default route, turning fan off immediately after light is off, regardless of the time the light was on. As shown in the screenshot below, time on was >10s but still went default route.
The value_template: "{{as_timestamp(now()) | int - as_timestamp(states.light.baie_light.last_changed) | int}}
reports true when tested under developer tools so it doesn’t make sense to me. Is this a limitation of the visual editor?
My automation has an additional option which works fine but concerning failing option starts at line 32:
alias: Fan Automation
description: ''
trigger:
- platform: device
type: turned_on
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_light
domain: light
condition: []
action:
- choose:
- conditions:
- condition: time
after: '22:00:00'
before: '07:00:00'
sequence:
- type: turn_on
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_fan
domain: light
- wait_for_trigger:
- platform: device
type: turned_off
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_light
domain: light
continue_on_timeout: false
- type: turn_off
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_fan
domain: light
- conditions:
- condition: time
after: '07:00:00'
before: '22:00:00'
sequence:
- type: turn_on
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_fan
domain: light
- wait_for_trigger:
- platform: device
type: turned_off
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_light
domain: light
continue_on_timeout: false
- choose:
- conditions:
- condition: template
value_template: >-
{{as_timestamp(now()) | int -
as_timestamp(states.light.baie_light.last_changed) | int >
10}}
sequence:
- delay:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
- type: turn_off
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_fan
domain: light
default:
- type: turn_off
device_id: 781ee485eb41ce9a494fc8a3ceb8a17e
entity_id: light.baie_fan
domain: light
default: []
mode: restart