Turn off Lights when no Motion

Hi, I’m looking for a simple automation/script/blueprint that Turns off the lights, when no motion is detected after 10 seconds, and auto dims after 5 seconds.

I’ve tried and tested the blueprints available in the forums, but can’t get them to work for some reason, or they don’t turn the light of a set time.

I’m using a Sonoff Mini (Zigbee) with Tasmota Zbridge.

Would appreciate help on this.

Thanks

This is doable with the UI editor without any blueprints. Have you tried that?

I have and couldn’t get it to work unfortunately, would you mind creating an example then pasting the yaml for me?

Thanks

Probably need 2 separate automation

- alias: no motion 5s light on 128 brightness
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'off'
    for:
      seconds: 5
  condition:
     condition: state
     entity_id: light.name
     state: "on"
  action:
    - service: light.turn_on
      target:
        entity_id: light.name
      data:
        brightness: 128

- alias: no motion 10s light off
  trigger:
    platform: state
    entity_id:
      - binary_sensor.motion_sensor_xxx
    to: 'off'
    for:
      seconds: 10
  action:
    - service: light.turn_off
      entity_id: light.name

in your “light on” automation you need to set brightness back to 255, your light might save last state when turn back on

1 Like

The community forum is filled with examples of automations and blueprints to create a motion-controlled light. It’s concerning that you were unable to get any of them to work. If the following example fails then there’s a fundamental problem somewhere in your system.

Simply change the names of the entity_ids to match what you have. It turns off the light after 3 minutes of no motion detected.

alias: example 555
mode: restart
trigger:
- platform: state
  entity_id: binary_sensor.kitchen
  to: 'on'
- platform: state
  entity_id: binary_sensor.kitchen
  to: 'off'
  for: '00:03:00'
condition: []
action:
- service: 'light.turn_{{ trigger.to_state.state }}'
  target:
    entity_id: light.kitchen
5 Likes

Thanks. I’ve tested this as well and @huu code, but couldn’t get it to work correctly unfortunatly. You maybe right, I think my motion sensor is at fault here sadly.

I guess a Sonoff ZbMini (Sonoff Mini is Wifi), but that is a switch, not a motion sensor. Can you see change in logbook or history for your motion sensor ? Are you using tasmota2zigbee or ZHA with your ZbBridge ?

@francisp Yes it’s a switch, the Sonoff Mini is zigbee based (not wifi).which is connected to the light. I’m using ZHA integration and both devices are paired. The Zbbridge is flashed with Tasmota.

In the logbook the motion sensor keeps switching to ‘Motion’ and ‘Cleared (no motion detected)’ after a few seconds.

I’m not sure if the sensor is faulty, but it’s look likely to be unfortunately. It is a pretty old sensor with slow response, and I don’t think it supports occupancy either. Model: Tuya PIR RH3040 (the square design)

I read there are many complaints Tuya doesn’t pass on state update to hassio properly, either never or very delay.

When it’s a switch you shouldn’t use

- service: light.turn_off

Because… it’s not a light

  1. Go to Developer Tools → States (tab) → Find your light or switch entity → Screenshot → Paste it here
  2. Go to Developer Tools → States (tab) → Find your motion sensor entity → Screenshot → Paste it here
  1. Does this mean you want the light to dim after 5 seconds of no motion, then turn off 5 seconds later if there are still no motion?
  2. Related to question number #3 - as far as I know, Sonoff Mini does not support light/switch dimming.

Sonoff Mini or MiniR2 only on/off no dimming