MATCH_ALL state trigger?

Hi there,

I’m trying to streamline some of my configuration. To this end, I would like to use some kind of “catch-all” trigger and then match it later on with my own with templates. Here’s my working example:

- alias: Fernbedienung Komplett
  id: fernbedienung
  trigger:
  #- platform: template
  #  value_template: "true"
  #- platform: template
  #  value_template: '{{ "elro_800_switch_s15" in trigger.to_state.name and trigger.to_state.state == "on" }}'
  #- platform: state
  #  to: 'on'
  #  entity_id: '*'
  - platform: state
    to: 'on'
    entity_id:
    - binary_sensor.elro_800_switch_s15_ua_on
    - binary_sensor.elro_800_switch_s15_ua_off
    - binary_sensor.elro_800_switch_s15_ub_on
    - binary_sensor.elro_800_switch_s15_ub_off
    - binary_sensor.elro_800_switch_s15_uc_on
    - binary_sensor.elro_800_switch_s15_uc_off
    - binary_sensor.elro_800_switch_s15_ud_on
    - binary_sensor.elro_800_switch_s15_ud_off
  #condition:
  #- condition: template
  #  value_template: '{{ "elro_800_switch_s15" in trigger.to_state.name and trigger.to_state.state == "on" }}'
  action:
    service: script.toggle_it
    data_template:
      entity: >
        {% if   'ua_on'  in trigger.to_state.name %}
        switch.wohnzimmer_buchregal
        {% elif 'ua_off' in trigger.to_state.name %}
...

But I don’t like listing all those entity ids. It makes my automations hard to maintain. So, I’d like to use on of the other triggers instead.

I have tested the condition with the state trigger and its long entity list: It allows all the state events to actually run the action. So, the condition should be fine. The problem seems that the automation does not even get there, if I use one of the other triggers.

I think, the template triggers don’t work, because:

  1. “trigger” is not a recognized variable in the trigger itself yet. (So says the error, I receive.)
  2. They only fire, when one of the mentioned entities changes its state. So “true” won’t ever fire. [Why won't this trigger?!]

The * entity_id however, should work. There is something in the code called MATCH_ALL. But when I use it, the automation is never started at all.

Here’s the code lines, whch I think should do the job…

What am I missing?

Thanks!
Andreas

Maybe you could use a state changed event without specifying an entity ID? But even if this wound work, I suspect it would be a very bad idea as the automation would be basically constantly triggered / conditioned.

You say your automations become difficult to handle. How often are you updating your sensors? :slight_smile: Perhaps you could instead create a template sensor that you update once a sensor in the list you manually maintain changes state, and trigger your automatons based on that template sensor.

Hi Dolores,

thanks for your answer!

  1. The entity_id is a required parameter for a state Trigger. So, HA does not even load without this Parameter.
  2. I am changing the sensors quite often, because I am in the Phase of finding my best Setup. :slight_smile: And if only Change the naming conventions, I will always have to correct it 8 times in this single Automation alone…
  3. The template sensor sounds like a Sound idea. At least for Automation triggering.

Thanks also for the hint on the Performance! I was having second thoughts on this as well. So, will the “condition” be much slower than “matching” the Events?

Andreas

Silly question, why don’t you try and group your entities?
I’m not entirely sure what your automations do so there may be an issue / more work needed with your conditions/actions, but you would only have your group in triggers…

Thanks, @lolouk44. This sounds like a neat idea.

Unfortunately, I need to list my states in the group then, so it would not really help. Unless I have more automations, of course.

Also, the group’s state would not be changed with every state change of the group’s elements, since the ‘on’ state is just an or-combination of all the group’s elements.

You always have to list entity_id’s for triggers. Even if you were able to ‘loop through’ a group of entity_id’s, the trigger would never fire because triggers work off entity_id’s. If you feed it code without entity_id’s, the trigger doesn’t know what to watch.

EDIT: This is the same for any template sensor/device. They need entity_id’s to update.