HI,
somehow it seems impossible to turn_off multiple media_players at once by means of a template.
using:
{{ states.media_player|selectattr('entity_id','in',state_attr('group.radio_players','entity_id'))
|selectattr('state','eq','playing') |map(attribute='entity_id')|join(', ') }}
gives a comma separated list of currently playing media_players.
using the script:
stop_radio:
alias: Stop radio
sequence:
- service: media_player.turn_off
data_template:
entity_id:
- >
{{states('sensor.radio_players_playing')}}
does not work and errors out with:
Error executing service <ServiceCall script.stop_radio (c:058568383cb043d594eab8deccd6659b)>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1130, in _safe_execute
await self._execute_service(handler, service_call)
File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1143, in _execute_service
await handler.func(service_call)
File "/usr/local/lib/python3.6/site-packages/homeassistant/components/script.py", line 123, in service_handler
context=service.context)
File "/usr/local/lib/python3.6/site-packages/homeassistant/components/script.py", line 181, in async_turn_on
kwargs.get(ATTR_VARIABLES), context)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/script.py", line 130, in async_run
await self._handle_action(action, variables, context)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/script.py", line 172, in _handle_action
action, variables, context)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/script.py", line 261, in _async_call_service
context=context
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py", line 81, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File "/usr/local/lib/python3.6/site-packages/homeassistant/core.py", line 1101, in async_call
processed_data = handler.schema(service_data)
File "/usr/local/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 267, in __call__
return self._compiled([], data)
File "/usr/local/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 589, in validate_dict
return base_validate(path, iteritems(data), out)
File "/usr/local/lib/python3.6/site-packages/voluptuous/schema_builder.py", line 427, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: Entity ID media_player.googlehome_hall, media_player.googlehome_woonkamer is an invalid entity id for dictionary value @ data['entity_id']
while entering the same list in the dev-service:
works just fine.
other services, like volume or media_source selection work fine with multiple entity_ids…
what could be wrong, or have I stumbled on a bug…
Update
well that was easy and silly.
changed the service to:
- service: media_player.turn_off
data_template:
entity_id: >
{{states('sensor.radio_players_playing')}}
working now.