#Automation that Loops
1 messages · Page 1 of 1 (latest)
It doesn't like you want a trigger
If you just want to loop: https://www.home-assistant.io/docs/scripts/#repeat-a-group-of-actions
If you do want another trigger, you'll need to decide what you want it to be
It sounds like you just have a script
I am looking at your link above. Thanks for helping.
You only need two triggers: light on for 1h, light off for 10m and in the action you just toggle the light
No need for a loop at all
OK, thanks, interesting. I have an automation that turns the light on for x amount of time and then off for x amount of time. How do you get it to repeat or is that not necessary?
Automations will trigger when the trigger occurs
It's not necessary
You don't need to reset or repeat or anything
The XY problem is asking about your attempted solution rather than your actual problem.
So, is there an actual problem?
OK looking at the automation and will see the result, will ckeck back in a few.
Here is what I am doing. I had a battery candle, removed the battery, and then connected a 3-volt DC power supply. The light comes on for 2 hours, and then the candle bulb goes out. If I turn off the candle for 30 seconds and then turn it back on, it works again. I power the DC supply with a ZigBee Switch.
If you want it to be continuously lit, I suggest using a power monitoring plug and trigger on that
If the load is detectable
Then it's even easier
trigger: switch is on for 2h
condition: none
action: turn off the switch , wait 10s, turn on the switch
Or that, if you know exactly how long it stays on
Thank you
@tidal zephyr do you understand how that implicitly creates the loop you want?
I am struggling with the automation. I am just starting with automations and HA. Can you show an example of this in yaml?
I'm on my cellphone at a campsite, giving you an example is a bit tricky 😉
I hope the weather is good. I will dig into this and figure it out.
mode: single
triggers:
- entity_id:
- switch.couch
to: "on"
for:
hours: 2
minutes: 0
seconds: 0
trigger: state
- event: start
trigger: homeassistant
conditions: []
actions:
- metadata: {}
data: {}
target:
entity_id: switch.couch
action: switch.turn_off
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- action: switch.turn_on
target:
entity_id:
- switch.couch
data: {}
Thanks
Wasn't too hard to create on the phone.
Copy that automation, just change switch.couch to your switch and maybe adjust the timings
But the question still stands: do you see how that loops implicitly?
I am not one to copy and move on. I examine each line and determine what it is saying.
Let me know in case you need some explanations
Will do.
I now understand the yaml that was sent. It is working, and thank you.
Can anyone help? I want to be able to start and stop this automation as follows: start at 4 AM and stop it at 9 PM. description: ""
mode: single
triggers:
- entity_id:
- switch.couch
to: "on"
for:
hours: 2
minutes: 0
seconds: 0
trigger: state
- switch.couch
- event: start
trigger: homeassistant
conditions: []
actions: - metadata: {}
data: {}
target:
entity_id: switch.couch
action: switch.turn_off - delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0 - action: switch.turn_on
target:
entity_id:
- switch.couch
data: {}
Please format your code; you need three backticks before and after the code.
For your question, did you mean that you want to only allow the automation to be triggered between 4am and 9pm? If so, you simply need to add a time condition to the conditions section (called “and if” in the UI)
To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.
The only edgecase with the condition would be that the end result during the night phase is not predictable
What do you mean by that? The condition is predictable: if either trigger fires before 9pm the automation will run. If either trigger fires after 9pm (and before 4am) it won’t.
The state of the light when entering "night mode" (see initial message) is not predictable.
is the desire to not run the automation after 9pm, or is the desire to turn the light off at 9pm? The former is what I suggested, the latter is simply another trigger with a different action (using a choose block)
Let me clarify, I want the automation to run only from 4 AM to 9 PM.
you simply need to add a time condition to the conditions section (called “and if” in the UI)
description: ""
mode: single
triggers:
- entity_id:
- switch.couch
to: "on"
for:
hours: 2
minutes: 0
seconds: 0
trigger: state
- event: start
trigger: homeassistant
conditions:
- condition: time
after: "04:00:00"
before: "21:00:00"
actions:
- metadata: {}
data: {}
target:
entity_id: switch.couch
action: switch.turn_off
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- action: switch.turn_on
target:
entity_id:
- switch.couch
data: {}
Thank you, learning HA and yaml. That looked easy. I need to do more reading.
the problem is still: you don't know the state of the lamp when it becomes 21:00
I assume you want to turn it off over night
if the cycle would happen to be on right before 21:00 the lamp would stay on the entire night and you can't turn it off using the automation because the condition would prevent that from happening
also the light will never turn on the next day
going with that condition is technically answering your question but it'd not achieving what you want
If the automation is supposed to turn it on or off at 4am or 9pm, then yes it is not set up to do that currently.
You are correct, the light did not go OFF at 9 pm (I manually turned it OFF). This morning at 4 AM, the light did not turn ON (I had to turn it ON manually).
i have a similar issue with a device. my fix:
basically i have one automation that triggers on time, power draw dropping to zero, and ha restart. it has some conditions on time and other sensors to determine if it should actually turn on. then a second automation triggering on time and ha restart, again with time as a condition, to turn it off.
i have to maintain the time interval as conditions in both automations as well as the trigger time, but these automations are robust. even if ha is down through the switch times it will recover when ha starts.