This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LG smart TV
#21
Just try the Wake-on-LAN script, either it works with your TV or it does not.
Reply
#22
Hi , Admin how should i use Wake-on-LAN script
TV has wake-on-lan feature , i tried with someother controllers,But could'nt make it with LM
Reply
#23
Use this script: https://forum.logicmachine.net/showthread.php?tid=687
Code:
wol_send('TV_MAC_ADDRESS')
Reply
#24
Thanks it worked.
Another thing i stumbled on is mute

"lgtv.request('ssap://audio/setMute', {mute: true});"

How can i change this line to lua ?
Reply
#25
Check the code/examples in this thread, especially this: https://forum.logicmachine.net/showthrea...6#pid20936
Reply
#26
I have seen this examples but i'm missing something

Attached Files Thumbnail(s)
   
Reply
#27
Code:
payload = json.encode({ mute = true })
Reply
#28
Thank you Admin.
Reply
#29
(13.07.2020, 17:54)ro_ki@tut.by Wrote: Attached you can find the library to control LG TV with Web OS. 
It uses Lua websocket library from here https://github.com/lipp/lua-websockets. Websocket library is also available in this forum.
Just change the name of the library to yours in the coding ('user.websocket_client_sync')

It was inspired by Node.JS module https://github.com/hobbyquaker/lgtv2, you can also find a list of commands and configuration instructions there.

Coding is published as is , errors are possible Smile

The following command will turn Off the LG TV . 2 constants below are the IP address of the LG TV and the KNX group address to store the handshake key.
Code:
lg_execute_command(LGTV65_IP, LGTV65_KEY, "", "request", "ssap://system/turnOff", "")
Hi, 
Thank you so much for your works, I am working with your script. On WOL I can work with the TV, but with script I always receive (no connection). Is there some initial confirmation to do before start?
Best regards Cristian
Reply
#30
Hello Admin,
How to make the get commands like the following:
audio/getStatus
audio/getVolume
Best Regards,
Reply
#31
You need to modify the lg_execute_command function to return the response:
Code:
function lg_execute_command(ip, key_address, prefix, msgtype, uri, payload)
  local connection_sync = require('user.websocket_client_sync')
  local url = 'ws://'..ip..':3000/'
  local resp
  local client = connection_sync.client(5)
  local noerr,msg,headers = client:connect(url)

  if noerr then
    if initial_connect(client, key_address) then
      resp = send_command_with_response(client, prefix, msgtype, uri, payload)
    end
  else
    log('No connection with TV. Probably it is switched off', url, noerr, a, text)
  end

  local was_clean,code,reason = client:close()
  log("Connection close result:", was_clean,code,reason)

  return resp
end

Then try this and see if you get anything logged:
Code:
resp = lg_execute_command(LGTV65_IP, LGTV65_KEY, "", "request", "ssap://audio/getStatus", "")
log(resp)
Reply
#32
Thanks Admin
yes I get the following: 
Code:
"returnValue":true,"volumeStatus":{"activeStatus":true,"adjustVolume":true,"maxVolume":100,"muteStatus":false,"volume":8,"mode":"normal","soundOutput":"tv_external_speaker"},"callerId":"com.webos.service.apiadapter","mute":false,"volume":8}}
Best Regards,
Reply
#33
Looks like a part of a JSON string. Have you copied it completely?
The correct way is to parse the JSON but it is also possible to get the volume value from the output like this:
Code:
volume = resp:match('"volume":(%d+)')
log(volume)
Reply
#34
Here is the full string
Code:
* string: {"type":"response","id":"******","payload":{"returnValue":true,"volumeStatus":{"activeStatus":true,"adjustVolume":true,"maxVolume":100,"muteStatus":false,"volume":8,"mode":"normal","soundOutput":"tv_external_speaker"},"callerId":"com.webos.service.apiadapter","mute":false,"volume":8}}
Best Regards,
Reply
#35
Try this then:
Code:
data = require('json').pdecode(resp)
if type(data) == 'table' then
  volume = data.payload.volumeStatus.volume
  log(volume)
else
  log('invalid response', resp)
end
Reply
#36
Hello dears,
the turn off command stop working, is there any changes have been made on the LG TV?

here are the log response of the lg_execute_command

* arg: 1
  * string: No connection with TV. Probably it is switched off
* arg: 2
  * string: ws://192.168.10.8:3000/
* arg: 3
  * nil
* arg: 4
  * nil
* arg: 5
  * nil


* arg: 1
  * string: Connection close result:
* arg: 2
  * bool: false
* arg: 3
  * number: 1006
* arg: 4
  * string: wrong state
Best Regards,
Reply
#37
Hello Dears,
Has anyone encountered a similar issue? Are there any updates that need to be applied?
Best Regards,
Reply


Forum Jump: