Automation trigger volume change

This is my automation which do turn on my devices,

  • id: Aarti @ 7:30
    alias: ‘Morning Aarti Time’
    hide_entity: false
    trigger:
    platform: time
    hours: 7
    minutes: 30
    seconds: 0
    condition:
    condition: and
    conditions:
    - condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri

    action:

    • service: media_player.turn_on
      entity_id: media_player.megabox
    • service: media_player.turn_on
      entity_id: media_player.onkyorec

i want to play music in morning or let say 7 pm in evening with volume set to 25%
for this i would like to get some volume slider working so that it can be set as initial 25% volume.

please use </> when highlighting your code

Well I can’t read your code because it’s not formatted but all you need to do is add the volume set service in your action:

  action:
    - service: media_player.turn_on
      entity_id: media_player.megabox
    - service: media_player.turn_on
      entity_id: media_player.onkyorec
    - service: media_player.volume_set
      entity_id: media_player.onkyorec
      data:
        volume_level: 0.25

dear, thanks for guiding i am testing it
Dear, one more thing what about slider
if i want volume slider to work with my megabox and onkyorec,
i tried every thing but didnot get succeded.
can you please help me thanks in adv.
I would also like to get updated my slider in HA when i increase or decrease it using remote.

Dear i tried your way but my device volume doesnt get set with this settings.
Please guide me ti chage it and ake it work

I’m leaving for the weekend so i wont be able to help until monday. In that time, please post your yaml with the correct formatting. If you don’t do that, I won’t be able to help.

automations.yaml?
This does start my devices at stated time, but the sound/Volume doesnt get at targeted value

 automation:
- alias: 'Morning Aarti Time'
  hide_entity: false
  trigger:
    platform: time
    hours: 08
    minutes: 30
    seconds: 0
  condition:
    condition: and
    conditions:
      - condition: time
         weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
action:
    - service: media_player.turn_on
      entity_id: media_player.megabox
    - service: media_player.turn_on
      entity_id: media_player.onkyorec
    - delay: '01:05:05'    
    - service: media_player.volume_set
      entity_id: media_player.onkyorec
      data:
        volume_level: 35
    - service: media_player.volume_set
      entity_id: media_player.megabox
      data:
        volume_level: 5

input_number.yaml

megabox:
  name: 'Mega Volume'
  min: 0
  max: 15
  step: 1
  initial: 10
 onkyorec:
  name: 'Onkyo Volume'
  min: 0
  max: 77
  step: 1
  initial: 40

