Return LG WebOS TV to its previous power state or input source

This has proven a challenge for me at my current knowledge level. I have an automation that casts my video doorbell to my TV when motion’s detected or the doorbell is pressed. It works fine and I can get the automation to turn the TV off again afterwards or change the source input back to something more useful than the Chromecast using a call service such as:

service: media_player.select_source
  source: Live TV
  entity_id: media_player.lg_webos_tv_oled65c26ld
enabled: true

Where i’m struggling though is that what I really want is to return the TV to the state it was before it began streaming the doorbell. So, if the TV was powered off, switch it off again or if the TV was being watched on a different source, leave it on but return it back to the original source. Can anyone point me in the right direction? I’ve looked at variables a bit, including the Variables+History HACS integration but I can’t seem to work out how to use it correctly. I’m not so great with formatting more complex yaml. Or is there a simpler method? I would really appreciate any help!

Fortunately, the LG WebOS integration has a media API that you can use to find out :bulb: what’s selected before changing it.

GET_CURRENT_CHANNEL = "tv/getCurrentChannel"

I’m trying it in Developer Tools / Services

service: webostv.command
  entity_id: media_player.lg_tv_uh615a_living_room
  command: tv/getCurrentChannel

So far, the template editor lets me see what several attribute values are, but I’m unable to get the output result of a service call to webostv.command .

{## Get media_player state attributes ##}
{% set current_source = state_attr("media_player.lg_tv_uh615a_living_room","source") %}
{% set current_type = state_attr("media_player.lg_tv_uh615a_living_room","media_content_type") %}
{% set current_title = state_attr("media_player.lg_tv_uh615a_living_room","media_title") %}
{{ current_source }} / {{ current_type }} / {{ current_title }}

LiveTV / channel / WCNC-HD

You’ll have to have an input_boolean to store tge state of rhe TV prior switching to casting of doorbell camera. Also you’ll have to have an input_select or input_text to store the source prior of switching, if the TV was on. Once the delay after casting elapsedbyou’ll have to swt the TV in the state reflected by the input_boolean, and if it was on then to the source based on the input_select or input_text.

Services have only just gained the ability to return data. 2023.7: Responding services - Home Assistant

Not every service has this ability. Most don’t.

I am particularly interested to trigger automations when a streaming app is paused.

Thank you for that lesson in recent HA history, @nickrout !! I spent most of July missing the releases while trying to rebuild my HA system after a failure to restore a backup left me without any system at all. Fortunately, I was able to recover many things from the backup manually. Probably best that I started fresh, as my old system and database was the result of years of updates and configurations and cleanups and more.

I guess I’ve got some reading to do tonight!

The point is that services cannot, in general, feed back info.

I wonder though if there might be some info in logging.

I’m using some of those commands but where obtaining the current input is concerned, I only see GET_INPUTS which is a list. I see there’s GET_POWER_STATE though which might be one requirement solved.

My problem is putting this into a piece of yaml / script that will work with my automation. I was hoping someone had this already and I could copy/paste :slight_smile: But from the responses here it sounds as though it’s a current limitation. I had read about the recent new service response feature but if the integrations don’t make use of it yet…

Although I do sometimes edit automations in yaml, in this case I need to be able to retrieve these values and work with them in the UI or I get a bit lost. I think what you can achieve in HASS without being a dev is very cool but i’m out of my depth here without an oven-ready example to adapt.

just wondering…use PIP for stream (if supported)?

As i’m interested in this as well, just did some searching and stumbled on these: We output RTSP stream to LG webOS TV
pywebostv · PyPI
CLI Installation | webOS TV Developer

PiP would be ideal though :thinking:

Back to the problem at hand - I think if the tv is showing live tv before the interruption, and you switch back to live tv, it should revert to the previous channel. If I am right, then we don’t need to get the channel.

My media_player entity for my LG WebOS TV shows the state of the TV and what live TV channel is being watched.
The problem seems to start once it is an app running.
I can see the name of the app, but not what is being watched in that app.

My TV can’t even use ‘real’ channels anymore, as my provider only provides streams :thinking:
But yeah, no data from what the app is playing is indeed an issue (hence PiP would be a solution).