I am trying to create a few action button widgets for my phone where with one press I can play my preferred music on a given speaker. I have this working with a simple automation where the speaker is hardcoded into the automation. I thought it’d be “trivial” to extract the speaker name into a variable to be passed from the widget so I can hard code each widget with the speaker I want it to play on.
alias: Universal Music Toggle
description: Toggles music play/stop on selected speaker
triggers:
- event_type: call_service
event_data:
domain: input_button
service: press
trigger: event
actions:
- choose:
- conditions:
- condition: template
value_template: |
{{ is_state(target_speaker, 'playing') }}
sequence:
- target:
entity_id: "{{ target_speaker }}"
action: media_player.media_stop
default:
- target:
entity_id: "{{ target_speaker }}"
data:
media_content_id: media-source://radio_browser/962cc6df-0601-11e8-ae97-52543be04c81
media_content_type: audio/mpeg
action: media_player.play_media
- target:
entity_id: "{{ target_speaker }}"
data:
volume_level: 0.1
action: media_player.volume_set
mode: single
variables:
target_speaker: |
{% if trigger.event.data.service_data is defined and
trigger.event.data.service_data.speaker is defined %}
{{ trigger.event.data.service_data.speaker }}
{% else %}
media_player.office_big_speaker
{% endif %}
I have tried numerous versions of passing the data through the widget but can’t seem to find the magic to get it to work.
Usually I get something along the lines of
extra keys not allowed @ data['service_data']
in the logs so I can’t even see what the body of the message looks like to process it.