Only turn light 'on' when the light is 'off'

I have a light that I want to turn on when motion is sensed, but I only want to issue the ‘on’ command if the light is ‘off’.

If the light is ‘on’ and it is at 50%, sending the ‘on’ command brings it to full brightness and that is undesirable.

Here is my automation with my condition. Thanks!

automation:
  alias: Motion turn on lamp
  trigger:
    - platform: state
      entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
      from: 'off'
      to: 'on'
  condition:
    - platform: state
      entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
      state: 'off'
  action:
      service: light.turn_on
      entity_id: light.lamp

Try this:

automation:
      alias: Motion turn on lamp
      trigger:
        - platform: state
          entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
          from: 'off'
          to: 'on'
      condition:
        - condition: state
          entity_id: light.lamp
          state: 'off'
      action:
          service: light.turn_on
          entity_id: light.lamp

Why the condition for the sensor? If it triggers to ‘on’, condition ‘off’ will not “fail”?

Good catch on the condition. I’ll try it with the lamp instead of the motion detector. I don’t know why I was trying it that way :slight_smile:

@Danielhiversen solution worked for me. Thank you.

@zakharm Can you post your corrected code? It will help other users searching later as well as me, following this thread now. Thanks!

The working code is in @Danielhiversen’s answer already :wink:

1 Like

I’m happy to post the solution and this would be a nice easy starter example for the documentation.

automation:
      alias: Motion turn on lamp
      trigger:
        - platform: state
          entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
          from: 'off'
          to: 'on'
      condition:
        - condition: state
          entity_id: light.lamp
          state: 'off'
      action:
          service: light.turn_on
          entity_id: light.lamp
4 Likes

Thanks - steps like that can save later users tons of time.

1 Like

Thank you for this. It was just what I needed.

3 years later, but thanks to this I made my first automation, guys! awesome.

if doorbell rings, flash lights. of state was on, turn back on, if state was off, stay off.