How to write a script that intercepts a service call?

Hi!
I am new to home assistant, so sorry in advance if it’s a stupid question, i have tried searching for it with no luck…

I would like to write a script that is triggered when a service is run, read the parameters passed to that service and use them to trigger other services.

in particular i would like to listen in to media_player volume_set and see what kind of volume is being set.
My use case is that my remote (roku_ultra) doesn’t seem to support volume_set and the tv-card i am using is not customizable and calls that volume_set regardless of configuration… i would like to catch that call and redirect it to my receiver (maybe adding some curves for the volume change)

other than my specific use case i am really curious on how to intercept services and trigger automation on that data, i really appreciate any help!

As far as I know, you can’t.
But if you explain your issue with volume then we can probably help you

1 Like

ah that sucks, i really thought that was something that we could do.

my issue with volume is that i am trying to use this card with a volume slider GitHub - usernein/tv-card: 📺 TV Remote Card (with touchpad and haptic feedback)
that slider doesn’t seem to work properly with my receiver, ranges don’t work right etc.
I have looked into the code and found this i can override

        let slider_config = {
            "type": "custom:my-slider",
            "entity": this._config.entity,
            "height": "50px",
            "mainSliderColor": "white",
            "secondarySliderColor": "rgb(60, 60, 60)",
            "mainSliderColorOff": "rgb(60, 60, 60)",
            "secondarySliderColorOff": "rgb(60, 60, 60)",
            "thumbWidth": "0px",
            "thumbHorizontalPadding": "0px",
            "radius": "25px",
        };

changing any of these fields seems to work ok, but if i try to add any other configuration like the ones found on the actual slider implementation here they don’t seem to work, maybe i am not passing it right? my-cards/docs/cards/slider-v2.md at aea9acaaef7317e851a3745356721575b66dcfaa · AnthonMS/my-cards · GitHub

(e.g. vertical, or min/max etc.)

these are the ways i have been trying to pass things (mainSliderColor works but the others do not)

      type: custom:tv-card
      entity: media_player.receiver
      slider_config:
        mainSliderColor: green
        vertical: true
        config:
          vertical: true
          min: 0
          max: 85

you could potentially use something like this:

to create a media_player.template which wraps your real media_player but then lets you override the set_volume and do whatever you want with it.

thank you i will have a look.

i actually figured out that that remote card is pointing to an older version of the slider here: my-cards/docs/cards/slider.md at aea9acaaef7317e851a3745356721575b66dcfaa · AnthonMS/my-cards · GitHub

but the configuration with min and max is still not working for me, i am investigating…

You can not catch a service call, but you can catch a change in the state the service call target, so look at the volume state instead.

by the way, that tv remote has largely been abandoned i think. you might want to take a look at @Nerwyn 's fork of it:

i use this one extensively and it’s quite good… and nerwyn’s pretty active and has added updates for things that have common value.

1 Like

thank you i will have a look at that android tv card as well!

i think my problem is that the media_player volume_set 1.0 only sets “40.0” on my receiver when the max volume is around 85, not sure how to remap that…

In that case it’s an issue with the integration to the receiver

yeah figured it out, i had to add some scripts to query the actual max volume for my onkyo and change the configuration.yaml, weirdly enough the value was 164 (on display it shows around 85db), now everything seems to work fine :slight_smile:

thank you everyone!