Just setting up my HA for the first time. Creating my first automation that turns on a switch when the Hue dimmer is triggered. It work without the delay but I want the switch to come on after 1min 30 seconds. For testing I changed this to 10 seconds. But I can’t get the delay to work at all. the logs just say:
Error rendering ‘Ensuite Light on’ delay template: offset ‘00:00:10’ should be format ‘HH:MM’ or ‘HH:MM:SS’
Forgive me if I am wrong, but I am following that format am I not? Here’s the automation:
- id: '1574252233270'
alias: Ensuite Light on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
action:
- delay: '00:00:10'
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_on
try:
action:
- delay:
seconds: 10
- service: switch.turn_on
entity_id: switch.sonoff_10001ebe10
the notation shouldn’t make a difference, but its what I use throughout the system with succes…
OK just changed the delay to 1 minute ‘00:01:00’ and it worked! Strange how 10 seconds doesn’t work?
Another question, if this automation is triggered and I then turn the light off again with a different automation, will the automation stop or will it continue to turn the switch on?
Thanks, that’s something to try. see above, it works with the format I used for 1 minute.
So there is nothing wrong with your automation in your first post. Are you sure it didn’t somehow contain some non-printing character, or you didn’t restart after changing it, or something like that? Again, there’s absolutely nothing wrong with
- delay: '00:00:10'
But, I agree, that error is unexpected.
The automation, once started, will not stop, although if it is re-triggered while it’s waiting in the delay, it will behave in a known, but unexpected way – it will abort the delay and move to the next step, which in this case is to turn the switch off. Many people get bit by this non-intuitive behavior.
Does that answer your question?
I only changed the numbers and nothing else. Strange, but 1.30 is what I was after anyway.
So I now have two automatons, one that turns the switch on with the dimmer (after 00:01:30) and another that turns the switch off once the dimmer is turned off (after 00:15:00). If I turn the dimmer off within the 1m 30s delay, will that stop the delay occuring? Or will the switch turn on anyway?
Can you post these two automations? I think I know what you need to do, and it would be helpful if I had your current code to modify.
- id: '1574252233270'
alias: Ensuite Light on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
action:
- delay: 00:01:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_on
- id: '1574253835249'
alias: Ensuite Light Off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- delay: 00:15:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_off
So the basic idea is, you want to be able to start and stop two different sequences. The easiest way to do that is to put the sequences into scripts, then start/stop the scripts from the automations.
Scripts:
ensuite_light_on:
sequence:
- delay: 00:01:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_on
ensuite_light_off:
sequence:
- delay: 00:15:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_off
Automations:
- id: '1574252233270'
alias: Ensuite Light on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
action:
- service: script.turn_off
entity_id: script.ensuite_light_off
- service: script.ensuite_light_on
- id: '1574253835249'
alias: Ensuite Light Off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_on
- service: script.ensuite_light_off
1 Like
OK that looks great, but not following the automation, sorry. I created what I thought was it using the GUI but it’s come out different.
- id: '1574269513145'
alias: ensuite_light_on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
condition: []
action:
- data:
entity_id: script.ensuite_light_off
service: script.turn_off
- service: script.turn_on
- id: '1574269612294'
alias: ensuite_light_off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- data:
entity_id: script.ensuite_light_on
service: script.turn_off
- service: script.turn_off
The GUI limits what you can enter and the format it will take. What it creates is not very “natural” YAML code, although it’s technically correct.
For the last step of each automation, just add the entity_id of the correct script. Does that make sense?
Basically, this:
- service: script.blah
is the same as:
- data:
entity_id: script.blah
service: script.turn_on
OK, so I don’t really follow why each automation has the opposite script listed. e.g. in the on automation you have this:
action:
- service: script.turn_off
entity_id: script.ensuite_light_off
In the on automation you want to stop the off sequence, right, then start the on sequence, right? That’s why.
Ah I see, so that will stop the switch coming on even though the dimmer has been turned off. I get it.
The on automation’s action would actually be (given entering in the GUI):
action:
- data:
entity_id: script.ensuite_light_off
service: script.turn_off
- data:
entity_id: script.ensuite_light_on
service: script.turn_on
And the off automation’s action would be:
action:
- data:
entity_id: script.ensuite_light_off
service: script.turn_on
- data:
entity_id: script.ensuite_light_on
service: script.turn_off
OK here’s what I have now, I’ve gone to editing the yaml instead of the GUI.
- id: '1574269513145'
alias: ensuite_light_on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_off
- service: script.turn_on
- id: '1574269612294'
alias: ensuite_light_off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_on
- service: script.turn_off
You’re not specifying the script in the last step of each automation. They should be:
- id: '1574269513145'
alias: ensuite_light_on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_off
- service: script.ensuite_light_on
and
- id: '1574269612294'
alias: ensuite_light_off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_on
- service: script.ensuite_light_off
Or what I posted in my previous reply.
To be perfectly clear, there are two “short cuts” I’ve been using. First
service: SERVICE
data:
entity_id: ENTITY_ID
can be shortened to:
service: SERVICE
entity_id: ENTITY_ID
And for turning on a script:
service: script.turn_on
entity_id: script.SCRIPT
can be shortened to:
service: script.SCRIPT
(The same is not possible for stopping, i.e., turning off, a script. Hence the longer form.)
Great thanks.
It’s kinda working, but now the switch has gone offline. Seems the HASS has closed the connection to the switch for some reason.
I’m also seeing this error in the logs.
Not passing an entity ID to a service to target all entities is deprecated. Update your call to script.turn_on to be instead: entity_id: all
- id: '1574269513145'
alias: ensuite_light_on
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 1_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_off
- service: script.ensuite_light_on
- id: '1574269612294'
alias: ensuite_light_off
description: ''
trigger:
- entity_id: sensor.en_suite_switch
platform: state
to: 4_click_up
condition: []
action:
- service: script.turn_off
entity_id: script.ensuite_light_on
- service: script.ensuite_light_off
'1574269163120':
alias: ensuite_light_on
sequence:
- delay: 00:01:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_on
'1574269258802':
alias: ensuite_light_off
sequence:
- delay: 00:01:00
- data:
entity_id: switch.sonoff_10001ebe10
service: switch.turn_off
I changed them to a minute to save time whilst testing.