pleas use ``` or the </> button to properly format, the spacing is wrong and it makes it impossible to help.

Dear Petro,
I also go this way
i changed every entity id as per your post #6

i get error
I have this settings for all my media devices megabox & Samsung TV
i am getting this error

Invalid value: -100.0 (range 0.0 - 100.0)

- alias: Set Zone 1 Slider
  trigger:
    - platform: state
      entity_id: media_player.onkyorec
  condition:
    - condition: template
      value_template: &gt;
        {% if is_state('media_player.onkyorec','off') %}
          true
        {% else %}
          {% if is_state_attr('media_player.onkyorec', 'volume_level', states('input_number.onkyorec') | int / 100) %}
            false
          {% else %}
            true
          {% endif %}
        {% endif %}
  action:
    - service: input_number.set_value
      entity_id: input_number.onkyorec
      data_template:
        value: &gt;
          {% if trigger.to_state.state == 'on' %}
            {% set n = trigger.to_state.attributes.volume_level | float %}
            {{ (n - 1.0)*100.0 | int }}
          {% else %}
            -80
          {% endif %}
- alias: Set Zone 1 Volume
  trigger:
    - platform: state
      entity_id: input_number.onkyorec
  condition:
    - condition: template
      value_template: &gt;
        {% if is_state('media_player.onkyorec', 'on') %}
          {% if not is_state_attr('media_player.onkyorec', 'volume_level', states('input_number.onkyorec') | int / 100) %}
            true
          {% else %}
            false
          {% endif %}
        {% else %}
          false
        {% endif %}
  action:
    - service: media_player.volume_set
      entity_id: media_player.onkyorec
      data_template:
        volume_level: &gt;
          {% set n = states('input_number.onkyorec') | float %}
          {{ n / 100 + 1 }}
- alias: Set Zone 2 Slider
  trigger:
    - platform: state
      entity_id: media_player.onkyorec_zone_2
  condition:
    - condition: template
      value_template: &gt;
        {% if is_state('media_player.onkyorec_zone_2','off') %}
          true
        {% else %}
          {% if is_state_attr('media_player.onkyorec_zone_2', 'volume_level', states('input_number.onkyorec_zone_2') | int / 100) %}
            false
          {% else %}
            true
          {% endif %}
        {% endif %}
  action:
    - service: input_number.set_value
      entity_id: input_number.onkyorec_zone_2
      data_template:
        value: &gt;
          {% if trigger.to_state.state == 'on' %}
            {% set n = trigger.to_state.attributes.volume_level | float %}
            {{ (n - 1.0)*100.0 | int }}
          {% else %}
            -80
          {% endif %}
- alias: Set Zone 2 Volume
  trigger:
    - platform: state
      entity_id: input_number.onkyorec_zone_2
  condition:
    - condition: template
      value_template: &gt;
        {% if is_state('media_player.onkyorec_zone_2', 'on') %}
          {% if not is_state_attr('media_player.onkyorec_zone_2', 'volume_level', states('input_number.onkyorec_zone_2') | int / 100) %}
            true
          {% else %}
            false
          {% endif %}
        {% else %}
          false
        {% endif %}
  action:
    - service: media_player.volume_set
      entity_id: media_player.onkyorec_zone_2
      data_template:
        volume_level: &gt;
          {% set n = states('input_number.onkyorec_zone_2') | float %}
          {{ (n / 100.0) + 1.0 }}

Invalid service data for media_player.volume_set: value must be at most 1 for dictionary value @ data[‘volume_level’]. Got 35
Invalid service data for media_player.volume_set: value must be at most 1 for dictionary value @ data[‘volume_level’]. Got 5

value got 5 and 35 are my default value in automation which start my media players in morning

- alias: 'Morning Aarti Time'
  hide_entity: false
  trigger:
    platform: time
    hours: 08
    minutes: 30
    seconds: 0
  condition:
    condition: and
    conditions:
      - condition: time
         weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
action:
    - service: media_player.turn_on
      entity_id: media_player.megabox
    - service: media_player.turn_on
      entity_id: media_player.onkyorec
    - delay: '01:05:05'    
    - service: media_player.volume_set
      entity_id: media_player.onkyorec
      data:
        volume_level: 35
    - service: media_player.volume_set
      entity_id: media_player.megabox
      data:
        volume_level: 5

my input’-number yaml

onkyorec:
name: ‘Onkyo Volume’
min: 0
max: 100
step: 1
initial: 40
1 Like

@petro
Please guide
thanks in advance
Please guide

Your issue is spelled out right in front of you, and my example already shows you the solution. What do you think this error means?

With this or with any of above,
I tried my, volume doesn’t sets,
Now leaving any hope of getting it work.
So thank you for your example
thanks for your support

I’m asking you to read the error you posted.

The error is telling you that 35 is too high. The second error is telling you that 5 is too high.

Your config has those numbers in 2 spots:

So if 35 is too high because it is above the max of 1, what should you change it to?

If 5 is too high because it is above the max of 1, what should you change it to?

I already tried it by changing to .05 and .35 with input_number as min 0 max 77 and 100 with intial .35 and .05.
But it didn’t work,
I think,
I am not getting biome slider working with my settings ( I can’t change volume with above settings).
So I have to work for input numbers to work for me

a input_number has any range that you set. You need to link the 2 together if you want to use the input slider. When setting the volume_level, you need to use between 0 and 1. That’s it. Change those in your yaml and that automation will work and those errors will be removed.

The

error is because you are using my configuration which is in decibels. For some reason, my receiver’s volume goes from -100 db to 0.

You need to come up with the conversion for YOUR receiver. You can’t just use mine and think it will work.

These are the sections that needs to change.

It’s most likely going to be {{ n / 100 }} for the first and {{ n * 100 | int }} and 0 for the second.

Dear,
Thank for your guidance,
Now all errors are gone
but still i cant make my onkyo rec / megabox 's volume as stated on automated startup.
and i cant make volume change with my slider, (may be because i am using broadlink rm mini3 to control all my media devices)
can you please suggest what should i do to control volume with slider or how to use commands volume + and volume -
Please can you guide me with slider?
thanks in adv

Hello @petro , i am trying the same thing as savage87 but i don’t get how it works in order to modify the automation. I have the script for volume UP and DOWN and is working but cannot make the trigger work. i have created the template that Petro suggested but i think i am missing something

@savage87 did this whole autmatization work only with the help suggested by Petro or did you also add the sensor settings ? Can you post the whole code ?

the trigger is simple, its the state of the media player

    - platform: state
      entity_id: media_player.xxxxxxxxxxxxx

Yes @petro , i have set it. The media player name is: media_player.tv

trigger:

  • entity_id: media_player.tv
    platform: state
    condition:
  • condition: template
    value_template: >
    {% set from = trigger.from_state.attributes.volume_level | float%}
    {% set to = trigger.to_state.attributes.volume_level | float %}
    {{ to > from}}
    action:
  • service: script.radio540

But is not triggering the script when i move up the volume from the remote