I setup a automation for each keyboard and each of the 6 options (that part can probably be reduced to less code), if the input is in the range of 3-6, the script starts Sonos with the appropriate playlist, then sets the Monoprice input back to 2, where the Sonos is connected.
If input 1 is selected, or turned on, it leaves it at that (Denon Zone 2), if the input is 2, then is starts Sonos (previously selected playlist).
I only have one Sonos, thus the last requested playlist plays. I only turns on the speaker(s) for the respective keyboard. This is from configuration.yaml:
- platform: monoprice
port: /dev/ttyS0
zones:
11:
name: Kitchen Speakers
12:
name: Deck Speakers
13:
name: Bedroom Speakers
14:
name: Bathroom Speakers
15:
name: Library Speakers
16:
name: Spare Speakers
sources:
1:
name: House Audio
2:
name: Sonos
3:
name: Sonos Piano
4:
name: Sonos Chill
5:
name: Sonos Lounge
6:
name: Sonos Energetic
This is one of the automations:
- id: '1553157703280'
initial_state: true
alias: Monoprice play Kitchen Sonos Piano
trigger:
platform: template
value_template: "{{ is_state_attr('media_player.kitchen_speakers', 'source', 'Sonos Piano') }}"
action:
- service: script.do_monoprice_play
data_template:
entity: media_player.kitchen_speakers
source: 'Piano'
This is the script:
> do_monoprice_play: # entity and source variables
> sequence:
> - service: media_player.select_source
> data_template:
> source: "{{ source }}"
> entity_id: media_player.house_sonos
> - service: media_player.select_source
> data_template:
> source: 'Sonos'
> entity_id: "{{ entity }}"