post: Use Tradfri Shortcut Button with Home Assistant
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Robert Kaussow 2022-08-22 23:03:57 +02:00
parent 270d31d16e
commit 230743a862
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
4 changed files with 120 additions and 0 deletions

View File

@ -61,3 +61,8 @@ ERP
IHK IHK
Baden-Wuerttemberg Baden-Wuerttemberg
Cottbus Cottbus
Tradfri
UI
Zigbee2MQTT
Zigbee
MQTT

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 KiB

View File

@ -0,0 +1,112 @@
---
title: "Use Tradfri Shortcut Button with Home Assistant"
date: 2022-08-22T21:35:25+02:00
authors:
- robert-kaussow
tags:
- Automation
resources:
- name: feature
src: "images/feature.jpg"
params:
anchor: Center
credits: >
[Artem Bryzgalov](https://unsplash.com/@abrizgalov) on
[Unsplash](https://unsplash.com/s/photos/switch)
---
Sometimes it can be helpful if single actions or entire automation in your Home Automation can be triggered with a physical button and not only from the Web UI. I'm using Zigbee2MQTT as a generic Zigbee to MQTT bridge as it supports a lot of different Zigbee devices and integrates flawlessly into Home Assistant. As I have a lot of different Tradfri Lamps in use already, I have bought a few of the Tradfri Shortcut Button (E1812).
<!--more-->
Pairing the Buttons with the [Zigbee2MQTT](https://www.zigbee2mqtt.io) coordinator was simple as usual, but I had some trouble to figure out how to use it in [Home Assistant](https://www.home-assistant.io/docs). Zigbee2MQTT recommends to use the [MQTT device triggers](https://www.zigbee2mqtt.io/guide/usage/integrations/home_assistant.html#via-mqtt-device-trigger-recommended) but the documentation wasn't that clear on this part.
The first thing to do is to figure out the available triggers of the device. Triggers are published to the MQTT topic `<discovery_prefix>/device_automation/` and we can subscribe to is to discover the messages. To subscribe to an MQTT topic we can use the `mosquitto_sub` CLI command e.g. `mosquitto_sub -h 192.168.0.1 -p 8883 -u user -P secure-password -t homeassistant/device_automation/#` or the Home Assistant UI at **_Settings_** \/ **_Devices & Services_** \/ <!-- spellchecker-disable -->**_Integrations_**<!-- spellchecker-enable --> \/ **_MQTT_** \/ **_Configure_** \/ **_Listen to a topic_**.
After subscribing to the topic, remember that device triggers are not published until the event has been triggered at least once on the device. Afterwards the following triggers should be listed for the Tradfri Button:
```Json
{
"automation_type": "trigger",
"device": {
"identifiers": [
"zigbee2mqtt_0x84b112233445566"
],
"manufacturer": "IKEA",
"model": "TRADFRI shortcut button (E1812)",
"name": "livingroom/switch_test",
"sw_version": "2.3.080"
},
"payload": "off",
"subtype": "off",
"topic": "zigbee2mqtt/livingroom/switch_test/action",
"type": "action"
}
{
"automation_type": "trigger",
"device": {
"identifiers": [
"zigbee2mqtt_0x84b112233445566"
],
"manufacturer": "IKEA",
"model": "TRADFRI shortcut button (E1812)",
"name": "livingroom/switch_test",
"sw_version": "2.3.080"
},
"payload": "brightness_stop",
"subtype": "brightness_stop",
"topic": "zigbee2mqtt/livingroom/switch_test/action",
"type": "action"
}
{
"automation_type": "trigger",
"device": {
"identifiers": [
"zigbee2mqtt_0x84b112233445566"
],
"manufacturer": "IKEA",
"model": "TRADFRI shortcut button (E1812)",
"name": "livingroom/switch_test",
"sw_version": "2.3.080"
},
"payload": "brightness_move_up",
"subtype": "brightness_move_up",
"topic": "zigbee2mqtt/livingroom/switch_test/action",
"type": "action"
}
{
"automation_type": "trigger",
"device": {
"identifiers": [
"zigbee2mqtt_0x84b112233445566"
],
"manufacturer": "IKEA",
"model": "TRADFRI shortcut button (E1812)",
"name": "livingroom/switch_test",
"sw_version": "2.3.080"
},
"payload": "on",
"subtype": "on",
"topic": "zigbee2mqtt/livingroom/switch_test/action",
"type": "action"
}
```
Great, with this data we are almost done. The only missing information is the `device_id`. I have not found a nice way to get this ID yet, but it is part of the URL after navigating to **_Settings_** \/ **_Devices & Services_** \/ **_Devices_** \/ **_\<device\>_**.
Finally we can add an action to the button. The example below is starting the Vacuum cleaner on a `single_click` (`on`) trigger:
```YAML
- alias: Start Vaccum
trigger:
- platform: device
domain: mqtt
device_id: 61b011e2e7d5e111111d8d804a029f61
type: action
subtype: "on"
discovery_id: 0x84b112233445566 action_on
action:
- service: vacuum.start
target:
entity_id: vacuum.valetudo_rockrobo
```

3
src/static/custom.css Normal file
View File

@ -0,0 +1,3 @@
:root {
--code-max-height: 60rem;
}