Another Motion Lights Automation Question

I have an idea on a better approach to motion lights for our house, but I’m stuck in figuring out how to implement it. As usual, I’m sure there’s 20 different ways to do this, so I welcome your ideas and opinions… even if your opinion is that my idea is stupid!!

So, here’s what I’m thinking.

  1. Typical Motion Lights automation - turns on with motion and turns off when no motion. This part is done and works fine.
  2. Second automation to abort the first, when someone wants the lights to stay on. Would be triggered by ANY change to the lights and would stop the first automation, thus leaving the lights on.

Just in case it’s not clear, if the lights are turned on by motion, I want them to turn off again by motion. UNLESS, someone alters the light. For instance, alexa is asked to increase the brightness. Or maybe a button is pressed.

Our dog often triggers the lights, which isn’t a big problem, just want them to turn back off without waiting too long. On the other hand, if you sit down and start doing something (without a lot of movement) it’s frustrating when the lights turn off on you.

Hope this makes sense. The trigger for step 2 is what I’m stuck on. How to I trigger an automation ONLY if another automation is running? Or perhaps there’s a better way.

Thanks in advance for your time and help!

If I am understanding correctly, just:
trigger on motion detection
turn light on
then add a “wait for trigger” with triggers for both motion going off, and a trigger for the light changing state (that is, someone meddling it).

Then, a choose block that chooses based on the trigger id, if it was triggered by the motion trigger, turn off the light, otherwise end the automation.

That’s a great approach, and much cleaner. Now I need to figure out the criteria for the trigger so I don’t miss things. If anyone has something that’s somewhat all inclusive, I’d love to see how you did it. Otherwise I’ll start with what I know how and tweak as I learn more.

Thank you!!

I know the status of the light switch in my office

if the light switch is OFF office motion will take over its a condition in the automation

but if i walk in and manualy turn on motion automation does nothing. therefore I have to manually turn it off

  - id: "motion in office : light on "
    alias: "motion in office : light on "
    initial_state: true
    trigger:
      - platform: state
        entity_id: binary_sensor.office_motion
        to: "on"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: sensor.office_switch
          state: "OFF"
    action:
# Action to turn ON
      - data:
          entity_id: light.office
        service: light.turn_on

You can use an input_boolean turned on & off by the motion automation and use that to determine if the automation will turn off the light.

so, basically:

  • motion automation first turns on the light then also turns on the boolean
  • then checks to see if the boolean is still on before it turns the light back off then also turn off the boolean
  • if you change the lights (however you determine that) then use that change to turn off the boolean so the motion automation gets cancelled due to the boolean condition not being met.

I assume that if you trigger on the brightness attribute it will catch all of the scenarios you are concerned about.

wait_for_trigger:
  - platform: state
    entity_id: light.table_lamp_level
    attribute: brightness
    id: light
  - type: no_motion
    platform: device
    device_id: 6408b196c169ce7502b2aab0d00297bd
    entity_id: binary_sensor.multisensor_6_home_security_motion_detection
    domain: binary_sensor
    id: motionSensor
continue_on_timeout: false

I’m not sure how the syntax for identifying what triggered it will be. Something like " {{ wait.trigger.id == motionSensor }} " ?

Thanks to those who responded. With your help, this is what I came up with.

alias: Motion Office
description: ''
trigger:
  - entity_id: binary_sensor.office_motion
    from: 'off'
    platform: state
    to: 'on'
condition:
  - condition: device
    type: is_off
    device_id: db59c13055654235aeff96920ddb6add
    entity_id: light.office_lamp
    domain: light
  - condition: numeric_state
    entity_id: sensor.office_light_level
    below: '1.25'
  - condition: not
    conditions:
      - condition: device
        device_id: aed5686196e4a69c6baf80fdd354c1a9
        domain: media_player
        entity_id: media_player.office_tv_2
        type: is_playing
action:
  - data:
      brightness_pct: 15
      rgb_color:
        - 255
        - 240
        - 197
    service: light.turn_on
    target:
      entity_id:
        - light.office_lamp
  - wait_for_trigger:
      - entity_id: binary_sensor.office_motion
        from: 'on'
        platform: state
        to: 'off'
        for:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
        id: nomotion
      - platform: state
        entity_id: light.office_lamp
        id: light
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.id == "light" }}'
        sequence:
          - wait_for_trigger:
              - entity_id: binary_sensor.office_motion
                from: 'on'
                platform: state
                to: 'off'
                for:
                  hours: 0
                  minutes: 15
                  seconds: 0
                  milliseconds: 0
          - service: light.turn_off
            target:
              entity_id: light.office_lamp
            data:
              transition: 10
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.id == "nomotion" }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.office_lamp
            data:
              transition: 10
    default: []
mode: restart

In short, this automation turns on lights when motion is detected in a dark room and turns them off again when the motion stops. UNLESS, someone changes the brightness of the light, in which case it stays on a while longer.

After I test this for the next day or two, I’ll post any modifications I make. Thanks again!!

1 Like