I have a light (not smart) for my back yard that when you turn it on it defaults to “motion”. That is to say it turns off and waits to detect movement before turning on. However it has a “feature” that if you toggle the light a few times (3) the light will stay on until the next time you turn it off.
I have recently put a smart switch to control this light, and I thought maybe I could set up an automation to have it stay on without having to manually toggle the light a bunch of times.
That is to say, when I turn a light on, I want the system to turn it on and off 3 times automatically in quick succession (ending on an on state)
I believe I am about 80% there, however I am unable to tweak the values to get it to work.
Either the light doesn’t toggle the correct number of times (and ends up off) or it keeps toggling over and over again in an infinite loop (as the state changes to on repeatedly and triggers new automations I think).
Thank you for your response! Based on my understanding of Automation Modes - Home Assistantmode: restart would cause the first execution to stop and a new execution context would fire up (which would continue ad-infinititum as the trigger for the automation is also the action of the automation.)
And yes, the 4 toggles would be 2 cycles, however the one that is manually triggered (i.e. pressing the switch) would be the 3rd. That said, if the hardware needs two more toggles I can add that once I get the multiple toggles working
Edit: I was able see that there is a timeline trace log that I can view - seems the order that things are triggering is not working as anticipated.
Ok, so I updated the timings, as well as added a 10 second delay to the end of the execution to prevent a new instance from firing up. This seems to prevent the infinite loop, and the order tends to fire in the correct order (mostly).
I would prefer to have something that does not rely on consistent network latency. The pseduo code of what I would like would be something like this:
When (light turns on):
Repeat 4 times:
light_state_variable = light.state
light.toggle
while (light.state == light_state_variable)
Sleep 100 miliseconds
endWhile //wait for the state of the light to register a change before moving to the next repeat
endRepeat
Here is my YAML (Yes I know the light ID changed, that light is just one I can see from my PC for testing purposes)
description: >-
Deck light defaults to motion sensor. Turning it on and off 3 times causes it
to stay on
trigger:
- platform: state
entity_id:
- light.front_hall_light
from: "off"
to: "on"
condition: []
action:
- repeat:
count: "4"
sequence:
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- type: toggle
device_id: ****************
entity_id: light.front_hall_light
domain: light
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
mode: single