I’m trying to combine 8 automations into 1 automation and 1 script.
I can get the switch.plug5_socket_1 to turn on using the state of the entity_id but I’d like to be able to pass the trigger.to_state.state successfully and use that to set and “on” and “off” condition and then match the associated input boolean to the devices that need to be turned on… does that make sense?
Sorry, I am terrible at explaining it in writing.
So the desired scenario would be to get the automation to pass the room and the trigger.to_state.state to the script.
The script could then utilize the variables to determine the proper sequence “on” or “off” and each of those paths would have a sequence to be executed depending on the room.
In my example, I was able to use the entity_id state and if that is all I can get, I could create 4 sequences (1 for each room) to turn them on and then create 4 more one to turn them each off.
so for each room, I have an automation nearly identical to this:
the differences are the media_player.zones
but turning on the switch.plug1_socket_1 could be an action that occurs one time if the pwrstate = ‘on’
your suggestion did work.
I made some progress and am able to have the two pwrstate sequences.
any additional recommendations to make the script more efficient?
It’s definitely possible, but you need to share with us how you expect to link the input booleans in the automation to the media players and switches/lights in the script.
Do your entity IDs follow a strict naming convention? Or will you need to set up a mapping?
For example, if the pattern is switch.plugX_socket_1 always goes with media_player.zone_X, you can use a couple variables to take the value of room from the earlier automation:
Though, I suggest not using the delay at the end. Set up a second automation to handle that. Delays do not survive reload or restart, so it’s best to avoid them for anything longer than a few minutes.
okay, so with your help I have a start on what I am wanting to do.
There is a “on” sequence" and and “off” sequence and each one was going to have a separate sequence for each room before I saw your room mapping example…
unfortunately, I did not use a strict naming convention so I will have more work.
your example is amazing, though. It clears some things up.
and the plug powers on an old airplay apple router I had lying around. if I left it on all the time it became unreliable so I put a plug on it and automate turning it on anytime I wanna play music in the house so that is why it gets turned on one time in the script above.
The mapping in your example is fantastic. I think that is the key for me.
Be aware, if you are keeping the delay at the end, you must change the mode to parallel, or the script will not be fit for purpose because it will be locked out from activating another room while it waits for 3.5 hours first the first run to finish.
yeah, the delay was to ensure the amp wasn’t left on for days, I will remove that and set something to check if left on and turn off at night. thanks for the information…
I am terrible at yaml and not sure where in the script the variables go. have bene fumbling with it and no luck.