Help needed with Hue Motion Sensors and Automation

Hello guys,
I am using Homeassistant for quite some time, but never had the muse to do it right.
Before I used the Hue Hub for most of the automation, but as my Raspi 4 is already running, why wasting energy on the Hue Hub.
So I bought an SONOFF Zigbee Gateway ZBDongle-E 3.0 USB Dongle Plus plugged it in, installed Zigbee2MQTT, tried some stuff, didn’t work. Sensors, switches and lights (mostly Innr) got disconnected.
Placed the raspi somewhere else, and it was better, but not acceptable yet.
As it is with technology, everyone has another opinion. Some went from Z2M to ZHA, others the other way around.
So I tried it with ZHA, now I had no disconnected devices but one Ikea On/Off Switch.
So far, so good.
Where I am really struggling: How to get the motion sensors automation right.
Used a few blueprint, did some automations myself but never got right.
Lights MAY switch on, but not off and so on.
Here is my script, maybe someone can help me out. Problem is, the light is not switching off.
Any help is really appreciated!

alias: "Flur: Licht Automation"
description: ""
trigger:
  - type: occupied
    platform: device
    device_id: 07708639d5af7c821d623f12a9a1def2
    entity_id: fa5f87d3fd2b0642798386669604e846
    domain: binary_sensor
    id: motion detected
  - type: not_occupied
    platform: device
    device_id: 07708639d5af7c821d623f12a9a1def2
    entity_id: fa5f87d3fd2b0642798386669604e846
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: No motion detected
condition:
  - type: is_illuminance
    condition: device
    device_id: 07708639d5af7c821d623f12a9a1def2
    entity_id: 850345be471452916e6be4b127631cb8
    domain: sensor
    below: 15
    enabled: false
action:
  - if:
      - condition: trigger
        id:
          - motion detected
    then:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.og_flur_lampen
    else:
      - condition: trigger
        id:
          - No motion detected
      - service: light.turn_off
        data: {}
mode: single

The goal is to turn the lights on when motion (occupancy) is detected while lux is under 15.
When no motion is detected for 2 minutes the lights should turn off.
They are turning on, but never turn off :confused:

1 Like

You missed adding the light to the turn off service call.

else:
      - condition: trigger
        id:
          - No motion detected
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.og_flur_lampen
1 Like

Thank you Ryan, you’re absolutely right. Fixed this, now we will see.

Edit: It runs as expected. Thanks again!

1 Like

Hello again,
the automation worked - kind of. It turned the lights on, when illuminance is under 15. But also did not turn off the lights when illuminance is under 15 (I changed that to 50).
I have created a new automation, but not sure if this is right.

id: '1696706396646'
alias: 'Flur: Licht Automation'
description: ''
trigger:
  - type: occupied
    platform: device
    device_id: 07708639d5af7c821d623f12a9a1def2
    entity_id: fa5f87d3fd2b0642798386669604e846
    domain: binary_sensor
    id: motion detected
  - type: not_occupied
    platform: device
    device_id: 07708639d5af7c821d623f12a9a1def2
    entity_id: fa5f87d3fd2b0642798386669604e846
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
    id: No motion detected
condition: []
action:
  - if:
      - condition: and
        conditions:
          - type: is_illuminance
            condition: device
            device_id: 07708639d5af7c821d623f12a9a1def2
            entity_id: 850345be471452916e6be4b127631cb8
            domain: sensor
            below: 50
          - condition: trigger
            id:
              - motion detected
    then:
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.og_flur_lampen
    else:
      - condition: trigger
        id:
          - No motion detected
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.og_flur_lampen
mode: single

Is this correct or should it also have worked the other way?

1 Like