i have the following automations and they work great, but i would like to combine theme in to one. im trying to do that with as many automations as i can using templates. but i get stuck on these regarding the state change. and multi entity_id in the actions any tips?
- id: '1517011965533'
alias: AppleTV Vardagsrum Play
trigger:
- entity_id: media_player.apple_tv_vardagsrum
from: idle
platform: state
to: playing
condition: []
action:
- data:
entity_id: script.1545874111999
service: script.turn_on
- id: '1517012054613'
alias: AppleTV Vardagsrum Pause
trigger:
- entity_id: media_player.apple_tv_vardagsrum
from: playing
platform: state
to: paused
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- data:
brightness_pct: 50
entity_id: light.golvlampa_2
service: light.turn_on
- data:
brightness_pct: 50
entity_id: light.golvlampan_2
service: light.turn_on
- id: '1517012153064'
alias: AppleTV Vardagsrum play pause
trigger:
- entity_id: media_player.apple_tv_vardagsrum
from: paused
platform: state
to: playing
condition: []
action:
- data:
entity_id: script.1545874111999
service: script.turn_on
- id: '1517012229016'
alias: AppleTV Vardagsrum Stop
trigger:
- entity_id: media_player.apple_tv_vardagsrum
from: playing
platform: state
to: idle
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
action:
- data:
entity_id: script.9998820176999
service: script.turn_on
Without going into the details yet, I’ll offer that it’s often clearer and easier to have separate automations than to try to combine them with fancy and hard-to-read constructs. When you have different triggers, different conditions, and different actions for each automation, trying to combine them is likely more trouble than it’s worth. I’ve been there.
May I also ask why ?
It can’t be for space as I recently checked my configuration.yaml file, 532 bytes, but due to file allocation it consumes 1MB
And As Rob points out, scanning through a file when you have a vague search term will yield easier, quicker results than studying each template you come accross.
Put them all in the same package, order them alphabetically, or by device, or by room, close the package and you probably won’t return to it. So no great loss.
These also look like they were written by the automation manager (random id:'s and frequent [ ] are a dead givaway) you could compact these quite a lot, whilst making them more readable but I’m not sure what your theme is. light / media_player or what you want to do are they generally triggered by the sun going down ? Can’t see what this script 11999 does either.
Maybe we can help with making them more readable and combining actions that occur at the same time.
I am making an assumption here that your automations are all stored in automation.yaml. Have you considered splitting up your configuration (to make management easier) I would recommend packages but not everyone agrees, read up see what you think and ask questions when you get stuck.
Mutt
Ah ! that’s the key issue.
Most people consider the automation editor to be a work in progress.
It can’t understand comments, so doesn’t know where to place them and to keep it clean, just removes them.
It also doesn’t know much about templates so I’m sure in most cases it treats them less than kindly.
If anyone gives you code (automation/script) they will get similar treatment.
So when people get to the stage where they are considering splitting up their yaml (it’s all yaml still, what you have know is yaml too) then they have to make the decision to abandon the automation manager. You can then go with your favourite editor (notpad++ is common on windows, atom on mac etc.) . Or if you like the idea of having an integrated one (i.e. on the same host - you could load ‘configurator’ (it’s an addon) not used it much myself but it seems to do the job.
Doing this is a big step and you will need time to consider what you want. But moving on opens up many possibilities. You get to work directly with code so your understanding will improve. you get to copy peoples code and put it where you want it to go. You could even take a full package (a media_player control or outside lights or colour management for RGB lights or … you get the idea).
You do need to travel at a pace that you feel comfortable with and during the transition there will be a few hiccups.
I think that I will abandon the automation editor and split it up for better order in my automations, I’m doing most of the things in the yaml files anyway.
Thanks for the automation example, I also see that it’s not worth it. But if you don’t know you have to ask😊