#Handling hundreds/thousands of automations

1 messages · Page 1 of 1 (latest)

knotty sequoia
#

I have over 100 wired motion sensors directly connected to an Elk M1 alarm panel.

I have over 100 Zooz z-wave switches for automating lights.

I have 17 in-ceiling voice assistants with mmWave sensors.

I was hoping that I could use label or area generically and build a single motion activated light automation but it doesn’t appear that automations support labels/areas (sample code)

alias: Motion → Lights ON (ELK + Timers)
description: ""
triggers:

  • event_type: state_changed
    trigger: event
    conditions:
  • condition: template
    value_template: >
    {% set e = trigger.event.data.entity_id %} {% set n =
    trigger.event.data.new_state %} {{
    e is not none
    and e.startswith('sensor.elkm1_zone_')
    and n is not none
    and n.state == 'violated'
    }}
    actions:
  • target:
    entity_id: "{{ timers }}"
    action: timer.cancel
  • target:
    entity_id: |
    {{ lights | select('is_state', 'off') | list }}
    action: light.turn_on
    mode: parallel
    variables:
    room_labels: "{{ trigger.event.data.entity_id | labels }}"
    lights: |
    {{ label_entities(room_labels)
    | select('search', '^light.')
    | list }}
    timers: |
    {{ label_entities(room_labels)
    | select('search', '^timer.')
    | list }}
cedar garnet
#

I'm not at my computer now so can't easily give you an example of this but it's doable with a template trigger and an input number helper.
Trigger is something like: {{ label_entities(label) | select('is_state', 'on') | list | count != states(input number) | int}}
You then save the new number of "on" entities into the input number as part of the automation actions

#

You can access which entity actually caused the change with trigger entity and to_state

#

If you want to make explicit turn on and turn off automations rather than one that handles both use <> rather than !=

#

You'll obviously have to add some filtering on the room_labels - just start every controllable zone with some specific text or something (also makes it easier to sort your labels when you have a bunch)