Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Get the return value of a command in home assistant #56

Open
vaibhav2912 opened this issue May 23, 2022 · 2 comments
Open

[Question] Get the return value of a command in home assistant #56

vaibhav2912 opened this issue May 23, 2022 · 2 comments

Comments

@vaibhav2912
Copy link

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

@Jasper-itsme
Copy link

Wondering the same thing. Calling the command is no brain teaser but how to receive and use data coming from the tv is.

@vaibhav2912
Copy link
Author

Because I didn't get any response on this, I did it with Node-Red add-on in HA.
Its still not Publish-Subscribe model. I need to invoke the flow in Node-Red to get the latest PowerState of the TV. I have set up a automation in HA to do that so it works OK.

I use node-red-contrib-lgtv 1.1.0.

Use the config node from this to create a config for your LG TV. You need IP address of your TV. I recommend using static IP so your configuration is guaranteed to work.

Set up Node-Red with Home Assistant if you haven't already so you can use the output of the Node-Red flow inside Home Assistant.

The flow to test the API call to LG TV and see the output in the debug window in Node-Red. Copy this and paste in Node-Red import window.

[{"id":"a87c1f750a91bdbd","type":"inject","z":"0ae12e835f14d4d6","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":570,"y":200,"wires":[["d615edf81c390e96"]]},{"id":"d615edf81c390e96","type":"function","z":"0ae12e835f14d4d6","name":"getPowerState","func":"return {\n topic: 'ssap://com.webos.service.tvpower/power/getPowerState',\n payload: {}\n};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":200,"wires":[["8469f7793527dc01"]]},{"id":"8469f7793527dc01","type":"lgtv-request","z":"0ae12e835f14d4d6","tv":"","name":"requestPowerState","x":1030,"y":200,"wires":[["e0be6dfa88eafaba"]]},{"id":"e0be6dfa88eafaba","type":"debug","z":"0ae12e835f14d4d6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.state","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":280,"wires":[]}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants