Set day or night volume to speaker

Hi
I’ve made a blueprint to be able to set different volumes to my speakers depending if it’s day or night. It triggers on time than du choose and do not change volume of playing mediaplayers. This works good together with my other blueprint that change volume when mediaplayer goes inactive.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Try if U like :grin:

Blueprint Code

blueprint:
  name: Set volyme of speakers based of time of day
  description: Set volyme to different level on different times a day 
  domain: automation
  input:
    daytime_starts:
      name: Time of day
      description: Change level depending of time of day, Daytime level
      default: '07:00:00'
      selector:
        time:
    daytime_ends:
      name: Time of night
      description: Change level depending of time of day, Nighttime level
      default: '20:00:00'
      selector:
        time:
    volume_day:
      name: Set volume day
      description: The volume you want your media player to be reset to
      default: '0.50'
      selector:
        number:
          min: '0.00'
          max: '1.00'
          step: '0.10'
          mode: slider
    volume_night:
      name: Set volume night
      description: The volume you want your media player to be reset to
      default: '0.10'
      selector:
        number:
          min: '0.00'
          max: '1.00'
          step: '0.10'
          mode: slider
    filter:
      name: Filter players
      description: Players to be reset or not. Only
        entities are supported, devices must be expanded!
      default:
        entity_id: []
      selector:
        target:
          entity:
            domain: media_player
    include_exclude:
      name: Filter invert
      description: Turn off to reset choosen and on to choose all other
      default: true
      selector:
        boolean: {}
variables:
  filter: !input 'filter'
  player: >
    {% set result = namespace(player=[]) %}
    {% for state in states.media_player %}
      {% if include_exclude == 'true' %}
        {% if not state.state == 'playing' and not state.entity_id in filter.entity_id %}
          {% set result.player = result.player + [state.entity_id] %}
        {% endif %}
      {% else %}
        {% if not state.state == 'playing' and state.entity_id in filter.entity_id %}
          {% set result.player = result.player + [state.entity_id] %}
        {% endif %}
      {% endif %}
    {% endfor %}
    {{result.player|join(',')}}
trigger:
- platform: time
  at: !input 'daytime_starts'
- platform: time
  at: !input 'daytime_ends'
action:
  - choose:
      - conditions:
          - after: !input 'daytime_starts'
            before: !input 'daytime_ends'
            condition: time
        sequence:  
          - service: media_player.volume_set
            data_template:
              entity_id: '{{ player }}'
              volume_level: !input 'volume_day'
    default:
      - service: media_player.volume_set
        data_template:
          entity_id: '{{ player }}'
          volume_level: !input 'volume_night'
mode: 'single'

Update to add possibility to choose how to filter players, update 2 due to typo.
Another update due to a typo.

5 Likes

Hi

I’m back on this after some Corona. And find that no matter if i change the filter invert switch always get an update on the same devices. Do anyone have a clue what i’m doing wrong?

/Andreas