Example automation in Wiki not working
I'm trying to set up an automation in Home Assistant using the example in the Wiki: https://github.com/Koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant
but it just doesn't work... has anyone event tested it?
You should give more details about your installation or logs... because I think most of the users of zigbee2mqtt are successfully using it with Home Assistant.
What do you mean by it just doesn't work?
- Did you check the logs for error details? You can also enable debug mode https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-debug.
- Do you see the connection on your MQTT broker?
- Do you see any MQTT traffic?
The settings there are the setups for e.g. sensor not an automation.
Example for a round Xiaomi button
automation:
- alias: single
trigger:
platform: mqtt
topic: 'zigbee2mqtt/xiaomibutton'
condition:
condition: template
value_template: "{{ 'single' == trigger.payload_json.click }}"
action:
- service: scene.turn_on
entity_id: scene.vr_1
You use the linked siteto look for the condition templates.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I think he is right, the syntax in the wiki example is broken
@caffeineflo could you provide your zigbee2mqtt logging and your automation configuration? The example on the wiki works fine in my case.
@Koenkk I don't think there's really much you can do. If you paste the yaml into your configuration the indentation gets screwed up due to the way it's displayed through HTML.
The only way of making this better that I can think of, is keeping the automation content in a separate file and link to the raw file on GH. That would prevent that issue for most people
I have the same problem, my automation:
- alias: Switch Yeelight trigger: platform: mqtt topic: 'zigbee2mqtt/sensor.0x00158d0001593043_click' condition: condition: template value_template: "{{ 'single' == trigger.payload_json.click }}" action: service: light.toggle entity_id: light.yeelightw1
it do not works...
in the log of zigbee2mqtt I found:
zigbee2mqtt:info 2019-1-23 09:56:32 MQTT publish: topic 'zigbee2mqtt/0x00158d0001593043', payload '{"battery":100,"voltage":3032,"linkquality":28,"last_seen":"2019-01-23T08:56:32.381Z","click":"single"}'
but nothing happens
The topic does not match ʼzigbee2mqtt/sensor.0x00158d0001593043_clickʼ vs ʼzigbee2mqtt/0x00158d0001593043ʼ
and then... what can I do?
I tried to edit topic with:
topic: 'zigbee2mqtt/0x00158d0001593043'
but it do not works
Use zigbee2mqtt/0x00158d0001593043 in your automation as topic since this is where zigbee2mqtt is sending the event.
I have just did it but unsuccesfull...
Mhh... Can you check your home assistant log book to see if the automation gets triggered?
NO! in logbook I found only.... "0x00158d0001593043_click changed to single" without the automation I called "Switch Yeelight"
why it do not start the automation?
Good question! I don't have access to my configuration at the moment but I have it working :wink:
Temporarily I solved in another way... not using template mqtt but using template: state
Since my Hassio discover Xiaom switch and call it "sensor.0x00158d0001593043_click" I created a new automation...
- alias: Turn_on_off_yeelight
trigger:
platform: state
entity_id: sensor.0x00158d0001593043_click
to: 'single'
action:
service: light.toggle
entity_id: light.yeelightw1
and it works fine! Then is the automation based on mqtt that don't works
I tried that already, too. The downside of this is that this only works if the state actually changes. When you press the button, wait and press it again this triggered the automation only once instead of twice for me.
No.... I just configured this action based on a "double" click... and it works fine! :-)
This for me is better than "template mqtt" that are complicated to write... but I don't know if it works in any condition
- alias: Turn_on_off_yeelight
trigger:
platform: state
entity_id: sensor.0x00158d0001593043_click
to: 'double'
action:
service: light.toggle
entity_id: light.yeelightw1
This is my config with mqtt:
- alias: Xiaomi - TV Schrank
hide_entity: true
initial_state: 'on'
trigger:
- platform: mqtt
topic: zigbee2mqtt/wohnzimmer.switch
condition:
- condition: and
conditions:
- condition: template
value_template: '{{ trigger.payload_json.click is defined }}'
- condition: template
value_template: '{{ "single" in trigger.payload_json.click }}'
action:
- service: switch.toggle
entity_id: switch.wohnzimmer_light_tv_vitrine_switch
The topic is zigbee2mqtt/<friendlyName> as configured in data/configuration.yaml