Configuring HA with LG TV

Hello All,

Playing with HA for about two weeks. I already put Tasmota on all devices, configured automations, dashboard and things like that. Now I’m thinking how to control LG TV. I’ve installed docker app which “talks” to TV and put information about TV to MQTT. Of course it works both directions so TV can be controlled by MQTT. In MQTT Explorer it looks like this:

image

Now - there is lgtv/connected topic with payload 1 (offline) and 2 (online). I’ve putted this sensor into my configuration.yaml like this:

sensor oliwier_tv:                                                                                                                                                                                                                                          
  platform: mqtt                                                                                                                                                                                                                                            
  name: "Oliwier TV"                                                                                                                                                                                                                                        
  state_topic: "lgtv/connected"

and it actually WORKS showing me this in HA Dashboard:

image

Of course it only shows number 1 or 2.

  1. How can I change this value in dashboard itself so it will show OFFLINE instead of 1 and ONLINE instead of 2.

  2. As said I can also control TV. For example I can turn it off by sending message to MQTT lgtv/status/system/turnOff (without any payload). This also WORKS.

So ideally I would like to have my TV shown the same way like lightbulbs and other stuff in this way:

image

So it would show state (turn on/off/offline). Of course I understand that once I turn it off it will become offline instead turned off because TV cannot be turned on remotly.

In other words how to make such slider which shows state based on lgtv/connected and send command to turn off by /lgtv/status/system/turnOff once I click slider (when it’s showing turned on state of course).

Hope my question is clear in the manner of what I’m trying to achive. Probably knowing this I would know how to nicely put other variables in dashboard from TV like volume, current app runned on TV and things like that.

Guys… partially I just did it!

Here’s my code in configuration.yaml. It doesn’t work exactly as should but OK.

switch:                                                                                                                                                                                                                                                     
  - platform: mqtt                                                                                                                                                                                                                                          
    unique_id: oliwier_tv_power_switch                                                                                                                                                                                                                      
    name: "Oliwier TV Power Switch"                                                                                                                                                                                                                         
    state_topic: "lgtv/connected"                                                                                                                                                                                                                           
    command_topic: "lgtv/set/system/turnOff"                                                                                                                                                                                                                
    payload_on: "2"                                                                                                                                                                                                                                         
    payload_off: "1"                                                                                                                                                                                                                                        
    state_on: "2"                                                                                                                                                                                                                                           
    state_off: "1"                                                                                                                                                                                                                                          
    optimistic: false                                                                                                                                                                                                                                       
    qos: 0                                                                                                                                                                                                                                                  
    retain: true            

Result is like this:

image

When the TV is ON - Oliwer TV then slider is actually ON (blue and so on). When I click the slider the TV actually turns off. The only thing is that in such configuration after turning TV OFF the slider is OFF but not greyed OUT (as offline) so is clickable. It shouldn’t work like that. However when I click to turn ON it automatically goes back to turn OFF after two seconds (of course because MQTT tells HA that TV is actually OFF). So I know the config is messed but enough for my needs. WORKS !!!

About my first question. When I get payload from my TV saying something like com.webos.app.hdmi3 (meaning that TV is on HDMI3 right now) how can I change this information just in dashboard card to something more human readable like “Source: HDMI3” or “Application: HDMI3”?