#While Loop, yaml Review Request

1 messages · Page 1 of 1 (latest)

willow dawn
#

Hi, I'm trying to get my light switch to turn on when motion is detected, stay on for ten minutes, and then turn off unless it sees motion at the end of the ten minutes, at which point it just stays on for another ten minutes. The automation works except for the "stay on if you still detect motion at ten minutes" part. I don't think I'm doing the while loop correctly and I assume I'm messing up the trigger. Any quick review of my yaml is appreciated!

`alias: Garage Lights
description: ""
triggers:

  • type: motion
    device_id: detectorID
    entity_id: detectEntityID
    domain: binary_sensor
    trigger: device
    conditions: []
    actions:
  • action: switch.turn_on
    metadata: {}
    data: {}
    target:
    device_id: switchID
  • delay:
    minutes: 10
  • repeat:
    while:
    - condition: trigger
    id: automation.garage_lights
    sequence:
    - delay:
    minutes: 10
  • action: switch.turn_off
    metadata: {}
    data: {}
    target:
    device_id: switchID
  • delay:
    seconds: 10
    mode: single`
steep badge
#

There's no trigger ID called automation.garage_lights there

willow dawn
#

Ok, I thought it could refer back to itself as that's the automation itself.

steep badge
#

No

#

It wouldn't really make sense

willow dawn
#

Any guidance on what to do here with the trigger? I'm honestly a little confused on how to get the while loop trigger to work.

#

Or, I should say, what to input into the while loop trigger.

steep badge
#

You don't need a loop at all

#

This is a very typical motion light automation as far as I can tell

#

I think there's even a default blueprint for it

willow dawn
#

Ok, let me go dig into the blueprints. I'll come back here in a bit.

steep badge
#

Right here:

willow dawn
#

Ah, I remember why I didn't use the blueprint. It wants a light device and I'm turning a switch on/off.

#

I think I'd need to grab the motion_light.yaml and augment it to do the switch.

#

Yeah, there it is. It's as simple as swapping light.turn_on with switch.turn_on and the associated device details.

steep badge
#

You can make the switch into a light

#

Another way: