Closed rcarmo closed 4 years ago
I have been looking for a way to change the audio output using an API call for ages. I even contacted LG developer support but they just told me it was impossible (although that was a few years back).
@rcarmo thank you for pointing me in the right direction!
Would be awesom if this could be implemented!
Yes this is straightforward and I'll add it in the near future.
I just experimented a bit and the code below works for my LG EG920V tv to change the sound output and read it back:
import asyncio
from aiopylgtv import WebOsClient
async def runloop():
await client.connect()
await client.command('request', 'com.webos.service.apiadapter/audio/changeSoundOutput', {'output': "external_speaker"})
#"tv_speaker",
#"external_speaker",
#"external_optical",
#"external_arc",
#"lineout",
#"headphone",
#"tv_external_speaker",
#"tv_speaker_headphone",
#"bt_soundbar"
ret = await client.request('com.webos.service.apiadapter/audio/getSoundOutput')
print(ret)
await client.disconnect()
client = WebOsClient('192.168.1.???')
asyncio.get_event_loop().run_until_complete(runloop())
Maybe this can help you implement it @bendavid
If you want to call the lower level functions manually like that, you should still rather use client.request instead of client.command (request calls command underneath, but checks the response and includes all of the error handling.)
Also if someone has a 2019 model with earc support, would also be useful to know what the corresponding string is.
Explicit support for this is added by https://github.com/bendavid/aiopylgtv/commit/29110b81163414693cf8ab05fb9a1d04f2c55761 (including also state tracking)
@bendavid greath, thank you! Are you also going to make a PR to integrate this into HomeAssistant (after a version push)? Otherwise I would be willing to make one.
Yes I will take care of this together with some other changes.
For the moment most likely as an additional service in the webostv domain (ie no nice drop down box in the gui automatically)
Awesom, thanks! I presume also add a state attribute to the media_player for the sound_output.
So if you'd like to take a stab at a more general implementation in the media player api, feel free to go ahead.
(I already submitted a PR including the version bump here https://github.com/home-assistant/home-assistant/pull/31042)
I looked at the HA PR and it looks nice:) However I did not see the sound_output added as a state attribute, and also no additional service in the webos domain to switch the sound mode. @bendavid are you still going to include it in that PR, or should I start working on a PR for that?
Right that's what I'm saying, it's not included in that PR (only the bump to the latest aiopylgtv version), so you can start working on a PR for that, especially if you want to integrate it into the media_player api.
Alright, thanks for the info. Will probably start working on it tonight.
@bendavid I just made a PR to integrate it into HA: https://github.com/home-assistant/home-assistant/pull/31121
i try to use webos.select_sound_output service to select bt_soundbar. It looks like the mode is switched but BT device doesn’t connect. Is it possible to connect to BT device?
It is not possible to send a command to the TV to trigger BT device connection as far as I know.
Happy Holidays!
I've been looking for a way to control my LG TV audio output (I'm currently using this home bridge plugin, which supports it) and was wondering if you have plans to implement that.
From my cursory digging, the relevant service endpoints are: