Managing multiple triggers into the same automation
Emiliano Guerzoni
Project Manager | BESS Development | Driving 3+ GW of Energy Storage Projects in Italy
Welcome to a new episode of my?Tips & Tricks?newsletter?on?Home Assistant.
If you get a new e-mail about the availability of this article it's not spam! Please open it, react and comment.
It will be appreciated and will give me a much better idea of who is actually reading all this stuff.
Thank you so much!???
Automations in Home Assistant can greatly improve efficiency by taking over repetitive tasks but it's important to strike a balance.
Having too many automations can lead to a high maintenance workload and potentially asking you to put more effort to debug or modify each single automation.
One simple great way to reduce the number of automations is combining multiple triggers into a single one so that, in case any changes as well as improvements are needed, you can focus your effort to a single automation only.
Use case
You want to set the ring level of the smartphones of your family members (4) as soon as they leave home.
If you don't combine multiple triggers into the same automation you have to write and maintain 4 different automations.
Let's see how creating a single automation to cover all the family members at the same time!
领英推荐
Software configuration
Home Assistant code (yaml) / procedure
This is the code you have to write as Automation:
alias: Smartphones - Set ring stream level if away
description: Smartphones - Set ring stream level if away
trigger:
? - platform: zone
? ? entity_id: person.A
? ? zone: zone.home
? ? event: leave
? ? id: SetRingStreamLevel_A
? - platform: zone
? ? entity_id: person.B
? ? zone: zone.home
? ? event: leave
? ? id: SetRingStreamLevel_B
? - platform: zone
? ? entity_id: person.C
? ? zone: zone.home
? ? event: leave
? ? id: SetRingStreamLevel_C
? - platform: zone
? ? entity_id: person.D
? ? zone: zone.home
? ? event: leave
? ? id: SetRingStreamLevel_D
condition: null
action:
? - choose:
? ? ? - conditions:
? ? ? ? ? - condition: trigger
? ? ? ? ? ? id: SetRingStreamLevel_A
? ? ? ? sequence:
? ? ? ? ? - service: notify.mobile_app_smartphone_A
? ? ? ? ? ? message: command_volume_level
? ? ? ? ? ? data:
? ? ? ? ? ? ? media_stream: ring_stream
? ? ? ? ? ? ? command: "6"
? ? ? - conditions:
? ? ? ? ? - condition: trigger
? ? ? ? ? ? id: SetRingStreamLevel_B
? ? ? ? sequence:
? ? ? ? ? - service: notify.mobile_app_smartphone_B
? ? ? ? ? ? message: command_volume_level
? ? ? ? ? ? data:
? ? ? ? ? ? ? media_stream: ring_stream
? ? ? ? ? ? ? command: "6"
? ? ? - conditions:
? ? ? ? ? - condition: trigger
? ? ? ? ? ? id: SetRingStreamLevel_C
? ? ? ? sequence:
? ? ? ? ? - service: notify.mobile_app_smartphone_C
? ? ? ? ? ? message: command_volume_level
? ? ? ? ? ? data:
? ? ? ? ? ? ? media_stream: ring_stream
? ? ? ? ? ? ? command: "6"
? ? ? - conditions:
? ? ? ? ? - condition: trigger
? ? ? ? ? ? id: SetRingStreamLevel_D
? ? ? ? sequence:
? ? ? ? ? - service: notify.mobile_app_smartphone_D
? ? ? ? ? ? message: command_volume_level
? ? ? ? ? ? data:
? ? ? ? ? ? ? media_stream: ring_stream
? ? ? ? ? ? ? command: "6"
mode: parallel
Some specifics about the code above
Thank you for reading. ?? I hope you have enjoyed this article!
I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below.
Your feedbacks will be very appreciated!
Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read all previous episodes and still up to date on latest news.