Optional state triggers for automation blueprint

Hi,

I’m tryting to create a blueprint for some status displays, which I have in multiple rooms.

For context
I have KNX MDT Glastaster and use exposed input_text entities to send data to them. The text should change based on different external factors, e.g. show the departure time of the bus, when we have breakfast, show the radio station, artist and title when music is playing, and in other circumstances show sensor values like indoor and outdoor temperature, humidity, etc. The automation triggers on state changes of any of these sensors and updates the according input text. This part is not the problem and works fine in an automation for a single display.
Now I want to build a blueprint out of that, so I can reuse it for all displays. But I dont have every type of sensor in every room, also not every room has a media player. So I want to use the blueprint to select the relevant entities for the specific room.

The question
Is it possible to have optional inputs for a blueprint, that are then used as entity in the state trigger? Or is there any other way to achieve a similar result?

Here are two examples for triggers of two seperate automations, with different sets of sensors:

trigger:
  - alias: related object changes Esszimmer
    platform: state
    entity_id:
      - sensor.ez_temp
      - sensor.ez_humid
      - media_player.ez_denon
trigger:
  - alias: Related object changes Wohnzimmer
    platform: state
    entity_id:
      - sensor.wz_temp

So I want to create both triggers in two sperate automations from the same blueprint (with different inputs obviously).
Here is the basic setup of the blueprint:

blueprint:
  domain: automation
  name: KNX Glastaster - Statusdisplay
  input:
    temp_sensor:
      name: Temperature sensor
    humidity_sensor:
      name: Humidity sensor (Optional)
      default: ""
    media_player:
      name: Mediaplayer (Optional)
      default: ""

variables:
  temp_sensor: !input temp_sensor
  humidity_sensor: !input humidity_sensor
  media_player: !input media_player

And here are some of my attempts to define the trigger in the blueprint, none of them are working for more or less obvious reasons.

(I) No Default Value for optional inputs
Omitting the default = "" parameter for optional inputs leads to automations not even initialising, if the respective input is missing. Therefore all optional inputs have to be either set, or have a default value set as done in the example above.

(II) Using !input in the trigger
Defining each entity via !input works generaly fine, unless the input is empty.

trigger:
  - alias: Some related object changes
    platform: state
    entity_id:
      - !input temp_sensor
      - !input humidity_sensor
      - !input media_player

The resulting "" breaks the automation.

trigger:
  - alias: Some related object changes
    platform: state
    entity_id:
      - sensor.wz_temp
      - ""
      - ""

(III) Template for eliminating emtpy entities
In the blueprint:

trigger:
  - alias: Some related object changes
    platform: state
    entity_id: "{{ (temp_sensor,humidity_sensor,media_player) | select() | list }}"

This gets me this trigger in the finished automation, which does not work, as templates are not allowed in the entitiy_id

trigger:
  - alias: Some related object changes
    platform: state
    entity_id: >-
      {{
      (temp_sensor,humidity_sensor,media_player)
      | select() | list }}

As you can probably see, I am out of ideas. It tried some other things aswell, but they were even more desperate and ridiculous then the given examples, therefore they are not worth documenting at all.

Has anyone accomplished something like this? Or has any idea how it could be done?

Thx
CanisLupus

You can do that, but there has to be a valid entity in all of them. and empty string has no state.

You can use a template to check if it has a state before you read it, but that’s likely not what you want either.

There is this but it’s a bit tricky…
Selectors - Home Assistant.

My suggestion for using that would be to add the trigger that includes everything as the default, then delete the things you don’t want to trigger on for this automation .

Thank you for these suggestions.

My “solution” aka workaround in fact is to use non existing entities and checking if their state is unknown in the action: section of the automation if necessary.

input:
  media_player:
    name: Mediaplayer (Optional)
    default: "media_player.dummy"

I generate the automation by leaving the media_player input empty, this results in a valid automation, which would trigger on a non-extistent entity.

trigger:
 - alias: Some related object changes
   platform: state
   entity_id:
     - sensor.knx_wz_temperature
     - sensor.zb_wz_env_humidity
     - media_player.dummy