How to turn a light on/off with single PIR Sensor

Hi guys

So I’m struggling on the logic to turn my bedside light on and off with a single motion PIR.

I’ve used the PIRs to turn lights on and then off after a duration before but I can’t figure out how to use the same PIR unit to turn on and off the same light by moving my hand over it.

Below is the code I’ve used to turn the light on:

- alias: Auto Turn on Bedside Light Between 19:00 - 06:30
    initial_state: 'on'
      platform: state
      entity_id: binary_sensor.Other_Sensor
      to: 'on'
      condition: time
      after: '13:00:00'
      before: '06:30:00'
      service: switch.turn_on
      entity_id: switch.bedside_light

The problem I’m having is that I turn the motion sensor back to it’s off state after 2 seconds and then I need to use the lights “on” state combined with the motion state reading “on” to trigger the light off but then both the light on and light off automation trigger.

service: switch.toggle

Sure, but that would be the action right? I just need the logic for the trigger/condition

Not if you use that action.

Wave over it once: the light turns on. Wave over it again: the light turns off. (If between the times in the condition).

Or maybe I’m misunderstanding your problem. For a start, you don’t do this:

The sensor does it itself.

Sorry I don’t follow how it would work, could you please provide me with the code?

      service: switch.toggle
      entity_id: switch.bedside_light

Should be the only change you would need as said above. As it will simply toggle the light from on to off/off to on instead of accidentally trying to do both at the same time.

edit: fixed the formatting of your quote

1 Like

Ahh thank you, I understand now!