Hi… Apologies if I have missed something obvious - I’m new to HA.
I have this automation that is designed to trigger an amp to turn on when either the Chromecasts or Android TV boxes that feed that multizone amp start playing, and then after 10 mins shut off if no device is playing.
I thought this actually worked a few days ago when I tested it, but right now, even though I use restart mode, it just goes through one cycle and shuts the amp off after 10 minutes, even though the devices are still in playing mode.
What am I doing wrong?
alias: 'Turn on Middle amp while devices active '
description: >-
Keep the Middle amp on when any of the Middle Amp's Chromecasts or Shield TV's
are active
trigger:
- platform: state
entity_id: media_player.dining_room
to: playing
- platform: state
entity_id: media_player.kitchen
to: playing
- platform: state
entity_id: media_player.guest_room
to: playing
- platform: state
entity_id: media_player.kitchen_shieldtv
to: playing
- platform: state
entity_id: media_player.guest_bedroom_shieldtv
to: playing
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.middle_amp_power
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- service: switch.turn_off
target:
entity_id: switch.middle_amp_power
mode: restart
It’s only going to trigger when one of the players starts playing. No more triggers unless one of the other players starts playing. So your delay never restarts. A better approach would be:
group:
all_media_players:
name: All Media Players
entities:
- media_player.dining_room
- media_player.kitchen
- media_player.guest_room
- media_player.kitchen_shieldtv
- media_player.kitchen_shieldtv
- media_player.guest_bedroom_shieldtv
Automations:
alias: 'Turn on Middle amp while devices active '
trigger:
- platform: state
entity_id: group.all_media_players
to: 'playing'
action:
- service: switch.turn_on
target:
entity_id: switch.middle_amp_power
alias: 'Turn off Middle amp when all devices inactive for 10 minutes'
trigger:
- platform: state
entity_id: group.all_media_players
to: 'idle'
for:
minutes: 10
- platform: state
entity_id: group.all_media_players
to: 'off'
for:
minutes: 10
action:
- service: switch.turn_off
target:
entity_id: switch.middle_amp_power
Thanks for the quick reply. I get it now - the state platform only deals with transitions, not being in the state and retriggering?
But a question about the way the group operator works. Is it an “or” or an “and”?
If it’s an or, I set how the first one triggers when any of the entities good to playing mode.
But if it’s an or, and you have 2 devices playing, and one of them transitions to idle or off, wouldn’t that turn the amp off? We would only want the amp off of all the entities in the group either off or idle, not just one of them.
Again, sorry if I am missing something about how the group operator works!
Thanks for the reply. I built this and tried it out, but it doesn’t seem to trigger. When I look at the group status in developer options when one of the chromecasts is playing, the status is on, not playing, so the trigger never happens.
I know player is in playing mode, because I can go to the device and see it’s status in player card.
Also, if the group behavior is “or” by default, why would any of triggers to turn the amp off be triggered? Because any of the other players that were in off or idle state would trigger that group operator to be off? Or is it that it’s just tracking the change of state, so it doesn’t actually matter if the ones that were off stayed off, it’s only state changes that are being considered by the trigger?
Ok use the state ‘on’ in the the trigger instead of ‘playing’ and delete the ‘idle’ trigger.
I can’t follow what you are saying but it works like this:
If all the players are off for 10 minutes the amp will switch off.
If any player starts playing the amp will switch on.
Nothing happens if one player switches off while another is playing. The group stays on, no triggers occur. Only when 10 minutes past the last player stopping playing does the off automation trigger.
In theory at least. The spanner in the works might be the players going to idle state and keeping the group on. You’ll have to test this.
Thanks again for the help. I am a bit confused. I though the group operator was an or? In my test I all the devices are off except for the one starting to play a music track, and that one was playing, not on.
Why trigger the “on” state if the state is playing?
Things are still not working properly, nothing ever gets turned off. Does this page in the documentation mean we can’t use groups for media_player types?
There seem to be other forum posts of people having issues with groups and media players.
You could be confused by the front end Lovelace display though. The only place to get the real state is in Developer tools States Menu.
Edit: actually reading that document further indicates the display (in Lovelace) for a group of media_players should be ok and problem Someone has stupidly given it the problem device class. The actual states will still be off and on.
Anyway the automations as written above wont work as the group does not change state when playing, just when the players change from on to off. Which is no use to us.
alias: 'Turn on Middle amp while any device playing '
trigger:
- platform: state
entity_id: media_player.dining_room
to: playing
- platform: state
entity_id: media_player.kitchen
to: playing
- platform: state
entity_id: media_player.guest_room
to: playing
- platform: state
entity_id: media_player.kitchen_shieldtv
to: playing
- platform: state
entity_id: media_player.guest_bedroom_shieldtv
to: playing
condition:
- condition: state # no point doing the on action if it is already on
entity_id: switch.middle_amp_power
state: 'off'
action:
- service: switch.turn_on
target:
entity_id: switch.middle_amp_power
alias: 'Turn off Middle amp when all devices inactive for 10 minutes'
trigger:
- platform: state
entity_id: media_player.dining_room
to:
- 'idle'
- 'off' # add the paused state to all the triggers too if you want.
for:
minutes: 10
- platform: state
entity_id: media_player.kitchen
to:
- 'idle'
- 'off'
for:
minutes: 10
- platform: state
entity_id: media_player.guest_room
to:
- 'idle'
- 'off'
for:
minutes: 10
- platform: state
entity_id: media_player.kitchen_shieldtv
to:
- 'idle'
- 'off'
for:
minutes: 10
- platform: state
entity_id: media_player.guest_bedroom_shieldtv
to:
- 'idle'
- 'off'
for:
minutes: 10
condition:
- condition: not # all the players have to be not playing (the 10 minutes is taken care of by the triggers)
conditions:
- condition: state
entity_id: media_player.dining_room
state: 'playing'
- condition: state
entity_id: media_player.kitchen
state: 'playing'
- condition: state
entity_id: media_player.guest_room
state: 'playing'
- condition: state
entity_id: media_player.kitchen_shieldtv
state: 'playing'
- condition: state
entity_id: media_player.guest_bedroom_shieldtv
state: 'playing'
action:
- service: switch.turn_off
target:
entity_id: switch.middle_amp_power
See why I thought groups would be easier?
You can also add the state ‘paused’ to the list of off triggers if you you want this.
One word of warning, you cant use the UI automation editor to create lists of triggers like this:
- platform: state
entity_id: media_player.kitchen
to:
- 'idle'
- 'off'
It butchers them to:
- platform: state
entity_id: media_player.kitchen
to: 'idle off'
Which is incorrect (should be to: 'idle', 'off' )
So you have to use YAML.
Thanks everyone. I was totally confused by what it meant to have “problem” as a device class. Should this be flagged as a bug? It sure would be nice if media_players could be managed as a group, but at least you all have explained it to me that I am not so confused. I can see why some people say HA is a not a good platform for beginners to use.
One other question. is it possible to give a list of entities and have it “or” them, or do I really need to do the platform, state, etc… for each source? I see examples of this all over the forums, but it’s not clear to me what works in what context.
It would take a new media group platform to deal with the multiple states (not just off/on). Like the light group has brightness and colour attributes as well as state. I just remembered that there is this:
But I’ve never used it and from a quick read it does not seem like it would be that useful for you. Maybe it would. You could have a play with it.
Everyone has to start somewhere.
You need something to list the items in. Like a group, or trigger platform. I wrote the automations out long hand to make it clear but you could do this:
alias: 'Turn on Middle amp while any device playing '
trigger:
- platform: state
entity_id:
- media_player.dining_room
- media_player.kitchen
- media_player.guest_room
- media_player.kitchen_shieldtv
- media_player.guest_bedroom_shieldtv
to: playing
condition:
- condition: state # no point doing the on action if it is already on
entity_id: switch.middle_amp_power
state: 'off'
action:
- service: switch.turn_on
target:
entity_id: switch.middle_amp_power
alias: 'Turn off Middle amp when all devices inactive for 10 minutes'
trigger:
- platform: state
- media_player.dining_room # EDIT: now I think about it I'm not sure this one is a good idea. You'd have to test it.
- media_player.kitchen
- media_player.guest_room
- media_player.kitchen_shieldtv
- media_player.guest_bedroom_shieldtv
to:
- 'idle'
- 'off'
for:
minutes: 10
condition:
- condition: not # all the players have to be not playing (the 10 minutes is taken care of by the triggers)
conditions:
- condition: state
entity_id: media_player.dining_room
state: 'playing'
- condition: state
entity_id: media_player.kitchen
state: 'playing'
- condition: state
entity_id: media_player.guest_room
state: 'playing'
- condition: state
entity_id: media_player.kitchen_shieldtv
state: 'playing'
- condition: state
entity_id: media_player.guest_bedroom_shieldtv
state: 'playing'
action:
- service: switch.turn_off
target:
entity_id: switch.middle_amp_power
The conditions must be AND logic so we cant just list them all under the one condition.