Motion activated lighting with manual override

Thought I’d share. Here’s my solution for the following usecase:
hardware:

  1. an on/off sensor (i.e. Motion )
  2. light, scene, automation, etc to switch

use:

  1. when light is switched on: motion activated lights = ON and they turn off after a certain period.
  2. when light is switched off: lights OFF, motion activation OFF
  3. when light is switched off, then on within a certain time, lights ON, motion activation OFF.

Thoughts:
I do not want to decouple the switch from the lights in case the switch loses connection to HA for whatever reason. It still needs to act as a light switch (graceful degradation)

Feel free to comment on my code, I’m not a good programmer by any stretch of the imagination.

** Edit: changed to github link & fixed a scheduler issue.

1 Like

Updated post with updated script as there was a scheduler issue. Should be fixed now.