Problem with my motion sensor rule, perhaps someone has a idea?!

Hello members,

I have a problem with my motion detector rule, and it often works perfectly, but sometimes the light just stays on and doesn’t go off again.

then i have to switch the light off manually.

The rule should work as follows, if movement is triggered, the light should turn on, then he should leave the light on for 30 seconds, I use HUE motion detectors and, as far as I know, it takes 30 seconds to switch from “occupied” to “unoccupied”.
then he should check whether there is no more movement and switch off the light.

maybe i made a mistake somewhere.

My HUE Motion Sensor :

The EntityID always switches with the Hue motion detector
“binary_sensor. Bewegungsmelder_1er_stock_32496408_occupancy”

alias: Bewegungsmelder -- Erster Stock
description: (Sonnenuntergang )
trigger:
  - type: occupied
    platform: device
    device_id: 51dd0ed5f05dd0e1983080a04a2fa27b
    entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
action:
  - service: light.turn_on
    data:
      brightness_pct: 20
    target:
      entity_id: light.osram_classic_a60_w_clear_lightify_5372040a_level_on_off
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - type: is_not_occupied
    condition: device
    device_id: 51dd0ed5f05dd0e1983080a04a2fa27b
    entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
    domain: binary_sensor
  - service: light.toggle
    data:
      brightness_pct: 0
    target:
      entity_id: light.osram_classic_a60_w_clear_lightify_5372040a_level_on_off
mode: single

THANK YOU FOR YOUR TIME

Instead of this condition, try using wait until action type like this.

  - wait_for_trigger:
      - platform: device
        device_id: 51dd0ed5f05dd0e1983080a04a2fa27b
        domain: binary_sensor
        entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
        type: is_not_occupied
1 Like

I think I’ve tried it before, but I’ll test it again, I’ll get in touch when I know if it works.

Thank you

sheminasalam’s suggestion should fix the problem (and you can also remove the delay).

The condition you currently have will only allow the light to be toggled if the occupancy sensor is off 30 seconds after it was turned on. If after 30 seconds it’s still on, the light is left on and the automation is finished (thereby explaining why “sometimes the light just stays on and doesn’t go off again”).

The use of wait_for_trigger should produce the behavior you want.

1 Like

okay i tested it, and it dont works, the light is still on.

i get in my log a error

Logger: homeassistant.components.automation.neue_automatisierung_2
Source: helpers/script.py:1365
Integration: Automatisierung (documentation, issues)
First occurred: 19:38:00 (1 occurrences)
Last logged: 19:38:00

Bewegungsmelder -- Erster Stock: Already running

my automation:

alias: Bewegungsmelder -- Erster Stock
description: (Sonnenuntergang )
trigger:
  - type: occupied
    platform: device
    device_id: 51dd0ed5f05dd0e1983080a04a2fa27b
    entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
    domain: binary_sensor
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
action:
  - service: light.turn_on
    data:
      brightness_pct: 20
    target:
      entity_id: light.osram_classic_a60_w_clear_lightify_5372040a_level_on_off
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - wait_for_trigger:
      - type: not_occupied
        platform: device
        device_id: 51dd0ed5f05dd0e1983080a04a2fa27b
        entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
        domain: binary_sensor
  - service: light.toggle
    data:
      brightness_pct: 0
    target:
      entity_id: light.osram_classic_a60_w_clear_lightify_5372040a_level_on_off
mode: single

It’s a warning, not an error. Your automation’s mode is single. While wait_for_trigger is waiting for the occupancy sensor to be not_occupied, it ignores any re-triggering of the automation. That’s the meaning of mode: single and the message is normal.

If you wish, you can try this version:

alias: Bewegungsmelder -- Erster Stock
description: (Sonnenuntergang )
trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
    to: 'on'
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_1er_stock_32496408_occupancy
    to: 'off'
    for: '00:00:30'
condition: "{{ is_state('sun.sun', 'below_horizon') }}"
action:
  - service: light.turn_on
    target:
      entity_id: light.osram_classic_a60_w_clear_lightify_5372040a_level_on_off
    data:
      brightness_pct: "{{ 20 if trigger.to_state.state == 'on' else 0 }}"
mode: single

Hi there,
I set up my homeassistant from scratch, now it seems to be working. I also used my HUE bridge again instead of connecting everything to the ConbeeII.

So many thanks to everyone who took their time.