Hi I’m trying to create a blueprint for a device that sends events from zigbee2mqtt but the discovery_id gives me some troubles…
I have the following blueprint
blueprint:
name: 'Zigbee2MQTT - Hue Tap Dail Switch'
description: |
Control lights with a Philips Hue Tap Switch. Use the four buttons
to control up to four light(s) with an on/off toggle. The dial can be used to
dim the most recently used light.
source https://community.home-assistant.io/t/philips-hue-tap-dial-switch-zha/446636/114
domain: automation
input:
button_sensor:
name: Philips Hue Tap dial switch sensor entity
description: Sensor for Philips Hue Tap dial switch to use
selector:
device:
multiple: false
integration: mqtt
manufacturer: Philips
model: 'Hue Tap dial switch (8719514440937/8719514440999)'
button_sensor_discovery_id:
name: discovery_id
description: 'The first part of the discovery_id "0x001788010d7d3cac"'
selector:
text:
mode: restart
max_exceeded: silent
variables:
button_sensor_discovery_id: !input button_sensor_discovery_id
action_button_1_press_release: "{{ button_sensor_discovery_id }} action_button_1_press_release"
trigger:
- platform: device
domain: mqtt
device_id: !input button_sensor
type: action
subtype: button_1_press_release
discovery_id: "{{ action_button_1_press_release }}"
action:
- service: notify.mobile_app_pixel_6_pro
data:
message: "action_button_1_press_release: {{action_button_1_press_release}}"
Creating it works like a charm and triggering it manually does indeed work, but when pressing the button nothing happens.
If I hardcode the discovery_id value then it works.
So my guess is that discovery_id not support templates/variables?
What changes would be needed in HA to make this work? (I’m willing to make a pull request to make this happen if someone can give me some pointers)
If there is some way to use a variable in discovery_id that I have missed then please enlighten me
Edit:
I have also tried to move my variables into trigger_variables but that didn’t help.
blueprint:
name: 'Zigbee2MQTT - Hue Tap Dail Switch'
description: |
Control lights with a Philips Hue Tap Switch. Use the four buttons
to control up to four light(s) with an on/off toggle. The dial can be used to
dim the most recently used light.
source https://community.home-assistant.io/t/philips-hue-tap-dial-switch-zha/446636/114
domain: automation
input:
button_sensor:
name: Philips Hue Tap dial switch sensor entity
description: Sensor for Philips Hue Tap dial switch to use
selector:
device:
multiple: false
integration: mqtt
manufacturer: Philips
model: 'Hue Tap dial switch (8719514440937/8719514440999)'
button_sensor_discovery_id:
name: discovery_id
description: 'The first part of the discovery_id "0x001788010d7d3cac"'
selector:
text:
mode: restart
max_exceeded: silent
trigger_variables:
button_sensor_discovery_id: !input button_sensor_discovery_id
action_button_1_press_release: "{{ button_sensor_discovery_id }} action_button_1_press_release"
trigger:
- platform: device
domain: mqtt
device_id: !input button_sensor
type: action
subtype: button_1_press_release
discovery_id: "{{ action_button_1_press_release }}"
action:
- service: notify.mobile_app_pixel_6_pro
data:
message: "{{action_button_1_press_release}}"
Personally I hate device triggers and find them pretty much unusable. However I can try to help you.
Your first one could never work because variables are not rendered until after the trigger. So your instincts to use trigger_variables is a good one.
Your next problem is this:
You need to put this into developer - templates and edit it until what you get is what you are trying to get. I would guess that is not giving you the action_button_1_press_release that you want it to, and that is why it isn’t working.
I personally would change this to trigger more generally, IE on every trigger of the device and then in the condition or action statement sort out what the trigger event was and act on it there. In condition statements you have the full set of template functions to work with. In the trigger you only have a few.
But that is a personal choice.
Edit:
But just to be sure I tried the following template in the template editor
{% set button_sensor_discovery_id = '0x001788010d7d3cac' %}
{{ button_sensor_discovery_id }} action_button_1_press_release
And it outputs 0x001788010d7d3cac action_button_1_press_release
which is correct?
Edit 2: I tried to hardcode the trigger variable to "0x001788010d7d3cac action_button_1_press_release" and that also fails, so I’m 99% sure its not the value in the variable that is the issue.
input:
controller:
name: Z2M Controller Name
description: The name of the device, remember device name must have no space or - _
default: ''
base_topic:
name: Z2M Base mqtt topic
description: The base topic z2m
default: zigbee2mqtt
However, I better like to use “state”. Seem easier.