cmer/lg-tv-control-macos

ERROR: incorrect type 'nil' for argument 1 (expected string)

tonycassara opened this issue · 11 comments

I keep getting this error whenever the script tries to run. I'm wondering if I have an outdated version of something. I'm on OS Ventura.

	/Users/tcassara/.hammerspoon/init.lua:18: in function 'lgtv_current_app_id'
	/Users/tcassara/.hammerspoon/init.lua:88: in function </Users/tcassara/.hammerspoon/init.lua:72>
2023-01-30 10:29:29: 10:29:29 ERROR:   LuaSkin: hs.caffeinate.watcher callback: /Users/tcassara/.hammerspoon/init.lua:18: ERROR: incorrect type 'nil' for argument 1 (expected string)
stack traceback:
	[C]: in function 'hs.json.decode'
	/Users/tcassara/.hammerspoon/init.lua:18: in function 'lgtv_current_app_id'
	/Users/tcassara/.hammerspoon/init.lua:88: in function </Users/tcassara/.hammerspoon/init.lua:72>

I'm not sure if this is related to the MacOS version, but I'm on OS Ventura and have the same error:

2023-02-01 10:24:00: 10:24:00 ERROR: LuaSkin: hs.caffeinate.watcher callback: /Users/russdunkin/.hammerspoon/init.lua:18: ERROR: incorrect type 'nil' for argument 1 (expected string)
stack traceback:
[C]: in function 'hs.json.decode'
/Users/russdunkin/.hammerspoon/init.lua:18: in function 'lgtv_current_app_id'
/Users/russdunkin/.hammerspoon/init.lua:88: in function </Users/russdunkin/.hammerspoon/init.lua:72>

Seems likely!

Changing "tv_name" in init.lua to "MyTV" instead of the actual TV name fixes the sleep issue:

local tv_name = "MyTV" -- Name of your TV, set when you run lgtv auth

However, the wake-up command still doesn't function, and "500 Application error" occurs if I run the command:

russdunkin@russmacbookpromax ~ % ~/opt/lgtv/bin/lgtv MyTV screenOn ssl
DEBUG:root:Initiating handshake
DEBUG:root:Received response
DEBUG:root:{"type":"registered","id":"register_0","payload":{"client-key":"18215e3501bf07b8de382b5231f8fe92"}}
DEBUG:root:Handshake complete
DEBUG:root:{'id': '0', 'type': 'request', 'uri': 'ssap://com.webos.service.tvpower/power/turnOnScreen', 'payload': '{"standbyMode": "active"}'}
DEBUG:root:Received response
DEBUG:root:{"type":"error","id":"0","error":"500 Application error","payload":{"returnValue":false,"state":"Always Ready","errorCode":"-102","errorText":"The current sub state must be 'screen off'"}}
DEBUG:root:{'type': 'error', 'id': '0', 'error': '500 Application error', 'payload': {'returnValue': False, 'state': 'Always Ready', 'errorCode': '-102', 'errorText': "The current sub state must be 'screen off'"}}
{"type": "error", "id": "0", "error": "500 Application error", "payload": {"returnValue": false, "state": "Always Ready", "errorCode": "-102", "errorText": "The current sub state must be 'screen off'"}}
{"type": "error", "id": "0", "error": "500 Application error", "payload": {"returnValue": false, "state": "Always Ready", "errorCode": "-102", "errorText": "The current sub state must be 'screen off'"}}
DEBUG:ws4py:Closing message received (1000) 'b'''
{"closing": {"code": 1000, "reason": ""}}

Might have to go back to invoking wakeonlan instead... but if it gets me there okay then.

Unfortunately my tv_name is already set to MyTV as set when authenticating and I still can't sleep the screen.

The issue for me after debugging is that the hs.execute method does not actually return anything. I'm not sure how it's being eaten up but I get a nil return on line 16.

Opened an issue with hammerspoon hopefully someone there knows what's up: Hammerspoon/hammerspoon#3375

hs.execute returns 4 results and without knowing what those other result values are, it's hard to say what the problem is... (see http://www.hammerspoon.org/docs/hs.html#execute)

as a debugging measure, you could change line 16 to something like this:

    -- local foreground_app_info = exec_command("getForegroundAppInfo")
    local foreground_app_info, status, typ, rc = exec_command("getForegroundAppInfo")
    print(foreground_app_info, status, typ, rc)

This would show what the other values are. Ideally, the three additional values should be true, "exit", and 0 which would indicate that the command executed and exited properly.

If the number at the end is 127, then it means that the command isn't being found in the path (or the path, if fully specified, is wrong) or that the file doesn't have it's execute bit set. Other numbers would depend... if the program itself uses return codes to indicate problems, you'd need to look at its documentation or man pages; if the program doesn't use return codes, then check the man pages for bash or zsh, depending upon what your default terminal shell is.

Rather than using Hammerspoon, I've just set BetterTouchTool to run the commands.

After Mac Wakes Up From Sleep: ~/opt/lgtv/bin/lgtv MyTV screenOn ssl;
Before Mac Goes Yo Sleep: ~/opt/lgtv/bin/lgtv MyTV screenOn ssl;

My LG is now turning on and off like a monitor.

Okay just to be clear I installed the application in the wrong place. I installed it in my root directory and not the user directory 😣

You can just remove ~ from the application path if you did the same and it works!