I have two scripts that I use to join or unjoin two Sonos-speakers. Both scripts work fine, but I want to toggle between the two.
I have set up a binary sensor that is connected to a GPIO header. So… when I press the physical switch, I want to toggle between grouped/ungrouped speakers.
Sorry about the messy code-formatting, but I can’t seem to fix it. Indention in all my code is valid YAML and works fine when edited in Visual Studio Code.
I ended up using this automation:
- alias: Sonos Group/Ungroup
trigger:
platform: state
entity_id: binary_sensor.sonos_toggle_rooms
from: "off"
to: "on"
action:
- service_template: "{% if is_state_attr('media_player.kkken','is_coordinator', false) %} script.sonos_ungroup_players {% else %} script.sonos_group_players {% endif %}"