#Automation that Loops

1 messages · Page 1 of 1 (latest)

tidal zephyr
#

I can create an automation that turns on the light for 1 hour and then off for 10 minutes. How do you make an additioanal trigger to go back to the start and repeat?

trail narwhal
#

It doesn't like you want a trigger

#

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

tidal zephyr
#

I am looking at your link above. Thanks for helping.

tough yoke
#

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

tidal zephyr
#

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?

trail narwhal
#

Automations will trigger when the trigger occurs

tough yoke
#

It's not necessary

trail narwhal
#

You don't need to reset or repeat or anything

green daggerBOT
#

The XY problem is asking about your attempted solution rather than your actual problem.

trail narwhal
#

So, is there an actual problem?

tidal zephyr
#

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.

trail narwhal
#

If you want it to be continuously lit, I suggest using a power monitoring plug and trigger on that

#

If the load is detectable

tough yoke
#

Then it's even easier
trigger: switch is on for 2h
condition: none
action: turn off the switch , wait 10s, turn on the switch

trail narwhal
#

Or that, if you know exactly how long it stays on

tidal zephyr
#

Thank you

tough yoke
#

@tidal zephyr do you understand how that implicitly creates the loop you want?

tidal zephyr
#

I am struggling with the automation. I am just starting with automations and HA. Can you show an example of this in yaml?

tough yoke
#

I'm on my cellphone at a campsite, giving you an example is a bit tricky 😉

tidal zephyr
#

I hope the weather is good. I will dig into this and figure it out.

tough yoke
#
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: {}
tidal zephyr
#

Thanks

tough yoke
#

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?

tidal zephyr
#

I am not one to copy and move on. I examine each line and determine what it is saying.

tough yoke
#

Let me know in case you need some explanations

tidal zephyr
#

Will do.

tidal zephyr
#

I now understand the yaml that was sent. It is working, and thank you.

tidal zephyr
#

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
  • 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: {}
surreal widget
green daggerBOT
#

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.

tough yoke
surreal widget
tough yoke
surreal widget
#

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)

tidal zephyr
#

Let me clarify, I want the automation to run only from 4 AM to 9 PM.

surreal widget
#
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: {}
tidal zephyr
#

Thank you, learning HA and yaml. That looked easy. I need to do more reading.

tough yoke
#

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

surreal widget
#

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.

tidal zephyr
leaden prawn
#

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.