Thoughts on switching lights off after X minutes

Hi All,

Before I start writing the config for a solution that switches lights off after X amount of minutes from last motion in a room I want to get peoples thoughts on how they would approach it before i create something complicated.

I’m going to have a input slider to control the number of minutes a global level. I have a PIR in each room and I want to switch of th lights in that room 10 minutes after last motion.

I’m calling it money save mode :slightly_smiling_face:!.

My head is saying have a timer for each PIR that keeps getting reset everytime motion is detected? It feels like the only way but feels resource intensive?

Thoughts?

Sam

I’m using philips hue lights and motion sensors. All rooms kitted out. I’ve disabled the lights off after x time on the hue app, and instead have H.A. controlling it. I did a quick automation, and then copied it for each room where I need it. Works fine. Takes about 2 minutes. I haven’t noticed any impact on performance as such.

Hi @samtwilliams,

How are you sending your messages to home assistant? If its via mqtt you can use an automation like this one:

- id: '1521022835735'
  initial_state: true
  alias: Turn off kitchen lights
  trigger:
    platform: mqtt
    topic: masoko/kitchen-motion/state
    payload: '0'
  condition:
    condition: state
    entity_id: sensor.kitchen_motion
    state: '0'
    for:
      minutes: 5
  action:
  - service: switch.turn_off
    entity_id: switch.kitchen_light

You’ll only have to integrate the slider value in the duration part of the condition.

I am indeed using mqtt from sonoff bridges.

That’s a really good approach, I’d also pop a condition on a input Boolean that would allow me to switch it off permanently if needed.

you can just turn off the automation to switch it off.

Thanks Paul.

I don’t use hue that much as I couldn’t find nice enough light switches. I went for Lightwave rf smart series instead. I have a few other light systems so controlling it via ha allows for one control across many device. Thanks for the head ups though good to know that exists in gue

Does it remember that state after reboot?

My setup don’t remember them as I use initial_state: true
You can easily test that if you remove this from the automation yaml

1 Like

Do you get any undesired effects should someone switch the light of and then back on before the automation has excited. Essential switching the light of randomly after it’s just been turned on?

No I don’t get such effects - maybe it can depend on the bulbs you use but I don’t see how this will happen - maybe if the bulb needs some time to start responding after powered on, but even if this happens the light will be powered off the next time the no motion period is reached - so you’ll still save power and not let it run for long.
The automation I posted is for a led strip controlled with smart power switch similar to sonoff but I also use same approach for xiaomi bulbs with no problems.

Ok thanks masoko, I’ll give it a bash.

So i went for a test on this:

  - alias: 'Auto Switch Lights Off'
    trigger:
      platform: state
      entity_id: binary_sensor.pir6
      to: 'on'
    condition:
      condition: state
      entity_id: binary_sensor.pir6
      state: 'off'
      for:
        seconds: 10
    action:
      - service: light.turn_off
        entity_id: light.kitchen

It doesn’t seem to work, my understand is that;

trigger: when pir goes to on (motion detected)
Condition: when the pir has been off for 10 seconds
action: turn the light off

It’s the condition thats at fault, remove that the rest works.

Got it working like this;

  - alias: 'Auto Switch Lights Off'
    trigger:
      platform: state
      entity_id: binary_sensor.pir6
      to: 'off'
      for:
        seconds: 10
    action:
      - service: light.turn_off
        entity_id: light.kitchen