Zigbee2MQTT automation light switch doing its own thing

Hi all,

I’ve had an automation which ran perfectly with ZHA, but having moved to Zigbee2MQTT, it’s no longer working as expected. It’s infuriating me. It works sometimes, then doesn’t.

Basically, a shelly motion sensor detects motion and switches on a Zigbee light switch. Once the detection is changed to false, 2 minutes later, it will switch that light switch off. It works sometimes, then other times just does nothing. Yet the reporting on the automation says everything is fine.

There is however an error showing in the Zigbee2MQTT log, but I am not sure what to make of it… any ideas?

Error from Zigbee2MQTT:

Zigbee2MQTT:error 2022-01-05 18:02:07: Publish 'set' 'state' to 'Utility Room Light Switch' failed: 'Error: Command 0x847127fffef7deca/1 genOnOff.on({}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null,"writeUndiv":false}) failed (no response received)'

The automation is:

 - id: 'utility_room_motion_lights_on'
    alias: utility room motion lights on
    trigger:
    - platform: state
      entity_id: sensor.utility_room_motion
      to: 'True'
    condition:
    - condition: numeric_state
      entity_id: sensor.utility_room_lux
      below: '140'
    action:
    - type: turn_on
      device_id: df623acb13a7d69929028867b228aae7
      entity_id: light.utility_room_light
      domain: light
    mode: single

  - id: 'utility_room_no_motion'
    alias: Utility Room No Motion
    trigger:
    - platform: state
      entity_id: sensor.utility_room_motion
      to: 'False'
      for:
        minutes: 2
    action:
    - service: script.telegram_notification
      data:
        message: "No motion for 2 mins in the utility room"
    - type: turn_off
      device_id: df623acb13a7d69929028867b228aae7
      entity_id: light.utility_room_light
      domain: light
    mode: single

I should add that the light switch (zigbee) was detected as a switch, but I have changed it to a light in the Zigbee2MQTT config. It didn’t change the behaviour at all as this same issue was happening when it was a switch too.

Sensor from shelly is triggered via MQTT

  - platform: mqtt
    name: "utility_room_motion"
    state_topic: "shellies/shellymotionsensor-60A4239A65B6/status"
    value_template: "{{ value_json.motion }}" 

Thanks for any help!