core: mqtt device trigger -> discovery_id does not work with trigger_variables?

The problem

Hi I have the following blueprint that works as expected

blueprint:
  name: 'Test'
  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)'
mode: restart
max_exceeded: silent
trigger:
  - platform: device
    domain: mqtt
    device_id: !input button_sensor
    type: action
    subtype: button_1_press_release
    discovery_id: '0x001788010d7d3cac action_button_1_press_release'
action:
  - service: notify.mobile_app_pixel_6_pro
    data:
      message: "Test"

But if I move the value of discovery_id into trigger_variables and use a template in discovery_id then it no longer works?

blueprint:
  name: 'Test'
  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)'
mode: restart
max_exceeded: silent
trigger_variables:
  action_button_1_press_release: '0x001788010d7d3cac 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: "test"

It no longer works?

What version of Home Assistant Core has the issue?

core-2023.12.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

mqtt

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mqtt/

Diagnostics information

No response

Example YAML snippet

blueprint:
  name: 'Test'
  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)'
mode: restart
max_exceeded: silent
trigger_variables:
  action_button_1_press_release: '0x001788010d7d3cac 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: "test"

Anything in the logs that might be useful for us?

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 6 months ago
  • Comments: 21 (17 by maintainers)

Most upvoted comments

This should make it possible to use templating for discovery_id, type and sub_type. using the trigger_variables:

https://github.com/home-assistant/core/pull/107830

Trigger variables will be inserted for use inside the template, further all template features are available including the state of the device automation as this

device_attr might not be available in the trigger_variables, but with the PR it can be used directly in a template on discovery_id.

I think I managed to get my case working with a mqtt trigger instead, but haven’t tested it fully yet, if it fails I will try this patch.

Well technically, this is not a fix, but a feature request, and this is not the place to register that.

You can register it here: https://community.home-assistant.io/c/feature-requests/13

Or open a PR.