zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Example automation in Wiki not working

Open mario-g0 opened this issue 8 years ago • 18 comments

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?

mario-g0 avatar Oct 18 '18 15:10 mario-g0

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?

  1. Did you check the logs for error details? You can also enable debug mode https://github.com/Koenkk/zigbee2mqtt/wiki/How-to-debug.
  2. Do you see the connection on your MQTT broker?
  3. Do you see any MQTT traffic?

carldebilly avatar Oct 18 '18 17:10 carldebilly

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.

Underknowledge avatar Oct 18 '18 19:10 Underknowledge

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.

stale[bot] avatar Dec 18 '18 15:12 stale[bot]

I think he is right, the syntax in the wiki example is broken

caffeineflo avatar Jan 20 '19 00:01 caffeineflo

@caffeineflo could you provide your zigbee2mqtt logging and your automation configuration? The example on the wiki works fine in my case.

Koenkk avatar Jan 21 '19 09:01 Koenkk

@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

caffeineflo avatar Jan 21 '19 18:01 caffeineflo

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

vpomax avatar Jan 23 '19 08:01 vpomax

The topic does not match ʼzigbee2mqtt/sensor.0x00158d0001593043_clickʼ vs ʼzigbee2mqtt/0x00158d0001593043ʼ

sehraf avatar Jan 23 '19 09:01 sehraf

and then... what can I do? I tried to edit topic with: topic: 'zigbee2mqtt/0x00158d0001593043' but it do not works

vpomax avatar Jan 23 '19 09:01 vpomax

Use zigbee2mqtt/0x00158d0001593043 in your automation as topic since this is where zigbee2mqtt is sending the event.

sehraf avatar Jan 23 '19 09:01 sehraf

I have just did it but unsuccesfull...

vpomax avatar Jan 23 '19 09:01 vpomax

Mhh... Can you check your home assistant log book to see if the automation gets triggered?

sehraf avatar Jan 23 '19 09:01 sehraf

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?

vpomax avatar Jan 23 '19 10:01 vpomax

Good question! I don't have access to my configuration at the moment but I have it working :wink:

sehraf avatar Jan 23 '19 10:01 sehraf

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

vpomax avatar Jan 23 '19 10:01 vpomax

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.

sehraf avatar Jan 23 '19 10:01 sehraf

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

vpomax avatar Jan 23 '19 10:01 vpomax

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

sehraf avatar Jan 23 '19 16:01 sehraf