bendavid / aiopylgtv Goto Github PK
View Code? Open in Web Editor NEWThis project forked from thereallink/pylgtv
Library to control webOS based LG Tv devices
License: MIT License
This project forked from thereallink/pylgtv
Library to control webOS based LG Tv devices
License: MIT License
Hi Josh!
Thanks for adding these new methods!
set_current_picture_mode()
works fine here: aiopylgtvcommand 192.168.1.78 set_current_picture_mode expert2
But not set_picture_mode()
: aiopylgtvcommand 192.168.1.78 set_picture_mode expert2 hdmi2_pc
Basically, I try to switch to the same preset but into PC mode from non-PC mode. Does it work for you?
Thanks
TV: LG B8, fw 4.10.25, webos 4.1.0-5511
Firing multiple volume_up
/volume_down
when sound_output
is "external_arc"
will result in only the first one (or at least only one of them) being processed.
I don't know if it's webostv causing this or the external speaker, but I have at least encountered the same issue on 2 different speakers.
Hello,
I am using this integration in home assistant. I would like for the automation to trigger based on the Power state change.
Manually calling the endpoint "com.webos.service.tvpower/power/getPowerState" works. I see a debug log in the event log whose payload tells me the power state.
Example.
2022-05-22 18:57:23 DEBUG (MainThread) [aiowebostv] recv(192.168.5.131): {"type":"response","id":51,"payload":{"returnValue":true,"state":"Screen Saver"}}
Home assistant call_service API does not provide a return value so I can't get this output anywhere in home assistant except the debug logs.
I see in the code that we are subscribed to the power state changes and I also do see a log in the debug logs when TV power state changes. Example Active -> Screen Saver
Is there a way to call the getPowerState endpoint and read the data coming back from the TV?
Regards,
Vaibhav
I noticed this in Home Assistant.
There should be an additional check, that the code doesn't execute if the TV is off.
This might be a strange request, but I'm trying to figure out a way to wake the screen every time I send the MEDIA_PLAY command is sent. The problem comes from how the screensaver gets interrupted the first time I try to resume playback and I have to tell it to resume a second time for the desired action. I'm not very good with Python, but I was trying to create something along these lines:
I thought maybe I could modify this to, instead of urls, send first TURN_ON_SCREEN, followed by MEDIA_PLAY with a sleep in between. Any help or advice would be appreciated.
Hello,
I am having problems using the system/turnOn command for my LG TV. TurnOff works fine. I'm running this from services in developer tools:
service: webostv.command
data:
entity_id: media_player.living_room_tv
command: system/turnOn
I need the turnOn function because the CEC functions don't seem to work with my Series X. Thanks!
Hello, could you create a plugin for Domoticz? I would like to use it to control my LG TV.
Domoticz-LGTV-WebOS-Plugin does not work correctly on the new LGC9.
Thank you.
Hi Josh, is therr a similiar way like this to do this?
Btw, where did you find those hidden options? Do you have a doc/link about them?
Thanks
Whilst running homeassistant I noticed this bug:
Mar 02 12:56:47 hass hass[26367]: File "xx/hass/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 373, in consumer_handler
Mar 02 12:56:47 hass hass[26367]: while not closeout_task.done():
Mar 02 12:56:47 hass hass[26367]: UnboundLocalError: local variable 'closeout_task' referenced before assignment
I have been using Home Assistant with the WebOS integration for awhile and it has been working well. Recently I changed how my TVs are connected to my home network and it has caused some unexpected behavior with the integration. First some background:
My TVs have builtin Google Cast capability. However, we never cast directly to the TVs so their appearance in the cast options is confusing. In an effort to have the TVs no longer appear in the list of devices to cast to I put them in their own subnet to isolate in their own broadcast domain. Since the TVs are now in a different broadcast domain than client devices, the TVs no longer show up as castable. There are no firewall rules between my Home Assistant instance (on LAN1 below) and this new subnet (LAN2 below):
┌────┐ ┌──────┐ ┌────┐
│LAN1◄──┤Router├──►LAN2│
└──┬─┘ └──────┘ └──┬─┘
│ │
│ │
┌──▼──┐ ┌─▼──┐
│ HAS │ │ TV │
└─────┘ └────┘
Now to my problem:
When the TV is turned off, either via the TV itself/remote or by calling the service from Home Assistant the underlying TCP connection that aiopylgtv opens is never closed. When the TV turns off, it never sends a FIN packet and so the TCP session is in a hung state that will never close without action. Since aiopylgtv thinks there is an active TCP connection, there is never an attempt to reconnect when the TV is turned on again by the remote control. Therefore, if the TV is operated independently from Home Assistant, Home Assistant does not reflect the correct state.
I have a hypothesis why everything works fine on the same network: The TCP session does in fact get hung always, however when on the same subnet the ARP entry will expire relatively quickly. When the ARP entry expires, the operating system automatically closes the TCP session. The next time Home Assistant polls, there is no active TCP session so one is attempted. This repeats until the TV is turned on and a new TCP session is established.
When I moved my TVs into a new subnet, ARP was no longer in play and so the operating system shows the TCP session as open (as it should since no FIN packets are sent). This problem is arguably an LG problem, since the TV should close any TCP sessions that can't ever be used again. However, I've found that if all I do is call disconnect() when the power state changes to suspend, this cleans up the underlying TCP session and everything works again as expected (see the commit following this note).
I don't know if my solution is correct, or if I'm perhaps completely missing something, but I'd love any feedback you have on my circumstances.
Good evening,
any hints on how to change the channel list between the 3 different types?
Thanks in advance
Hi. A quick question: I checked the endpoints and it seems there's no way to change the AV Sync Adjustment. Do you confirm?
How do I get the current picture mode? I can see a method to set current picture mode but could not find anything that returns the current mode already set. Am I missing something?
Also, how to get the list of picture mode that are available on the connected tv as all picture modes are not available on all models. Is that possible?
Hi.
I've wiresharked some new endpoint that can be usefull
It looks like:
com.webos.service.ime/insertText
payload have attributes text (string) and replace (boolean)
We can fill any text forms with that.
And it's faster than pressing every button on screen keyboard
Hello, and first of all thanks for this library! I was trying to get my LG TVs work with Home Assistant and I discovered it uses this library. Trying the basic example it works out of the box with my newer LG TV with WebOS3 but to make it work with the other TV with WebOS2 I have to comment out https://github.com/bendavid/aiopylgtv/blob/master/aiopylgtv/webos_client.py#L233 otherwise I always get
Traceback (most recent call last):
File "/home/vide/tmp/lg.py", line 14, in <module>
asyncio.get_event_loop().run_until_complete(runloop(client))
File "/usr/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
return future.result()
File "/home/vide/tmp/lg.py", line 7, in runloop
await client.connect()
File "/home/vide/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 137, in connect
return await self.connect_result
File "/home/vide/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 239, in connect_handler
self.subscribe_sound_output(self.set_sound_output_state),
File "/home/vide/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 694, in subscribe_power_state
return await self.subscribe(callback, ep.GET_POWER_STATE)
File "/home/vide/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 631, in subscribe
uri, payload=payload, cmd_type="subscribe", uid=uid
File "/home/vide/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 618, in request
raise PyLGTVCmdException(f"Invalid request response {response}")
aiopylgtv.webos_client.PyLGTVCmdException: Invalid request response {'type': 'error', 'id': 3, 'error': '404 no such service or method', 'payload': {}}
btw Home Assistant doesn't work with WebOS3 either but that's another topic :)
This exception happens when the TV is turned off, might be related that I have disabled the Quick Start+
feature,
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 340, in ping_handler
ping_waiter = await ws.ping()
File "/usr/local/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 657, in ping
await self.ensure_open()
File "/usr/local/lib/python3.9/site-packages/websockets/legacy/protocol.py", line 735, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: code = 1001 (going away), reason = server shutting down
The exception needs to be caught here:
aiopylgtv/aiopylgtv/webos_client.py
Lines 356 to 359 in 6b676ea
I updated my TV firmware and now it is rejecting non-SSL WS connection. The API still works with WSS with SSL. However, aiopylgtv doesn't currently support that.
To support SSL we need the following changes:
3001
(from 3000
)wss://
instead of ws://
As a proof of concept, I got it working by changing the following code:
WebOsClient.connect_handler
:
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
...
websockets.connect(
f"wss://{self.ip}:3001",
ping_interval=None,
close_timeout=self.timeout_connect,
max_size=None,
ssl=ssl_context,
)
...
websockets.connect(
inputsockpath,
ping_interval=None,
close_timeout=self.timeout_connect,
ssl=ssl_context,
)
Is there any documentation, which key exist for the different endpoints?
I just found the reference for the WebOS Luna Service API, but just some payload key worked for me. Most of them not.
Hi,
I have spotify installer on my LG and can turn it on and play with your SDK. However when carlingue tue command fastForward it jumps of 10s forward but I don't find how to go to the next track. Is there a command for that?
Thanks!
Doing this changes some settings, what I noticed at least, color gamut to wide and color temperature to warm 50:
await client.start_calibration(picMode="game")
await client.end_calibration(picMode="game")
I want to only change oled light without changing anything else like this:
await client.start_calibration(picMode="game")
await client.set_oled_light(value=backlight)
await client.end_calibration(picMode="game")
I could not figure out how to set color gamut and temperature back to my desired values either.
Sidenote: color gamut "wide" is not selectable in the lg menu for game mode (atleast for pc).
Hi Josh! Just an interesting new method, maybe it works for you as well.
import asyncio
from aiopylgtv import WebOsClient
async def runloop():
client = await WebOsClient.create('192.168.1.18')
await client.connect()
settings = {"mode": "user", "flagUpdate": True}
await client.launch_app_with_params("com.webos.app.softwareupdate", settings)
await client.disconnect()
asyncio.run(runloop())
Hi,
I'm a total Python dummy. Can you please help me on how I can retrieve the current picture settings. I wasn't successful with these attempts:
import asyncio`
from aiopylgtv import WebOsClient
async def runloop():
client = await WebOsClient.create('192.168.0.60')
await client.disconnect()
await client.connect()
await client.start_calibration(picMode="game")
print(client.set_oled_light)
#print(client.get_picture_settings("backlight"))
await client.disconnect()
asyncio.run(runloop())
Thanks!!
Helge
Hello,
The magic remote of my LG TV includes this STB button.
Will it be possible to "press" that button from this library?
What would be needed to include that button?
I would like Home Assistant to be able to turn on/off my settopbox.
Thank you
I use webos integration in Home Assistant. There is the latest version of Home Assistant 2021.10.4
This code does not run on a TV with webOS 4.5. I have two TVs, one LG 43UK6750 with webOS 4, and the second LG 32LM6350 with webOS 4.5. If I run this code for the LG 43UK6750 TV, then everything works, and if I run the code for the LG 32LM6350 TV, then it doesn't work there.
service: webostv.command
data:
command: system.launcher/launch
entity_id: media_player.tv_lg_na_kukhne
payload:
id: youtube.leanback.v4
contentId: DKM9d5CZUxk
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:
ssap://com.webos.service.apiadapter/audio/changeSoundOutput
ssap://com.webos.service.apiadapter/audio/getSoundOutput
Most of the features in this library don't need the numpy
library and it's an awefully heavy dependency to install on a lighter system.
I absolutely love numpy but it's a really heavy lib to build and install :P
I have 2 LG TVs, this integration works great with my older 49uj6565
which runs webOSTV 3.5
. When I call get_volume
the payload is:
{'returnValue': True, 'volumeMax': 100, 'muted': False, 'scenario': 'mastervolume_tv_speaker', 'subscribed': True, 'volume': 9, 'action': 'requested', 'active': False}
But on my LG CX running webOSTV 5.0
I get a different payload:
{'volumeStatus': {'activeStatus': True, 'adjustVolume': True, 'maxVolume': 100, 'muteStatus': False, 'volume': 9, 'mode': 'normal', 'soundOutput': 'tv_speaker'}, 'returnValue': True, 'callerId': 'secondscreen.client'}
so payload.get("volume")
fails, since there's a new volumeStatus
object.
I'll open a PR with the fix shortly
Hi!
First of all, thanks for your work!
Let me know if you need any help with B8 (Alpha7 2nd gen chipset, 17 points cube).
Hi
is there a way to send letters or numbers as if a keyboard on search screens?
I couldn't find any endpoint for this
I was trying to integrate the new picture_settings and ability to set brightness, contrast, etc in home assistant and this is what I observed.
Initially picture_settings contains all four brightness, contrast, backlight and color properties. But once I called set_current_picture_settings with a dict containing only backlight, the picture_settings now only contains the backlight property.
Is this expected? How to ensure that all the properties are correctly reported even after setting one of the properties optionally?
Hello,
We can use changeSoundOutput
to change the audio to bt_soundbar
. However, this does nothing as webos will no try to connect to any known device.
Is there a way to connect to a bluetooth device by name ?
Thank you
Apologies if this is the wrong place to ask this but I'd like to set the picture mode via homeassistant automations. I don't need to adjust picture settings necessarily just change between modes that are already configured. Any guidance would be appreciated.
I can change the soundoutput to bluetooth via command but only if the device is already connected. if not, the command doesnt work.
how can i connect to the bluetooth device via command?
or is there any other way to automatically connect to the last connected bluetooth device? my tv asks me at every start. but i'd like to automate this annoying behavior
LG UJ620V. Any command ends in error even after successful pairing. It is worth mentioning that I am running aiopylgtvcommand
from WSL with Debian. If the TV were completely turned off, a TimeoutError
appears, so it's not a connection issue.
$ aiopylgtvcommand 192.168.1.41 volume_down
Traceback (most recent call last):
File "/home/surpaul/.local/bin/aiopylgtvcommand", line 10, in <module>
sys.exit(aiopylgtvcommand())
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/utils.py", line 49, in aiopylgtvcommand
asyncio.run(runloop(args))
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/utils.py", line 9, in runloop
await client.connect()
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 163, in connect
return await self.connect_result
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 283, in connect_handler
task.result()
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 1641, in subscribe_picture_settings
return await self.subscribe(settings, ep.GET_SYSTEM_SETTINGS, payload=payload)
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 726, in subscribe
uri, payload=payload, cmd_type="subscribe", uid=uid
File "/home/surpaul/.local/lib/python3.7/site-packages/aiopylgtv/webos_client.py", line 711, in request
raise PyLGTVCmdError(response)
aiopylgtv.webos_client.PyLGTVCmdError: {'type': 'error', 'id': 6, 'error': '500 Application error', 'payload': {'returnValue': False, 'errorCode': -1000, 'errorText': "category, picture doesn't support the key(s): contrast,backlight,brightness,color"}}
I've been trying to use the latest version of aiopylgtv, but am having issues with it and my C6 OLED. Regardless of what command is attempted the following error is thrown:
Traceback (most recent call last):
File "/config/python/test.py", line 13, in <module>
asyncio.get_event_loop().run_until_complete(runloop())
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/config/python/test.py", line 6, in runloop
await client.connect()
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 163, in connect
return await self.connect_result
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 283, in connect_handler
task.result()
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 1641, in subscribe_picture_settings
return await self.subscribe(settings, ep.GET_SYSTEM_SETTINGS, payload=payload)
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 725, in subscribe
return await self.request(
File "/usr/local/lib/python3.9/site-packages/aiopylgtv/webos_client.py", line 711, in request
raise PyLGTVCmdError(response)
aiopylgtv.webos_client.PyLGTVCmdError: {'type': 'error', 'id': 5, 'error': '500 Application error', 'payload': {'returnValue': False, 'errorCode': -1000, 'errorText': "category, picture doesn't support the key(s): contrast,backlight,brightness,color"}}
I've tested it using the basic example script included in the readme.md, i.e:
import asyncio
from aiopylgtv import WebOsClient
async def runloop():
client = await WebOsClient.create('192.168.1.53')
await client.connect()
apps = await client.get_apps()
for app in apps:
print(app)
await client.disconnect()
asyncio.get_event_loop().run_until_complete(runloop())
This completes successfully with version 0.4.0, but throws the above error when using 0.4.1.
I'd like to use the calibration function with a 2021 QNED model, more specifically a 65" QNED919PA, to upload LUTs generated with DisplayCal. Due to the risk of bricking the mainboard, I wanted to ask if there are any known compatibility issues or if someone already has successfully done it.
The QNED919PA supports auto-calibration (CalMan) with LUT access
and uses an Alpha7 Gen4 Processor 4K
according to the data sheet).
Here is the output of some of the info methods:
system_info: {'returnValue': True, 'features': {'dvr': False}, 'receiverType': 'DVB', 'modelName': '65QNED919PA', 'serialNumber': '<redacted>', 'programMode': True}
software_info: {'returnValue': True, 'product_name': 'webOSTV 6.0', 'model_name': 'HE_DTV_W21U_AFADATAA', 'sw_type': 'FIRMWARE', 'major_ver': '03', 'minor_ver': '30.10', 'country': '<redacted>', 'country_group': '<redacted>', 'device_id': '<redacted>', 'auth_flag': 'N', 'ignore_disable': 'N', 'eco_info': '01', 'config_key': '00', 'language_code': '<redacted>'}
It seems that the calibration_support_info
method needs to be updated for QNED models.
Apart from the general question of compatibility, I also have some questions concerning the calibration itself:
Does it make sense to set color temperature and saturation as well as gamma in calibration mode before performing the calibration to bring the basic picture closer to the intended target or are they redundant since LUTs also affect them?
What about the local dimming feature? Should I turn it off in calibration mode or does the calibration mode set it in some way?
Hi,
Would it be possible to retrieve the details of what is being played on Netflix? Like Series Title, Season Number, Episode Number, ecc?
That would be great to scrobble that info to services like trakt.
Thanks!
Tell me, how can I use webos integration to launch youtube on a TV with channel search? I have described in more detail here
There is no way AFAIK to get the current state of the TV. Is it playing or paused.
This is very useful for automations. Also when my oled tv is in screensaver mode on a puased video, I have to call PLAY up to 3 times to get it to resume the video, but there is no way to know if any of the calls actually worked or just woke up the TV.
Is this doable?
P.S. knowing if the screensaver is on would be great too.
@bendavid I just tested the code of your latest open PR: home-assistant/core#31099
I noticed that the turn_off service does not work anymore using the code of that PR.
I have an 'older' webos2 TV: LG EG920V
Could you maybe have a look at it?
How would I switch to Teletext / Text mode of the LG WebOS TV set? There is a "TEXT" button on the remote, but I could not find a way to do it programmatically.
hi. i dont know how to launch an specific app via home assistant command. (via service)
(I want to launch the app waipu.tv)
i can see here that the command should be "com.webos.applicationManager/launch"
and i have to enter the id in the payload. but how to find the correct id? it doesnt work with waipu.tv.
and when i run the GET_CURRENT_APP_INFO or GET_APPS command i absolutely dont get where the output is
stored.
Hi there,
I have been using this wonderful tool in combination with Kodi to switch from expert2 to/from game to enable TruMotion when I am not gaming on a LG C9.
Now with a different NVidia card I am also running 120Hz and G-SYnc/VRR/Instant Game Response. However now it seems with instant game response on I cannot use TruMotion anymore as all options are greyed out. I am also unable to DISABLE instant game response on the Windows side of things. Neither disabling G-Sync, nor using 60Hz standard Resolution works to disable VRR. The only thing that helps is when I disable Instant Game Response within the LG Picture Menu and TURN OFF Instant Game Response on the respective HDMI port.
This makes things pretty ugly. Does anyone know of a way to disable Instant Game Response programmatically ?
THANKS!
2021-11-12 02:22:30 DEBUG (MainThread) [websockets.protocol] client > Frame(fin=True, opcode=<Opcode.TEXT: 1>, data=b'{"id": 12, "type": "request", "uri": "ssap://externalpq/getExternalPqData", "payload": {"picMode": "hdr_game"}}', rsv1=False, rsv2=False, rsv3=False)
2021-11-12 02:22:30 DEBUG (MainThread) [websockets.protocol] client - event = data_received(<134 bytes>)
2021-11-12 02:22:30 DEBUG (MainThread) [websockets.protocol] client < Frame(fin=True, opcode=<Opcode.TEXT: 1>, data=b'{"type":"error","id":12,"error":"500 Application error","payload":{"returnValue":false,"errorText":"no file path from tvservice"}}', rsv1=False, rsv2=False, rsv3=False)
2021-11-12 02:22:30 ERROR (MainThread) [homeassistant.components.webostv.media_player] Error calling async_command on entity media_player.my_webos_smart_tv_48c1: PyLGTVCmdError('500 Application error')
When using externalpq/getExternalPqData
I got this error:
"no file path from tvservice
"
When using externalpq/setExternalPqData
I got this error:
"20 "Driver error while executing the command"
"
I just want to change OLED brightness.
I try writing the function separately, but the error will occur as soon as I start calibration.
I can't seem to figure it out.
BTW: for anyone who wants to use send command, the payload itself require a few more thing to complete for example
{"command": "BACKLIGHT_UI_DATA","picMode":"hdr_game"}
and perhaps
{"command": "BACKLIGHT_UI_DATA","picMode":"hdr_game", "data": "?WHATISIT", "dataCount": 30,"dataOpt": 1,"dataType":"float","profileNo": 0,"programID": 1}
But I still think that there's more to it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.