Logic Machine Forum
LG smart TV - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: LG smart TV (/showthread.php?tid=615)

Pages: 1 2


RE: LG smart TV - admin - 28.06.2021

Just try the Wake-on-LAN script, either it works with your TV or it does not.


RE: LG smart TV - mkaymak - 14.10.2022

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


RE: LG smart TV - admin - 14.10.2022

Use this script: https://forum.logicmachine.net/showthread.php?tid=687
Code:
wol_send('TV_MAC_ADDRESS')



RE: LG smart TV - mkaymak - 14.10.2022

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 ?


RE: LG smart TV - admin - 14.10.2022

Check the code/examples in this thread, especially this: https://forum.logicmachine.net/showthread.php?tid=615&pid=20936#pid20936


RE: LG smart TV - mkaymak - 14.10.2022

I have seen this examples but i'm missing something


RE: LG smart TV - admin - 14.10.2022

Code:
payload = json.encode({ mute = true })



RE: LG smart TV - mkaymak - 17.10.2022

Thank you Admin.


RE: LG smart TV - CristianAgata - 06.02.2023

(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


RE: LG smart TV - khalil - 28.02.2023

Hello Admin,
How to make the get commands like the following:
audio/getStatus
audio/getVolume


RE: LG smart TV - admin - 28.02.2023

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)



RE: LG smart TV - khalil - 28.02.2023

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}}



RE: LG smart TV - admin - 28.02.2023

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)



RE: LG smart TV - khalil - 28.02.2023

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}}



RE: LG smart TV - admin - 28.02.2023

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