Media Player Volume Automation Increase/Decrease by X

I looked and looked, and I couldn’t find anything that seemed like something I could piggyback on and utilize. If I missed something, drop the link, and I’ll dive right in.

I’m trying to create an automation to turn up a Media Player (specifically: Chromecast)'s volume by 30 when a switch is turned on (a loud window air conditioner that I have a Generic Thermostat driving its on/off state). And the inverse: down by 30 when it’s turned off. I need to emphasize that I need the volume to change (increase or decrease) by 30, not set to a specific level.

Thanks again, friends and fellow scholars. Any assistance will be thoroughly appreciated.

In case needed or can helpful:

  • Air Conditioner switch entity: switch.meross_plug_e_mss110_main_channel
  • Media Player entity: media_player.android_tv_bedroom

Hi @smibrandon, I can’t help you by writing an automation out of the top of my head but maybe this can get you there.

The condition of your automation can be the state of that switch, no?
The action will call a media_player.volume_set in which you can set 0,3 (30%).

HTH

EDIT: oops, increase/decrease… that will need more coding.
Just try this already, post your YAML code and someone else will surely help you.
Needless to say that you need 2 automations; one to increase, the other to decrease.

You can try copying this YAML code-

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: switch.meross_plug_e_mss110_main_channel
    to: 'on'
    from: 'off'
    id: Plug On
  - platform: state
    entity_id: switch.meross_plug_e_mss110_main_channel
    id: Plug Off
    from: 'on'
    to: 'off'
condition:
  - condition: state
    entity_id: media_player.android_tv_bedroom
    state: 'on'
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Plug On
        sequence:
          - service: media_player.volume_set
            target:
              entity_id: media_player.android_tv_bedroom
            data:
              volume_level: >-
                {{ state_attr('media_player.android_tv_bedroom', 'volume_level') + 0.25 }}
      - conditions:
          - condition: trigger
            id: Plug Off
        sequence:
          - service: media_player.volume_set
            target:
              entity_id: media_player.android_tv_bedroom
            data:
              volume_level: >-
                {{ state_attr('media_player.android_tv_bedroom', 'volume_level') - 0.25 }}
    default: []

Note: The YAML code above works if you have HA version 2021.7 and above - using the trigger condition and trigger ID features.