Enhanced speaker reset

Hi
I’ve made some minor upgrades to Thomas blueprint
The new function gives you possibility to set different volume depending on time of day and if you want to turn off the player after reset. This with a delay of your choice. Use it with the number of media players you want, comma separated entity’s. Set parameters to all row’s and enjoy.
Do try my other blueprint that works pretty good with this!
Please try it out.
Thanks to @tcarlsen for original idea and to @Marcus_Lundblad for help in a difficult time of code. :smile:

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

Blueprint Code


blueprint:
  name: Control speakers based on time when it stops playing
  description: After speaker has been turned off its volume reset to x
  domain: automation
  input:
    media_player:
      name: Media Players
      description: Select a media player or multiple media players
      selector:
        entity:
          domain: 'media_player'
    offtime:
      name: Off time
      description: Time off before reset the volume?
      default: '00:01:00'
      selector:
        time:
    off_delay:
      name: Timer for off
      description: Timer if U want a delay to shutdown
      default: '00:00:01'
      selector:
        time:
    daytime_starts:
      name: Time of day
      description: Change level depending of time of day, start
      #default: '07:00:00'
      selector:
        time:
    daytime_ends:
      name: Time of night
      description: Change level depending of time of day, end
      #default: '20:00:00'
      selector:
        time:
    reset_volume_day:
      name: Reset volume day
      description: The volume you want your media player to be reset to
      default: '0.5'
      selector:
        number:
          min: '0'
          max: '1'
          step: '0.1'
          mode: slider
    reset_volume_night:
      name: Reset volume night
      description: The volume you want your media player to be reset to
      default: '0.1'
      selector:
        number:
          min: '0'
          max: '1'
          step: '0.1'
          mode: slider
    shut_down_trigger:
      name: Turn device off
      description: Turn device off after volyme reset
      default: false
      selector:
        boolean:
variables:
  shut_down: !input 'shut_down_trigger'
  #player: '{{ trigger.entity_id.state != "playing" }}'
trigger:
  platform: state
  entity_id: !input 'media_player'
  from: 'playing'
  for: !input 'offtime'
action:
  - choose:
      - conditions:
          - after: !input 'daytime_ends'
            before: !input 'daytime_starts'
            condition: time
        sequence:  
          - service: media_player.volume_set
            data_template:
              entity_id: '{{ trigger.entity_id }}'
              volume_level: !input 'reset_volume_night'
          - condition: template
            value_template: "{{ shut_down }}"
          - delay: !input 'off_delay'
          - condition: template
            value_template: '{{ not is_state(trigger.entity_id, "playing") }}'
          - service: media_player.turn_off
            data_template:
              entity_id: '{{ trigger.entity_id }}'
      - conditions:
          - after: !input 'daytime_starts'
            before: !input 'daytime_ends'
            condition: time
        sequence:  
          - service: media_player.volume_set
            data_template:
              entity_id: '{{ trigger.entity_id }}'
              volume_level: !input 'reset_volume_day'
          - condition: template
            value_template: "{{ shut_down }}"
          - delay: !input 'off_delay'
          - condition: template
            value_template: '{{ not is_state(trigger.entity_id, "playing") }}'
          - service: media_player.turn_off
            data_template:
              entity_id: '{{ trigger.entity_id }}'
    default:
      - service: media_player.volume_set
        data_template:
          entity_id: '{{ trigger.entity_id }}'
          volume_level: !input 'reset_volume_night'
      - condition: template
        value_template: "{{ shut_down }}"
      - delay: !input 'off_delay'
      - condition: template
        value_template: '{{ not is_state(trigger.entity_id, "playing") }}'
      - service: media_player.turn_off
        data_template:
          entity_id: '{{ trigger.entity_id }}'
mode: 'parallel'

3 Likes

:+1: :+1: :speaker: :play_or_pause_button: :mute:

This seems not to work anymore because of the recent HA updates…

I get this error (I’m using it with a google mini)

Error while executing automation automation.control_speakers_based_on_time_when_it_stops_playing: not a valid value for dictionary value @ data[‘entity_id’]

I’ll look into this as soon as I get some time to spare. :slightly_smiling_face:

/Andreas

Any progress on this?

Hi, i havent done anything since i havent been able to force this message into my logs.
How does your setup look and what message do you get?

/Andreas