diff --git a/.dictionary b/.dictionary index 87176ae..543bbaf 100644 --- a/.dictionary +++ b/.dictionary @@ -61,3 +61,8 @@ ERP IHK Baden-Wuerttemberg Cottbus +Tradfri +UI +Zigbee2MQTT +Zigbee +MQTT diff --git a/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/images/feature.jpg b/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/images/feature.jpg new file mode 100644 index 0000000..21c988c Binary files /dev/null and b/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/images/feature.jpg differ diff --git a/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/index.md b/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/index.md new file mode 100644 index 0000000..d5ba39c --- /dev/null +++ b/content/posts/2022/use-tradfri-shortcut-button-with-homeassistant/index.md @@ -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). + + + +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 `/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_** \/ **_Integrations_** \/ **_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_** \/ **_\_**. + +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 +``` diff --git a/src/static/custom.css b/src/static/custom.css new file mode 100644 index 0000000..e3812ab --- /dev/null +++ b/src/static/custom.css @@ -0,0 +1,3 @@ +:root { + --code-max-height: 60rem; +}