Luligu / zigbee2mqtt-automations

Automations extension for zigbee2mqtt
MIT License
15 stars 2 forks source link

Automation misinterpreting action payload #5

Closed robvanoostenrijk closed 1 week ago

robvanoostenrijk commented 1 week ago

Defined is the following automation:

    remote_den_off:
      active: true
      trigger:
      - entity: Remote - Den
        action: off
      action:
      - entity: Smart Bulb - Desk
        payload: turn_off
      - entity: Airconditioning - Den
        payload: { current_heating_setpoint: 28, preset: manual, system_mode: cool }

In Zigbee2MQTT this generates the following in the log:

info:   z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Remote - Den/action', payload 'on'
info:   z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Airconditioning - Den', payload '{"child_lock":"UNLOCK","current_heating_setpoint":"cool","deadzone_temperature":1,"fan_mode":"high","linkquality":65,"local_temperature":28,"local_temperature_calibration":0,"preset":"manual","schedule":"06:00/20 11:30/21 13:30/22 17:30/23 06:00/24 12:00/23 14:30/22 17:30/21 06:00/19 12:30/20 14:30/21 18:30/20","state":"ON","system_mode":"cool","system_mode_device":"cool"}'
error:  z2m: Publish 'set' 'current_heating_setpoint' to 'Airconditioning - Den' failed: 'Error: Don't know how to send type 'object''

Updating the automation as follows resolves the issue:

remote_den_off:
  active: true
  trigger:
  - entity: Remote - Den
    action: off
  action:
  - entity: Smart Bulb - Desk
    payload: turn_off
  - entity: Airconditioning - Den
    payload: { system_mode: cool, preset: manual, fan_mode: auto, current_heating_setpoint: 28 }

Interestingly enough, the failed Z2M MQTT message causes MatterBridge to end up failing its session. I will report this as an issue separately on MatterBridge.

robvanoostenrijk commented 1 week ago

I looked into this further, and its not an error with zigbee2mqtt-automations, but zigbee2mqtt parsing potentially invalid JSON.

This happened because I used the examples from zigbee2mqtt-automations:

  action:
    - entity: Miboxer RGB led controller
      payload: { brightness: 255, color: { r: 0, g: 0, b: 255 }, transition: 5 }
    - entity: Moes RGB CCT led controller
      payload: { brightness: 255, color_temp: 500, transition: 10 }

The JSON objects in these, do not use quoting which apparently can configure zigbee2mqtt message parsing.

For my example above, the correct YAML would be:

remote_den_on:
  active: true
  trigger:
  - entity: Remote - Den
    action: on
  action:
  - entity: Airconditioning - Den
    logger: info
    payload: { "system_mode": "cool", "preset": "manual", "current_heating_setpoint": 26 }

I cross-verified this with the following MQTT messages:

mosquitto_pub -t 'zigbee2mqtt/Airconditioning - Den/set' -m '{ "system_mode": "cool", "preset": "manual", "current_heating_setpoint": 26 }'

versus

mosquitto_pub -t 'zigbee2mqtt/Airconditioning - Den/set' -m '{ system_mode: cool, preset: manual, current_heating_setpoint: 26 }'

Without the quoted JSON, zigbee2mqtt will set:

{"current_heating_setpoint":26,"preset":"manual","system_mode":26}

With quoted JSON, zigbee2mqtt will set:

{"current_heating_setpoint":26,"preset":"manual","system_mode":26}

Closing this issue, as its not a zigbee2mqtt-automations issue.