I am trying to configure multiple Aqara Cube actions via a single script. It should be possible to increase the volume, decrease the volume, or reset the volume to a fixed value.
Currently this works like this:
Automation:
[...]
action:
- service: script.play_music
data_template:
entity_id: media_player.google_nest_hub
command: |
{% if (trigger.event.data.command == 'rotate_right') %}
volume_up
{% elif (trigger.event.data.command == 'rotate_left') %}
volume_down
{% else %}
volume_set
{% endif %}
volume_level: 0.4
Script:
choose:
- conditions:
- condition: template
value_template: '{{ command == "volume_up" }}'
sequence:
- service: media_player.volume_up
data_template:
entity_id: '{{ entity_id }}'
- conditions:
- condition: template
value_template: '{{ command == "volume_down" }}'
sequence:
- service: media_player.volume_down
data_template:
entity_id: '{{ entity_id }}'
default:
- service: media_player.volume_set
data_template:
volume_level: '{{ volume_level }}'
entity_id: '{{ entity_id }}'
I would like to simplify this by putting all options into a single condition. However, this fails because media_player.volume_set
needs the volume_level
parameter, but media_player.volume_up
won’t accept it:
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['volume_level']
Is there a way to skip adding the volume_level
using a condition?