6-8-2019 – have stopped using the Broadlink RM Pro +
Nowadays I switched from the Broadlink to a Harmony Hub, so my code on Github has also been changed to the use of services that control the Harmony Hub. I have now added the basic code for using a Broadlink in this article.
Help my TV do weird things, Well no… it’s Home Assistant who is in control! Today we are going into the depths of a new part within my system, being able to operate your TV through “Hey Google turn on TV!” and more! 😀
To get this all working I use a Broadlink RM Pro, IFTTT and Google Assistant. Here and there you will find a link that refers to my code on github.
1. Find the right IR codes
I assume that you are already using a Broadlink device and that you have correctly set it up in Home Assistant. Then we have to figure out all the IR codes, so that we will later simulate the correct button from the remote control.
This goes as follow:
- In your UI go to developer tools -> Services.
- Choose the service: Broadlink.learn.
- Enter as service data: {“host”:”IP_ADDRESS OF BROADLINK”}
- Click on call service.
- Then point your remote control at the Broadlink device and press the desired button that you want to teach in.
- You now get a persistent notification in your UI with the IR code (base64 string), save it somewhere.
- Repeat these steps until you have saved all the buttons you want.
2. Scripts
Next, we will create script (see code below) for channels 0 through 9, each of which can send a broadlink package from the specific button with that number. If you have done this, check whether your TV responds with the correct numbers. During testing in my house, sometimes a IR code didn’t work well and I had to repeat the steps above.
# Channel 0
channel_0:
alias: 'TV - Kanaal 0'
sequence:
- service: broadlink.send
data:
host: HOST_IP
packet:
- "IR CODE - BASE64 STRING"
You can of course also use the same service (service: broadlink.send) to have the TV change from source. put several packets underneath each other and especially view the documentation of the broadlink for even better examples.
3. Python code
I have found a python script (select_channel.py) on the community forum, with which Google Assistant will be able to independently match the right number combination and the underlying broadlink packages. So that you can call all channels on your TV with less hardcoded scripts.
4. If This Then That (IFTTT)
Now we will make sure that we can ask Google Assistant, to get the desired channel on TV through voice. Create a new applet with IF (Google Assistant) and THEN (Webhook). Below 2 screenshots so that you can see exactly what you must enter.
If you have also read my previous blog about bedtime / getting up, then you know that there must also be an automation (handle_ifttt.yaml) that handles the IFTTT requests. You have to add the attribute “channel” to the “data_template”, this to catch the number / tv channel that you say to google and use it in the python script.
From now on it is possible to say: “Hey Google! Channel 5 please”.
5. Switch TV on or off
It would also be nice if you could turn the TV on / off and that we could adjust the volume or mute the TV. How did I do that in the code? Well you can find it below.
---
# https://www.home-assistant.io/components/broadlink/#switch
#
platform: broadlink
host: BROADLINK_IP
mac: BROADLINK_MAC_ADDRESS
type: rm2_pro_plus
switches:
tv_lg:
friendly_name: "LG TV Power"
command_on: 'IR CODE - BASE64 STRING'
command_off: 'IR CODE - BASE64 STRING'
tv_mute:
friendly_name: "LG TV mute"
command_on: 'IR CODE - BASE64 STRING'
command_off: 'IR CODE - BASE64 STRING'
tv_volume:
friendly_name: "LG TV volume"
command_on: 'IR CODE - BASE64 STRING'
command_off: 'IR CODE - BASE64 STRING'
6. Make a remote in the UI
To top it all off, sometimes it can also be nice if you can operate the TV from the UI / frontend. So I made a separate view (media_player.yaml) and build a kind of remote control made in lovelace.
Are things not clear? Or if you have come to ideas by reading this blog, about how I can make it cooler and better? Share it with me! Via Twitter, mail or Github.