Lights off if there is no motion without detecting motion first

Hi,

This question might seem basic, but after quite long search I still didn’t find a solution.

Simple automation - if there is no movement for certain time turns lighs off.

But my hue motion is triggering this automation only after motion was deteced first.

So if lights are turned on with UI and there was no motion in the room, automation doesn’t run.

In order for it to start somebody must trigger a motion and only after that no motion event is triggered.

Is this just a behaviour of hue sensor, or generall? Is there a way to overcome this?

That has nothing to do with hue

An automation works be 3 steap

1 Trigger. Something happens/changes that triggers the automation.

2 Condition. Optional. One or more conditions that must be met to continue. If not met, the automation stops here

3 Actions. One or more actions that are done

You seem to have an automation that react to motion not happening for a certain time. That logic only makes sense if there has been motion followed by a time period without.

If it was not like that, your trigger would fire non stop contuinously. Several times per second, always. There has to be a starting time for a trigger to define a single event where the motion has been off for X seconds. You need to rethink your automation and also consider turning on the light as a trigger to something that times out.

You could add a second trigger to your light off automation:


trigger:
  - platform: template
    value_template: |-
      {% set b = 'binary_sensor.YOUR_HUE_SENSOR' %}
      {% set l = states('light.YOUR_LIGHT') == 'on' %}
      {% set no_motion = states(b) == 'off' and now() - states[b].last_changed >
      timedelta(minutes=2) %}
      {{ l and no_motion }}

I thought - that cannot work.

So I added an automation like that

And yes, it does not work like I think the OP wants it. The automation can only turn the light off with this. So then you need another automation to turn it on. If that other automation is the hue motion sensor then it works.

But you cannot turn the light on from HA UI or a zigbee switch. The minute the light turns on with motion sensor not detecting anything the trigger hits and turns the light off instantly. I am sure this is not what the OP wanted. He was concerned that when the UI is used to turn light on, the automation would not run. And I understand that as he wants the same timeout as when you enter the room.

I have understood it that way, if the light is turned on via UI, although there is no motion anymore, turn off the light.

Automation works like this:
If there is no motion detected start timer for 4 minutes.
If there is still no motion after that turn lights off.

And I want the same if lights were turned on by UI. It means if there is no motion after lights were turned on, start the same timer and at the end of it turn lights off.

I understand, that there must be a moment which will be considered as no motion and it seems like, the sensor is reporting only change of state, it means that no motion is triggered only after there was a motion and vice versa.

Is there a way to “force” the state of sensor to motion detected after the light is turned on via UI, so after that automation will run normally?

You might take a look at Entity Controller from HACS - it allows you to achieve this sort of thing in just a few lines of code:

  - bathroom_light:                               
      sensor: 
      - binary_sensor.bathroom_motion_sensor_motion  
      entities: 
      - light.bathroom_1
      delay: 600

This turns the bathroom light on when motion is detected and off again if no further motion is detected for 10 minutes.

Try this:

trigger:
  - platform: state
    entity_id: light.foo
    from: 'off'
    to: 'on'
    for: 
      minutes: 4
  - platform: state
    entity_id: binary_sensor.foo
    from: 'on'
    to: 'off'
    for: 
      minutes: 4
condition:
  - condition: state
    entity_id: binary_sensor.foo
    state: 'off'
    for: 
      minutes: 4
  - condition: state
    entity_id: light.foo
    state: 'on'
action:
  - service: light.turn_off
    target:
      entity_id: light.foo

hello.
did you manage to get this to work.
I also wants that if there is no motion for x mins then turn off a light but if durning that x mins there was a motion then restart the x mins timer.