Universal media player volume is broken

Yes :

 sensor.hts_volume	0.5	friendly_name: hts_volume
  1. Media players wont show volume if the device is off. Is the device on when you try to change the volume?
  2. The volume slider does not appear in the user interface, it will only appear in the expanded media_player. To expand it, click on the media player in the interface while the device is on. A new panel will appear with your volume slider.

Thanks for the help ! Here are my answers :

  1. the media_player is on and I just checked but the volume_level is also set correctly.
  2. Here is the screen shot of the problem :

Interesting project, is it possible to share the various scripts you use to control the TV? I have an old Samsung TV and i would like to control just like you do…
If yes, thanks since now…

That’s odd. When you check the media player in the states page, does volume_level have a value associated with it? If yes, the universal control may not actually allow a slider.

I use a broadlink RM Mini for IR control and this custom component to transform it into a media_player.
If your TV is a smart TV this custom component might do the trick too.

If you are interested here is the SOAP command I use for volume (LG HTS device) :

- platform: command_line
  name: hts_volume
  command: "curl -s -H 'Content-Type:text/xml;charset=\"utf-8\"' -H 'SOAPAction:\"urn:schemas-upnp-org:service:RenderingControl:1#GetVolume\"' -X POST http://192.168.1.200:2870/control/RenderingControl --data '<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:GetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\"><InstanceID>0</InstanceID><Channel>Master</Channel></u:GetVolume></s:Body></s:Envelope>' | grep -oPm1 \"(?<=<CurrentVolume>)[^<]+\" | tail -n1"
  scan_interval: 10
  value_template: '{{ value | multiply(0.01) | round(2) }}'
1 Like

Yes it is set to the correct value now.

And I think I found what’s wrong. Here is the Yamaha support constant :

SUPPORT_YAMAHA = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
    SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY

So it must probably be SUPPORT_VOLUME_SET that makes the slider appear. However here is the code for the universal media_player :

if any([cmd in self._cmds for cmd in [SERVICE_VOLUME_UP,
                                              SERVICE_VOLUME_DOWN]]):
            flags |= SUPPORT_VOLUME_STEP
            flags &= ~SUPPORT_VOLUME_SET
elif SERVICE_VOLUME_SET in self._cmds:
            flags |= SUPPORT_VOLUME_SET

So it can’t have both the step mode and the slider as I understand it. I’m going to try to break it to see if both works but otherwise I will just remove the step part. That’s very confusing because the documentation clearly declares both in the example…

Edit : it works ! just do the following replacement in the file components/media_player/universal.py in the python install folder of HA :

flags |= SUPPORT_VOLUME_SET
#flags &= ~SUPPORT_VOLUME_SET

Thanks for the help !!!

Thanks a lot… i have much to study now…

Ah that makes sense. The step up’s and the step downs are for volume devices that “don’t know their state”.

What does the SOAP command?

Just one question: where to save the .ini files?

Wherever you wish, you only need to provide the path of it relative to the root folder of your configuration.

For the SOAP : it’s a protocol based on HTTP POST requests with an XML payload that can command some parts of most “smart” media appliances. It can set and get the volume level and the mute state if used correctly.

Dear @grea09
I am using broadlink RM mini 3 and Vasilis broadlink.py as suggested by you.
I want my media devices

  1. mini m8sii (android TV box)
  2. onkyo receiver tx-sr508
  3. Samsung TV.

I would like to get volume slider to work with this devices connected to HA via broadlink RM mini 3.
Can you please guide me.
Thanks in adv.

Well that isn’t that easy. First you’ll need to make your own ini file by following the example. You get the codes by learning them using the service switch.broadlink_learn_command_ip_of_rm_mini and pushing each button on the remote (quite tedious and long to do). Normally the Samsung ini file should work.
If your devices are compatible, I would suggest using HDMI-CEC (plug the onkyo with an HDMI cable to your TV and search the menus for Anynet+). This will allow commands issued on the TV to be replicated on your reciever (and have sound level consistant).

For the android TV box you’ll need either an app on it that can interface with a protocol supported by HA or you can try your luck meddling with UPnP and SOAP like I did by using this app.

All of that will require a ton of work to make everything seamless but I always find it worth it. Good luck !

I am having problems with turning on and off the samsung tv. I already had two switches created with broadlink mini rm3 to turning on and off the tv and i am noticing the codes are different from the ones into the samsung.ini file. Which one to use?

I have my codes with me, i have already created ini file,
but what should be done for volume,
do i need to get codes like
Volume 0 = ?
Volume 1 = ?
Volume 2 = ?
like vice
which will never be same.

i will try this today

dont know how to use this,

use codes, received by broadlink learning codes,
they are codes for your tv, so that will work better than common codes.

No, as far as I know the broadlink component doesn’t work this way. I use a Universal media player that is like a template media player. You’ll need a sensor for the volume or a way to retrieve it. That is the very hard part.

The thing is that you’ll need to do some retro engineering. If your TV is connected either try with this component (and hope everything works out of the box) or with the android App to scan the network. Once you found your TV (it’s better to set it’s IP static in the DHCP settings of your router to avoid future problems), look for the controls in it. It should be like “GetVolume”. Then invoke the service and go into the logs. There you will need to find the line of the action you just did (clear and try again if necessary). That will give you all the informations to tweak the command line sensor I posted earlier.

The last resort is to try to either guess the volume and use a variable in HA to keep track (which will stop working if anything changes the volume externally) or if you have a display of the volume to find a way to capture it and use OCR on it (using a camera and the 7 segment component of HA).

That is quite advanced endeavour but you’ll probably learn a lot doing it.

Ok, is there a way to use the sources options (HDMI, HDMI1 etc…) in a script so tu run automatically in an automation?

I get the following error:

" File “/home/homeassistant/.homeassistant/custom_components/media_player/samsungtv.py”, line 76, in setup_platform
add_devices([SamsungTVDevice(host, port, name, timeout, mac)])
File “/home/homeassistant/.homeassistant/custom_components/media_player/samsungtv.py”, line 87, in init
from wakeonlan import wol
ImportError: cannot import name ‘wol’"

How to solve?