Setting volume of media player in automations

Hi There, Im trying to set the volume of our Lenovo wall tablet to a low volume before playing a sound and then turning it back up again. If i do these actions manually from the automation, then the it plays at the correct volume, but when the automation runs it does not. Any ideas?

Please post your code as yaml using the </> button as posting pics can not be seen easily on all devices.

But at first glance there seems to be nothing wrong, check the traces to see what is happening.

1 Like

Thanks for the reply… Here is the entire automation. Basically locking and unlocking our cat door at specific times of the day. The cats didn’t understand when it was unlocked in the morning as does it silently, so we added a cat noise - after a while, now they understand that specific noise is their door unlocked :slight_smile:

Note: We have an input select helper for the cat door setting, there is another automation that actually triggers the cat door setting based on the choice of the input select - so we can have a manual choice on our kitchen dashboard.

id: '1748579200504'
alias: Cat Door
description: ''
triggers:
  - trigger: time
    at: '07:00:00'
    id: Morning
  - trigger: time
    at: '14:00:00'
    id: Afternoon
  - trigger: state
    entity_id:
      - input_boolean.good_night_mode
    from: 'off'
    to: 'on'
    id: Night
conditions:
  - type: is_connected
    condition: device
    device_id: 9e28697dc8726bd7c897c72421bb3b47
    entity_id: a3834f4f434c74f8f7cfa6dec6b21a0c
    domain: binary_sensor
  - type: is_connected
    condition: device
    device_id: 2bd1c9899ef539311219afce6b93125e
    entity_id: 26239b96df676df6665f581e10a3b141
    domain: binary_sensor
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Morning
          - condition: numeric_state
            entity_id: zone.home
            above: 0
        sequence:
          - action: input_select.select_option
            metadata: {}
            data:
              option: Unlocked
            target:
              entity_id: input_select.cat_door_setting
          - delay:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
          - action: media_player.volume_set
            metadata: {}
            data:
              volume_level: 0.1
            target:
              entity_id: media_player.lenovo_tab_m10_plus_3rd_gen
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0
          - target:
              entity_id: media_player.lenovo_tab_m10_plus_3rd_gen
            data:
              media_content_id: media-source://media_source/local/Media/Sounds/cat.mp3
              media_content_type: audio/mpeg
            action: media_player.play_media
          - action: media_player.volume_set
            metadata: {}
            data:
              volume_level: 0.8
            target:
              entity_id: media_player.lenovo_tab_m10_plus_3rd_gen
      - conditions:
          - condition: trigger
            id:
              - Afternoon
        sequence:
          - action: input_select.select_option
            metadata: {}
            data:
              option: In Only
            target:
              entity_id: input_select.cat_door_setting
          - action: media_player.volume_set
            metadata: {}
            data:
              volume_level: 0.05
            target:
              entity_id: media_player.lenovo_tab_m10_plus_3rd_gen
          - target:
              entity_id: media_player.lenovo_tab_m10_plus_3rd_gen
            data:

Looking at the race time line, it does not look like those things are actually happening… am i missing something here?

Update here - I figured out what was going on, I needed a delay in between playing the media and turning the volume back up. It was triggering media_player.play_media and then media_player.volume_set - but the delay in the tablet playing the media was obviously more than media_player.volume_set