vpomax
(Vpomax)
January 18, 2019, 9:18pm
1
I would like to use this automation to turn on/off my Xiaomi Yeelight with a Aqara Switch button… but it do not works… why?
- 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
kiwinol
(Adam)
January 19, 2019, 8:45am
2
Double check the topic is correct to start with by watching the zigbee2mqtt log or subscribing with mqtt_sub and check that an event is received when you push the button
vpomax
(Vpomax)
January 22, 2019, 10:23pm
3
When I click the xiaomi button the addon zigbee2mqtt log show:
zigbee2mqtt:info 2019-1-22 23:20:58 MQTT publish: topic ‘zigbee2mqtt/0x00158d0001593043’, payload ‘{“click”:“single”,“linkquality”:28,“last_seen”:“2019-01-22T22:20:58.654Z”}’
but nothing happens
tok
January 23, 2019, 9:36am
4
I’m afraid, the mqtt trigger is not flexible enough for your approach. Would you please try the following (adjust to your needs) setup?
For the sensor:
sensor:
- platform: mqtt
name: "aqara_switch_button"
state_topic: "zigbee2mqtt/0x00158d0001593043"
value_template: '{{value_json.click}}'
json_attributes_topic: "zigbee2mqtt/0x00158d0001593043"
And for the trigger part of your automation:
trigger:
platform: state
entity_id: sensor.aqara_switch_button
to: 'single'
No condition needed.
vpomax
(Vpomax)
January 23, 2019, 6:20pm
5
I solved in another way…
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!
Is it correct?
2 Likes
kiwinol
(Adam)
January 24, 2019, 6:19am
6
@vpomax I believe that there is an issue with using an automation like that. I dont think it will trigger if you do 2 single clicks as it wont be change TO single (it will already be single)
This is the reason to use an automation like this:
- alias: "Adam Light Off"
trigger:
- platform: mqtt
topic: 'zigbee2mqtt/Adams_Switch'
- platform: mqtt
topic: 'zigbee2mqtt/Bedroom_Main_Switch'
condition:
condition: and
conditions:
- condition: template
value_template: "{{ 'single' == trigger.payload_json.click }}"
- condition: state
entity_id: light.adams_light_light
state: 'on'
action:
- service: homeassistant.turn_off
entity_id: light.adams_light_light
1 Like
tok
January 24, 2019, 9:24am
7
Nice concept. I tried it for myself and am really impressed. Didn’t know of mqtt triggers before. Thanks a lot for sharing this.
adamtal3
(Adam Tal)
August 22, 2019, 10:50pm
8
Here’s how I got it to toggle a light (changing the ‘single’ to ‘double’ or ‘hold’ also works):
- id: switch_click
alias: Switch click
hide_entity: true
trigger:
platform: state
entity_id: sensor.0x0011110101111111_click
to: 'single'
action:
- service: light.toggle
data:
entity_id: light.light_name
1 Like