It took me a lot of time to find out how to make Automation with MQTT Device Triggers, as they are fairly new addition and it’s not entirely clear.
Here is an example of how it can be done with homeassistant_legacy_triggers: true
. It’s a dummy example showing it on IKEA Floalt LED Panel.
alias: Example with Triband Aqara switch with MQTT Device Triggers
variables:
# you have to find this via first selecting the device via UI automation editor
device_id: d54bba99c4c741b8bc41118918730630
trigger:
- platform: device
domain: mqtt
type: action
subtype: button_1_single
# you have to find this via first selecting the device via UI automation editor
discovery_id: 0x04cf8cdf3c7d8f7a action_button_1_single
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_1_hold
discovery_id: 0x04cf8cdf3c7d8f7a action_button_1_hold
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_1_release
discovery_id: 0x04cf8cdf3c7d8f7a action_button_1_release
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_2_single
discovery_id: 0x04cf8cdf3c7d8f7a action_button_2_single
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_2_hold
discovery_id: 0x04cf8cdf3c7d8f7a action_button_2_hold
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_2_release
discovery_id: 0x04cf8cdf3c7d8f7a action_button_2_release
device_id: '{{ device_id }}'
- platform: device
domain: mqtt
type: action
subtype: button_2_double
discovery_id: 0x04cf8cdf3c7d8f7a action_button_2_double
device_id: '{{ device_id }}'
action:
- variables:
command: '{{ trigger.payload }}'
- choose:
- conditions:
- condition: template
value_template: '{{ command in [''button_1_single'', ''button_2_single''] }}'
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/FloaltAlpha/set
payload: '{"color_temp_step": -150}'
- conditions:
- condition: template
value_template: '{{ command == ''button_1_hold'' }}'
sequence:
- repeat:
until:
- condition: template
value_template: '{{ trigger.payload == ''button_1_release'' }}'
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/FloaltAlpha/set
payload: '{"color_temp_step": 10}'
- delay: '0.3'
- conditions:
- condition: template
value_template: '{{ command == ''button_2_hold'' }}'
sequence:
- repeat:
until:
- condition: template
value_template: '{{ trigger.payload == ''button_2_release'' }}'
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/FloaltAlpha/set
payload: '{"color_temp_step": -10}'
- delay: '0.3'
- conditions:
- condition: template
value_template: '{{ command == ''button_2_double'' }}'
sequence:
- service: mqtt.publish
data:
topic: zigbee2mqtt/FloaltAlpha/set
payload: '{"dummy": "example"}'
mode: restart
max_exceeded: silent