In the action section the device_id seems a bit superfluous and obscure but if I remove the device_id lines I get ‘Message malformed: Unable to determine action @ data[‘action’][0]’. Is there a better way of doing this if I was writing by hand, that is more human readable?
Also the trigger device is called ‘sensor_button_pressed’. Is there a way of refuring to it by name rather than device_id?
I added a second Trigger as an event trigger but cant figure it out (just kept it there for reference, will delete later). I looked at Automation Trigger - Home Assistant but cant figre out the event type. The GUI does not have a pick list and cant find a lit is docs.
Is the closest I can find but its not quite right. Ive set the entity to ‘button.ben_bed_button’. Looked in Developer Tools → States to find atributes but no joy. Also trying to figre out platform. Did a google search on ‘platform homeassistant button’ but did not find anything usefull. Also wondering (and did some googleing) about doble click with nothing usefull.
You can monitor events in Developer Tools > Events. A Zigbee Home Automation (ZHA) event contains data like this (I copied this example from someone else’s post):
Based on that ZHA event example, we can create an Event Trigger like this:
alias: Ben Room Wake Up
description: ""
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: 41d62e5f1d793db5214849ba0a1a6faa
command: remote_button_double_press
condition: []
action:
- service: homeassistant.turn_on
target:
entity_id:
- light.ben_bedroom_uplighters
- switch.plug_ben_1_amp_screen_laptop
mode: single
NOTE
If you ever need the value of a device’s device_id you can get it by using one of the following methods:
Go to Developer Tools > Template and use the following template. Replace light.example with any of the entities that belong to your device.
{{ device_id('light.example') }}
Go to Settings > Devices & Services > Devices and click the desired device. The value of its device_id will be displayed in the web page’s URL. For example: homeassistant.local:8123/config/devices/device/32175889ed5ab277dDE78b935798f5d
Thanks for that, all verry usefull. I took a leap of fathe and tried
alias: Ben Room Wake Up
description: ""
trigger:
- platform: event
event_type: remote_button_double_press
condition: []
action:
- service: light.turn_on
target:
entity_id:
- light.ben_bedroom_uplighters
data: {}
- service: switch.turn_on
target:
entity_id: switch.plug_ben_1_amp_screen_laptop
data: {}
mode: single
And it worked. I tried adding event_id and trigger: event_id: but it was malformed. Alough it works I fear it is not targeting the specific button, currently I only have one but when I have several feels this will fire for them all? I was trying not to use device_id in trigger. Love the ‘service: homeassistant.turn_on’. So feels as bit conseptualy like *.turn_on.
Go to Developer Tools > Events and set it up to listen for ZHA events. Then double-press your device’s button. The generated ZHA event will be displayed and you’ll see exactly what you need to configure an Event Trigger.
You’re right; it’s not. It’s triggering for anything that produces a remote_button_double_press event_type.
What does your device provide on sensors, binary_sensors or whatever? Or just, what device is this remote?
Right now, we only know, that you get an event, if the button is pressed. Maybe the remote provides something like a sensor with a state. I can only speak for my remote (it’s an IKEA Tradfri), and there I get a state similar to the action performed on the button. So when I press once, I get a state of arrow_right_click in my sensor.tradfri_remote. With this I can set the trigger to a state trigger and can avoid all device thingys in my config.
I didn’t post that kind of example because, as you can see from the sample ZHA event I posted above, the ZHA event does not contain an entity_id key. Therefore it’s not possible to do what you hoped to do here:
Regarding the use of a template, be aware that a Device Trigger does not support templating. Therefore you cannot do this:
However, I believe an Event Trigger supports templating so you can try this:
alias: Ben Room Wake Up
description: ""
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: "{{ device_id('button.ben_bed_button') }}"
command: remote_button_double_press
condition: []
action:
- service: homeassistant.turn_on
target:
entity_id:
- light.ben_bedroom_uplighters
- switch.plug_ben_1_amp_screen_laptop
mode: single
OK this is weard. I did 2 single clicks, a long click and a doble click. Everything worked as expected (I hade the original working trigger with device_id). But
So the command for long and doule click is both toggle, but how does it konw the diference. As I said everything is working fine. If I do two doble clicks it does nothing the second time).
I am afraid it does not work. Thanks for your help. I am going to have to leave it for now. Also this thread is geting quite long so seems best if I start another one focusing on the specific trigger question with a more targeted subject so others can more easily find it.
PS I actualy thought that may be the trigger, just could not figure how it diferentiated between doble tap and long press.
This topic’s title already describes the goal adequately for anyone searching how to specify something other than a device_id. Plus the example involves detecting a ZHA event which will be of interest to the many users of the ZHA integration.
Let’s isolate what does/doesn’t work. Here are four simple automations designed to report button events via a persistent notification. Try all four and see what does/doesn’t work.
alias: Button Event Version 1
description: "Detect all button events for device"
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: 41d62e5f1d793db5214849ba0a1a6faa
condition: []
action:
- service: notify.persistent_notification
data:
title: Button Event Version 1
message: "{{ trigger.event.data.command }}"
mode: single
You’ll notice that versions 2 and 4 use a Template Condition to detect the command type. Based on examples found elsewhere, this is a fairly common way to do it (as opposed to employing a command option in the Event Trigger).
Thanks, will give this a try but moving house this weekend so lots to do. Luckely everything is using a router I am going to take with me and use exclusivly for home automation.
Thanks a lot for all your help. Will get back to this next week.