Help automating lights based on motion and illuminance

Hi,

I have created an automation triggered by a state change of a motion sensor from off to on, it has a condition to check illuminance level from another sensor. It’s working perfectly except when I’m working and light level changes, it doesn’t trigger the automation because motion sensor state hasn’t change from off to on as it’s already on for a while. I can create another automation to trigger with light level change below certain number and also turn on the lights, but I would prefer if I could keep all within the same automation. I’ve thought of triggering it on motion and have a wait_for_trigger for the illuminance sensor. Is that the only way, or there are other possibilities?

You want to trigger the automation by lux < x and motion being on but also if there’s motion and the lux < x, right?
You could define the lightlevel also as a trigger and define an extra condition with the motion sensor being on.

thanks. that’s what I want, but I’m unsure how to create an automation with your proposal.

here’s my current config:

trigger:
  - platform: state
    entity_id: !input motion_sensor
    from: "off"
    to: "on"

condition:
  - condition: and
    conditions:
      - condition: time
        after: !input time_from
        before: !input time_to
      - condition: numeric_state
        entity_id: !input illuminance_sensor
        below: !input illuminance_level

action:
  - service: light.turn_on
    target: !input target_lights
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_sensor
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target: !input target_lights

trigger:
  - platform: state
    entity_id: !input motion_sensor
    from: "off"
    to: "on"
  - platform: state
    entity_id: !input illuminance_sensor
    below: !input illuminance_level

condition:
  - condition: and
    conditions:
      - condition: time
        after: !input time_from
        before: !input time_to
      - condition: numeric_state
        entity_id: !input illuminance_sensor
        below: !input illuminance_level
      - condition: state
        entity_id: !input motion_sensor
        state: "on"
action:
  - service: light.turn_on
    target: !input target_light

You can just add triggers and conditions if you want. See above :slight_smile:

1 Like

Oh, I see. I thought the conditions wouldn’t be true when the trigger was the motion_sensor, as it just changed states, but I guess it would already be on in this case.

That’s perfect, thanks!

Is that an automation or an script? Why use “input”? If it is a fixed value of one specific input, why not just put the value there?

I also uses values in this kind of automations. Nothing wrong there.
I’d just wanted to be close as possible for the given automation and used the input to demonstrate that you could use multiple triggers.

Awesome, thanks