#Motion detection automation turns light ON and DIRECTLY OFF

1 messages · Page 1 of 1 (latest)

verbal jewel
#

The below listed automation has some very weird behaviour:
The binary sensor gets state 'occupied', then light switches on but also very quickly < 0.5s also off gain.
The attached screenshot shows a detail of the Trace Timeline which confirms the switch indeed turns on and off.
I'm using a Sonoff ZBMINI (with neutral line) as a switch.

alias: "Zolder Verlichting beweging "
description: ""
triggers:
  - type: occupied
    device_id: 13d1c08c4154febe2c8afd1bc60e2b62
    entity_id: 7d507c6d4555bb0e7d1fe5e5f2a7f67b
    domain: binary_sensor
    id: Aanwezig
    trigger: device
  - type: not_occupied
    device_id: 13d1c08c4154febe2c8afd1bc60e2b62
    entity_id: 7d507c6d4555bb0e7d1fe5e5f2a7f67b
    domain: binary_sensor
    id: Afwezig
    trigger: device
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Aanwezig
        sequence:
          - type: turn_on
            device_id: 4523d0526cabc130a4e4afc04dc8197c
            entity_id: 1fd37b1e3552b9e28dbfeeca83d98e23
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - Afwezig
        sequence:
          - delay:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
          - type: turn_off
            device_id: 4523d0526cabc130a4e4afc04dc8197c
            entity_id: 1fd37b1e3552b9e28dbfeeca83d98e23
            domain: switch
mode: restart

Is there something I can do to figure out why this happens? And how to solve this?

orchid sky
#

My guess is that it's an issue with the device, or HA communication with the device. What happens if you manually turn the light on in HA?

verbal jewel
#

The device work directly and like expected.

#

I have multiple Sonoff ZBMINI devices, all without problems.
How come the Trace Timeline shows two lines? 'turned on' AND 'turned off' ...

orchid sky
#

I don't know. Device triggers and actions are magic

#

I suspect that it's just telling you about state changes

#

Sometimes when devices don't properly respond to commands to change state, HA will revert to the previous state soon after. You could also have another automation that's triggering when that motion sensor turns on

#

I suggest looking in the logbook for that device to see what it says

verbal jewel
#

I've just made an new automation from scratch, using the same sensor and same switch. And behold, the exact same behaviour....

#

I'll try to filter the Zigbee2Mqtt messages...

orchid sky
#

write a script that just runs that action

#

and do the other things that I suggested above (including looking for another automation)

verbal jewel
#

Just checked there is only one automation that uses the sensor and the switch.

verbal jewel
#
info 2024-12-02 20:07:19z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder Bewegingssensor ', payload '{"battery":100,"battery_low":false,"elapsed":3066688,"linkquality":91,"occupancy":true,"tamper":false,"voltage":3000}'
info 2024-12-02 20:07:19z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder verlichting ', payload '{"elapsed":141257,"linkquality":65,"state":"ON"}'
info 2024-12-02 20:07:19z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder verlichting ', payload '{"linkquality":65,"state":"ON"}'
info 2024-12-02 20:07:19z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder verlichting ', payload '{"elapsed":23,"linkquality":65,"state":"ON"}'
info 2024-12-02 20:07:20z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder verlichting ', payload '{"elapsed":217,"linkquality":76,"state":"OFF"}'
info 2024-12-02 20:07:20z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Zolder verlichting ', payload '{"elapsed":1,"linkquality":76,"state":"OFF"}'
#

Not sure how to show this data more clear... but the log shows that the light is turned on at 20:07:19 and turned off at 20:07:20. So the device does what it's ordered to do, turn on and off.

orchid sky
#

did you check the logbook yet?

verbal jewel
#

Now the question remains, why or who sends these mesages...

orchid sky
verbal jewel
#

These are from the Zigbee2Mqtt log

orchid sky
#

you keep not doing it

verbal jewel
#

I don't understand... I keep not doing what?

orchid sky
#

checking the logbook for the device

#

that tells you what did what to it

verbal jewel
#

The Log above is from Zigbee2Mqtt, my device is "Zolder verlichting" so I think the above log IS from the device...

orchid sky
#

log book

verbal jewel
#

But maybe I'm looking in the wrong place... ?

orchid sky
#

seems so

verbal jewel
#

Settings->System->Logs maybe?

orchid sky
#

no

verbal jewel
#

Ah, I see...

orchid sky
#

logs and logbook are completely different things

verbal jewel
#

The device logbook matches the Zigbee2Mqtt commands.

orchid sky
#

the first two happened at the same time

verbal jewel
#

Yes they did, that's very strange.

#

And the sensor that initiated the trigger:

#

The sensor only shows a single state change at the exact timestamp 20:07:19

#

So to me it seems that a single state change triggers two actions...

#

And I can't find the error in the automation, that's why I posted the YAML above and look for support in this channel.

orchid sky
#

I don't think there's anything wrong with that automation

verbal jewel
#

Do you have any idea if this is worth posting an issue on Github?

mighty lintel
#

What you probably want is to use a timer