Zigbee2MQTT and Automations

Anyone one willing to shed some light on automations? I’m trying to setup my new setup and I can’t get it to run. Specifically using Zigbee2MQTT. I found very specific examples matching my issue but the accepted solutions don’t seem to work.

What I am trying to do: I have a Xiaomi WXKG11LM button switch connected to HA via Zigbee2MQTT and I want to control a couple TP-Link HS100s with it.

I can see the messages appearing through zigbee (copied below) and the devices in HA. The automation isn’t triggering though. I’m sure it is something with my auotmations.yaml but I can’t tell what is wrong. Any thoughts?

Zigbee2MQTT Output:

zigbee2mqtt:info  2020-01-12 12:48:38: MQTT publish: topic 'zigbee2mqtt/0x00158d0002904e05', payload '{"battery":100,"voltage":3055,"linkquality":70,"click":"single"}'
zigbee2mqtt:info  2020-01-12 12:48:38: MQTT publish: topic 'zigbee2mqtt/0x00158d0002904e05', payload '{"battery":100,"voltage":3055,"linkquality":70,"click":""}'
zigbee2mqtt:info  2020-01-12 12:48:42: MQTT publish: topic 'zigbee2mqtt/0x00158d0002904e05', payload '{"battery":100,"voltage":3055,"linkquality":55,"click":"double"}'
zigbee2mqtt:info  2020-01-12 12:48:42: MQTT publish: topic 'zigbee2mqtt/0x00158d0002904e05', payload '{"battery":100,"voltage":3055,"linkquality":55,"click":""}'

automations.yaml: I have copied the entire filre. All the different ones I have tried are commented out-

id: '1578848851979'
  alias: Turn on Bedroom Lights
  description: ''
  hide_entity: true
  trigger:
    platform: state
    entity_id: sensor.0x00158d0002904e05_click
    to: 'single'
  action:
  - device_id: 16f5e3730e254c1e9b05bbca817862f6
    domain: switch
    entity_id: switch.bedroom_floor_lamp
    type: turn_on
# - alias: Turn on Lyndseys Lamp
#   trigger:
#     platform: state
#     entity_id: sensor.0x00158d0002904e05_click
#     to: 'double'
#   action:
#   - data:
#     entity_id: switch.bedroom_floor_lamp
#     type: switch.turn_on
#
# - id: '1578846412196'
#   alias: Turn on Lyndseys Lamp
#   trigger:
#   - platform: mqtt
#     topic: 'zigbee2mqtt/0x00158d0002904e05'
#   condition:
#   - condition: template
#     value_template: '{{ "double" == trigger.payload_json.click }}'
#   action:
#   - device_id: 16f5e3730e254c1e9b05bbca817862f6
#     domain: switch
#     entity_id: switch.bedroom_floor_lamp
#     type: turn_on
#
# - id: toggle_my_light
#   alias: Turn_on_off_yeelight
#   trigger:
#       platform: state
#       entity_id: sensor.0x00158d0002904e05_click
#       to: 'single'
#   action:
#       service: switch.toggle
#       entity_id: switch.bedroom_floor_lamp

I’ve found that with buttons like that, you may need to enable debounce in Zigbee2MQTT. I set a value of 0.5 for my (Hue) remote, and after that it worked as expected.

I would have though that too, but the automation doesn’t even trigger if I set the state of the button in Developer Tools. I haven’t seen anyone else mention debounce either.

Should I be seeing automations in developer tools under state? I am not seeing any automations I create show in there.

I got one working. I tried all sorts of things, including having it create a new automations.yaml file by renaming the old one and restarting. What ended up working was creating the automation in the UI, which didn’t work. But Then I made a few test ones based on time etc. Then those showed in Developer Tools states so I could trigger them. I modified one of those to by copying and pasting the trigger and action pieces from a an automation I tried but failed to get working and then it worked. I have no idea why it wasn’t working then and why it is working now. The spacing and indents etc were exactly the same as one I tried previously.

Here is my entire automations.yaml file for anyone interested:

- id: '1578869381543'
  alias: Bedroom Lights
  description: ''
  trigger:
  - entity_id: sensor.0x00158d0002904e05_click
    platform: state
    to: single
  condition: []
  action:
  - device_id: 16f5e3730e254c1e9b05bbca817862f6
    domain: switch
    entity_id: switch.bedroom_floor_lamp
    type: toggle
1 Like