Using Node-red and Home-Assistant to send notificiations to your LG TV

LG_webOS thumb

So I wanted to cover today a topic that I’ve briefly touched on in previous articles and that is notifications through LG’s WebOS. Home-Assistant has an integration that allows us to communicate directly with LG TVs (at least the most recent ones anyway) and it’s awesome. Aside from the usual control like input switching and volume / standby etc, LG’s also have the ability to accept and display notifications. These I find really useful. Let’s face it, most of us watch a lot of TV, and so displaying notifications briefly and directly on the screen can serve us well. I will list a couple of useful ways we can use the notifications, and then I’ll walk you through the set up and execution. As always, the components are set up in Home-Assistant, but the heavy lifting is done in N0de-red.

LG WebOS
LG WebOS

Let’s get started with a list of useful notification types that we can create and use:

  1. Notification if a sensor’s state is changed. For example, if my Xiaomi zigbee contact sensor is triggered (i.e. a door or window is opened) – the TV responds with the following notifications “The (insert the name i.e. ‘back door’) has been opened.” The notification appears in the top right and disappears after a few seconds. Normally, after a certain time of the evening, I might well trigger a voice assistant also, but if you have very young children, or don’t want alexa or google blasting through the house, then this could be a potentially better option. Also if you have a home theatre, maybe you wouldn’t be able to hear or don’t own a voice assistant anyway. This is a decent alternative.
  2. I’ve already covered how much I like gaming with this most recent post. If it’s getting late but I’m tempted to sly off and try and get a few quiet rounds of call of duty with the boys, maybe I don’t want Alexa or Google ratting me out. Maybe a nice quiet 2 second pop up on the screen is exactly what’s necessary. i.e. “SteamID / Clan Warrior is online and playing “insert game” (you can get the game sensor from steam also).
  3. Maybe your children’s favourite Twitch streamer has just gone live and you’d like to watch them instead of reruns of a soap opera.
  4. Perhaps it’s nearing the kids’ bedtime and the internet is about to be cut from their rooms (doable in pfSense!) or the smart plug their bedroom TV sits on is about to have the power turned off. Maybe you want to give them a notification at 15minutes and 2minutes before on a school night that they have 15/2minutes left respectively. This can be set up on a daily weekday trigger very easily.
  5. Speaking of triggers. Perhaps you’d like a reminder 5 minutes before your favourite TV show is being broadcast. Again, you can send this to any LG tv in the house as well as a phone. I would use the Bigtimer node for the timing trigger, and this notification component.

The list goes on and on. My point is this can be really cool and useful, and super simple to set up once you have the component installed. I’ll show you how to set this up.

Firstly, give your TV internet access, whether this is wireless or wired, and give it a static IP address (usually best to do this at the router side and reserve a dhcp address). Ideally, get the TV on it’s own network (via VLANs). My reasoning for this is that some of the applications on the new smart TVs are ridiculous for the amount of connections they’re trying to make to god knows where, and some of the applications are, well, crap. By putting them on a separate network or VLAN you can control where they speak back to, as well as helping to keep them separate from your main LAN and your computers where all the valuable data sits.

Secondly, we look in home-assistant and we head over to the integrations page and search for the LG Web OS integration.

We have to add the following in our configuration.yaml page:

webostv:
  host: insert.your.tvs.ip
  name: Office TV
  turn_on_action:
    service: persistent_notification.create
    data:
      message: “Turn on action”
  customize:
    sources:
      – iptv
      – Plex
      – Youtube
      – Netflix
      – Google Play Movies & TV
      – Amazon Prime Video
If you read through the integration instructions it tells you how you can go about receiving the correct naming of the sources. You then code these into the yaml which will then give you the ability to select the source from the drop down list in Home-Assistant.
I also added the following to my configuration.yaml under the notify section:
notify:
  – platform: webostv
    host: insert.your.tvs.ip
    name: office_tv
    filename: webostv.conf 
Restart your Home-Assistant server and check you can see the newly formed Entities in your deverloper’s tools. Assuming everything is good, let’s fire up node-red.

In node-red we’re going to go with a simple notification based off a manual inject node just to test everything’s working as it should be.

Simple Notification Flow
Simple Notification Flow
LG TV Notification Flow
LG TV Notification Flow
And here is the result:
Web OS TV notification
Web OS TV notification
So far so good? As you can see, this was just a manual injection triggering a service call node in home-assistant.
Let’s make this a little more useable. I will now amend the flow to create a message automatically every time a contact sensor is triggered. I will use one of my Xiaomi Aqara sensors that I talked about extensively in this post. If you wish to know how to set these up with a $4 USB stick you can read further in this post also. The sensor is already in home-assistant and working correctly. This is the flow…
back door flow
back door flow
back door state change node
back door state change node

Two things to point out here

1) I added the if state is “on” – On my sensor that is when you pull the contacts apart.

2) You need to wire the notification to the top option on the state change node – if you hover over it, it shows ‘true’ (i.e. the condition of ‘on’ has been meant). If you want to wire a notification to the bottom part, when the contacts are closed, it can tell you something else. For this example I didn’t bother.

 

back door notification node
back door notification node
Just for completeness, I amended the text accordingly to the back door. Here’s the result when I open the contacts….
Xiaomi Contact Sensor
Xiaomi Contact Sensor
The back door is open notification
The back door is open notification

So everything works. This is the most simplest use for this component.

Other Ideas

How about a notification that tells you the temperature of the room? How would that be triggered? I’ll show you the formatting side of things for the message, but it’s up to you to think about how you would trigger it (At a set time? When the temperature falls out of a certain range? When you ask Alexa what the temperature is?). Let me know in the comments how you would do it.

Firstly the flow:

office temp flow
office temp flow

The inject node figures the Get State Node (Office Temperature). I am using my Xiaomi Aqara Temperature/Pressure/Humidity sensor I’ve already covered throughout my blog. You would change the inject node to a trigger of your choice.

get office temp node
get office temp node

 

Xiaomi Temperature/humidity/Pressure Sensor
Xiaomi Temperature/humidity/Pressure Sensor

The notification gets a little trickier here, as we need to pass through the actual result from the node we’ve just configured previously.

 

notify office temperature node
notify office temperature node

 

json edit of notification
json edit of notification

And the result:

LG Temperature Notification
LG Temperature Notification

I thought i would show you a slightly more advanced flow. I wont go into details and i’ve annotated the flow already, but in essence you can see from the debug window that I am manually showing what the flow results could be for internet speed by injecting various values into the flow on the left. I also trigger my actual internet speed to enter into the flow also. Only when the internet speed is 60 or below, do I get an alert to the LG tv about the download speed.

I could trigger this to run continually every X minutes or hours, or i could trigger this by asking Alexa what the download speed is etc.

internet speed flow
internet speed flow
Internet Speed Debug
Internet Speed Debug
Low Speed Notification
Low Speed Notification

 

I just want to show you what can be done, and how you can go about physically coding the messages accordingly. If you’d like more details on that last one or anything else I’ve covered, let me know in the comments.

If you find these tutorials useful, please consider giving my page a like on facebook where you can then see whenever a new tutorial is posted. The page can be found here: https://www.facebook.com/thesmarthomebook/

Cheers.

 

Leave a Reply

Your email address will not be published. Required fields are marked *