I am looking for a convenient way to reduce 7 automations into one. They are all doing more or less the same, only the room changes.
This is one of the mentioned automations:
alias: Office Light Sync
description: Sync lights in the office
trigger:
- entity_id:
- switch.office_passive
- light.office_passive
platform: state
to: 'on'
from: 'off'
- platform: state
entity_id: 'switch.office_passive,light.office_passive'
to: 'off'
from: 'on'
condition:
- condition: template
value_template: "{{ states('light.office_passive') != states('switch.office_passive') }}"
action:
- service_template: "homeassistant.turn_{{trigger.to_state.state}}"
data:
entity_id: >-
{% if trigger.entity_id == "light.office_passive" %} switch.office_passive
{% else %} light.office_passive {% endif %}
mode: single
So the automation synchronises the wall-switch with my zigbee lights.
I have similar automations for 6 other rooms. Has anyone an idea on how to merge those automations? I aim on reducing the number of automations and the amount of maintenance.
I am thinking about * and variables, but would be interested, if anyone has done something similar and can give a working option.
As far as I know the blueprint just helps me creating several automations. I would like to reduce the number of automations as well as reducing amount of maintenance.
But if blueprints are the only way to solve this I will try them out. Thanks for your suggestion.
With using a single, parametrized blueprint, you will still have 7 automations, but they only define the parameter values and benefit from every improvement you apply to the blueprint.
Personally (despite being a “programmer”) prefer easy to read, YaML only automations over heavily-scripted onces.
True, but can’t you make one automation with all 7 triggers that uses the specific trigger device name to do the rest of the automation? 1 automation, 7 results depending on the trigger. The problem is “parameterizing” the trigger device name so the rest of the automation would have switch.[room]_passive and light.[room]_passive.
I think something like this might work for you. If it does work, I believe it will trigger twice without the condition but I’ll leave that to you to fix.
FWIW, although it may appear to be an improved version of your suggested automation it’s a clean-sheet design.
Now that I’ve looked at your automation, I see it contains trigger.domain which isn’t available in a State Trigger (use trigger.to_state.domain). In addition, the double-quotes wrapping the two statements in the if-else will be passed literally to the entity_id (unnecessary; remove them). Although not critical, service_template was deprecated in favor of service a few versions ago.
Thanks for the input. It works like a charm.
Short, simple, efficient - love this community!
And thank you for comments on my depricated and unnecessary code-parts. I try to improve with every automation.