Turn down volume when rising - I NEED HELP

Hi guys, I’ve been trying to set it for hours that when the input boolean is turned on the TV lowers the volume to 15% and if you try to raise the volume it puts it back to 15% until the input boolean turned off

alias: volume test 1
description: ''
trigger:
  - platform: numeric_state
    entity_id: media_player.sony_bravia_tv
    above: '16'
    attribute: volume_level
  - platform: state
    entity_id: input_boolean.buonanotte
    to: 'on'
condition:
  - condition: state
    entity_id: input_boolean.buonanotte
    state: 'on'
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.tv_salotto
  - repeat:
      while:
        - condition: numeric_state
          entity_id: media_player.tv_salotto
          above: '16'
          attribute: volume_level
      sequence: []
mode: single

What did I do wrong?

I would do it this way. It would trigger on each and every volume change so there is no opportunity to ever miss a threshold being crossed. Pro = resiliency. Con = increased log traffic.

alias: volume test 1
description: ''
trigger:
  - platform: state
    entity_id: media_player.sony_bravia_tv
    attribute: volume_level
condition:
  - condition: state
    entity_id: input_boolean.buonanotte
    state: 'on'
  - platform: numeric_state
    entity_id: media_player.sony_bravia_tv
    above: '16'
    attribute: volume_level
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.tv_salotto
mode: single

I do have a question about this because I just went through a, “the TV is too loud but a volume number means nothing” project. If that is the same use-case, there are other approaches that don’t use a fixed volume number that may be worth discussing. But off topic.

Hi, I copied and pasted but it doesn’t work, why?
However I did not understand your question, I do not understand English well

I dunno, you don’t give us enough information. After all, I copied and pasted too!

Best to start here…

Simply when the input boolean is active as the first thing the automation sets the TV volume to 15% and if someone tries to raise it is automatically put to 15 until I turn off the input boolean.
Are they good as information? :sweat_smile:

In the trigger and condition volume level stated 16, shouldn’t that be above: ‘0.16’

I think @huu is correct.
And I would remove the while thing at the end as it’s not needed. It will just block the automation from triggering again.

alias: volume test 1
description: ''
trigger:
  - platform: numeric_state
    entity_id: media_player.sony_bravia_tv
    above: '0.16'
    attribute: volume_level
  - platform: state
    entity_id: input_boolean.buonanotte
    to: 'on'
condition:
  - condition: state
    entity_id: input_boolean.buonanotte
    state: 'on'
action:
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.tv_salotto
mode: single

What @crlogic posted should also work with 0.16 but it won’t trigger on boolean on.
If the volume is 0.4 when the boolean goes on then nothing happens until the volume has been changed.

Great, the only problem is that if I try to turn up the volume it doesn’t automatically turn down :frowning:

I don’t know what your entities are named but I do notice that you are triggering on one media_player and doing the action on a different media_player.
Is that correct?

I have many media players with a similar name, in fact that is a mistake, the right one is

media_player.sony_bravia_tv

however even with this last one I was not able to get the result I want to get.
But none of you have a smart TV to experience this thing?

So it would work, the only problem is that if I turn down the volume it always goes back to 15 … solutions?

alias: volume test 1
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.buonanotte
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: input_boolean.buonanotte
    state: 'on'
action:
  - repeat:
      while:
        - condition: state
          entity_id: input_boolean.buonanotte
          state: 'on'
      sequence:
        - service: media_player.volume_set
          data:
            volume_level: 0.15
          target:
            entity_id:
              - media_player.sony_bravia_tv
        - delay:
            hours: 0
            minutes: 0
            seconds: 1
            milliseconds: 0
mode: single

If this sets a new volume then the code I posted (with corrected media player) should also work.
If that doesn’t work then you need to post the automation trace so that we can see what is the issue.

I don’t think the automation you posted last is something you should use.

Given that this automation is causing you so much trouble, I must ask, why do you even want to do this?

In you last post, You change your trigger to be the change in input boolean and not change in volume (the trigger and the condition are the same? which i found a bit odd)