When bathroom fan turns on start a timer, after a certain time turn it off. Seems simple enough. Basically followed this tutorial: https://www.youtube.com/watch?v=usg8cB8sd8E&t=223s
Create timer helper:
Start timer when fan turns on:
alias: main bath fan
description: ""
trigger:
- platform: device
type: turned_on
device_id: dd4c20a8cf4dee1e00f20a57a2d0e075
entity_id: 960db2345deadccad50ba08bed7de940
domain: fan
condition: []
action:
- service: timer.start
target:
entity_id: timer.main_bath_fan_timer
data: {}
mode: single
Monitor fan and timer:
alias: main bath fan timeout
description: ""
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.main_bath_fan_timer
id: Timer Finished
- platform: device
type: turned_off
device_id: dd4c20a8cf4dee1e00f20a57a2d0e075
entity_id: 960db2345deadccad50ba08bed7de940
domain: fan
id: Fan off
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Timer Finished
sequence:
- type: turn_off
device_id: dd4c20a8cf4dee1e00f20a57a2d0e075
entity_id: 960db2345deadccad50ba08bed7de940
domain: fan
- conditions:
- condition: trigger
id:
- Fan off
sequence:
- service: timer.cancel
metadata: {}
data: {}
target:
entity_id: timer.main_bath_fan_timer
mode: single
When I turn the fan on I see the state of the timer change in developer tools from idle to active but the finishes at time is set to 30 seconds previous instead of 30 seconds after the start time. If I turn the fan off manually the timer immediately goes back to idle as it should. if I let it run, the timer runs for 30 seconds then changes back to idle. The timer.finished event never appears to fire so the fan does not turn off. Also, the remaining time in developer tools, states, never changes.
Device based automations are meant to be troubleshoot in the UI and while they can be worked on in YAML, it is more difficult because of the naming and the alternate function syntax. Generally if you want to work on stuff in YAML, that entity_id/state based method makes more sense.
Why and how to avoid device_ids in automations and scripts.
That said, I tend to stay away from timers when I can, and instead for shorter times like this use ‘wait for a time’ (Delay)
Trigger fan turns on
action 1 is delay
action 2 is turn fan off
If you manually turn the fan off, that is fine.
1 Like
People on this board always want things posted in yaml however, this automation was all done in the UI.
Also, I only have this set to such a short time for testing purposes. If the timer doesn’t work for 30 seconds it probably wont work for 30 minutes either.
do you get no trace whatsoever?
i just simplified your code and ran this:
alias: test timer timeout
description: ""
trigger:
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.test_timer
id: Timer Finished
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- Timer Finished
sequence:
- service: timer.cancel
target:
entity_id: timer.main_bath_fan_timer
data: {}
mode: single
it’s not the same but you can see it’s close enough. and it triggered fine for me. i used a 10 second timer.
can you give this a try see what it does, and grab the trace if it exists?
btw, I strongly believe that people should be leveraging the UI over straight yaml when pragmatic. I do so myself.
but @Sir_Goodenough advice to avoid device id is very good advice regardless of yaml or not.
It’s not the source of the issue with your timer situation. timer.finished should fire. but it is still nonetheless good advice.
I greatly appreciate everyone’s time and advice.
I started this morning by investigating how HAOS handles time. I noticed that the clock runs a little over 1 minute slow with respect to my linux mint daily driver by comparing my taskbar clock to {{ now() }} in developer tools → template. I thought maybe I was on to something. So I ran my test again and the automation worked!
I made no changes to my automation since yesterday. So I duplicated the automation for another bathroom fan and it worked as well.
I am at a total loss, the only thing I can think of is that there is some sort of house keeping function that enabled timers overnight. Anyway, this issue appears to be solved although I have no idea how.
2 Likes
TIL…
I will add that to my mental list of troubleshooting timers, check the clock.
Thanks for YOUR help.
1 Like