automation: - alias: Toggle Sonos night mode action: - service: media_player.sonos_set_option entity_id: media_player.den data_template: night_sound: >- {{ now().hour > 22 }} trigger: - platform: time at: '22:30:00' - platform: time at: '08:00:00' binary_sensor: - platform: template sensors: den_night_mode: friendly_name: Sonos Den Night Mode value_template: >- {{ state_attr('media_player.den', 'night_sound') }} script: sonos_tts: alias: "Sonos TTS" sequence: - service: media_player.sonos_snapshot data_template: entity_id: "{{ sonos_entity|default('media_player.den') }}" - service: media_player.sonos_unjoin data_template: entity_id: "{{ sonos_entity|default('media_player.den') }}" - service: media_player.volume_set data_template: entity_id: "{{ sonos_entity|default('media_player.den') }}" volume_level: "{{ volume|default(0.5) }}" - service: media_player.play_media data: entity_id: media_player.den media_content_id: https://hass.phoenixinquis.is-a-geek.org/local/chime.ogg media_content_type: music - delay: '00:00:03' - service: tts.amazon_polly_say data_template: entity_id: "{{ sonos_entity|default('media_player.den') }}" message: "{{ message }}" - delay: "{{ delay|default('00:00:00') }}" - wait_template: "{{ is_state(sonos_entity|default('media_player.den'), 'playing') }}" timeout: '00:00:05' - wait_template: "{{ not is_state(sonos_entity|default('media_player.den'), 'playing') }}" timeout: '00:02:00' - service: media_player.sonos_restore data_template: entity_id: "{{ sonos_entity|default('media_player.den') }}" group: Sonos: view: yes icon: mdi:speaker entities: - binary_sensor.den_night_mode - group.sonos_players - group.sonos_automations - group.sonos_scripts sonos_players: name: Sonos entities: - media_player.den sonos_automations: name: Automations entities: - automation.toggle_sonos_night_mode sonos_scripts: name: Scripts entities: - script.sonos_tts