Zigbee2MQTT: switch automatically toggles from OFF to ON after 1 second

I got my new Sonoff Mini Zigbee switch installed and paired with Zigbee2MQTT successfully.
https://www.itead.cc/sonoff-zbmini-zigbee-smart-switch.html

However, sometimes when turning the switch ON or OFF, it instantly (within 1-2 secs) toggles back to ON/OFF again.

My automation with a motion sensor shows the same issue (see log below). The last message turns the switch back on after 1 second after it was turned off by the automation:

info  2020-11-13 08:34:06: MQTT publish: topic 'zigbee2mqtt/aqara_motion_sensor_1', payload '{"battery":100,"illuminance":12,"illuminance_lux":12,"linkquality":118,"occupancy":true,"voltage":3025}'
info  2020-11-13 08:34:06: MQTT publish: topic 'zigbee2mqtt/aqara_motion_sensor_1', payload '{"battery":100,"illuminance":12,"illuminance_lux":12,"linkquality":118,"occupancy":true,"voltage":3025}'
info  2020-11-13 08:34:27: MQTT publish: topic 'zigbee2mqtt/sonoff_zbmini_switch_1', payload '{"linkquality":47,"state":"ON"}'
info  2020-11-13 08:35:36: MQTT publish: topic 'zigbee2mqtt/aqara_motion_sensor_1', payload '{"battery":100,"illuminance":12,"illuminance_lux":12,"linkquality":118,"occupancy":false,"voltage":3025}'
info  2020-11-13 08:36:06: MQTT publish: topic 'zigbee2mqtt/sonoff_zbmini_switch_1', payload '{"linkquality":118,"state":"OFF"}'
info  2020-11-13 08:36:06: MQTT publish: topic 'zigbee2mqtt/sonoff_zbmini_switch_1', payload '{"linkquality":118,"state":"OFF"}'
info  2020-11-13 08:36:07: MQTT publish: topic 'zigbee2mqtt/sonoff_zbmini_switch_1', payload '{"linkquality":118,"state":"ON"}'

The log also shows that sometimes duplicate messages are sent at the exact same time: can this do any harm? Is this pointing to the cause of my problem?

Here is the automation:

# Schuur light: turn on when there is movement
- id: "schuur_motion_detected"
  alias: "Schuur light: turn on when there is movement"
  trigger:
    platform: state
    entity_id: binary_sensor.aqara_motion_sensor_1_occupancy
    to: "on"
  condition:
    - condition: numeric_state
      entity_id: sensor.aqara_motion_sensor_1_illuminance
      below: 50
  action:
    service: switch.turn_on
    data:
      entity_id: switch.sonoff_mini_zigbee_1_switch

# Schuur light: turn off after 2 minutes of no motion
- id: "schuur_no_motion_detected_for_2_minutes"
  alias: "Schuur light: turn off after 2 minutes of no motion"
  trigger:
    platform: state
    entity_id: binary_sensor.aqara_motion_sensor_1_occupancy
    to: "off"
    for:
      seconds: 30 # set to 30 seconds because only when there is no movement for about 1:30 minutes the Aqara sensor sends a occupancy off.
  action:
    service: switch.turn_off
    data:
      entity_id: switch.sonoff_mini_zigbee_1_switch

Any help and suggestions are welcome!

Did you ever get this resolved? I’m experiencing the same thing Z2M 1.17.0.1.

I don’t really know what fixed it but after re-installing the switch in the wall it started functioning correctly (probably a loose contact or so).

Please check the wiring instruction and make sure you use the right type of light switch, i.e. with maintained contact and not a momentary toggle switch.