Simple TV Channel Command Sequencing: Broadlink RF-IR Blaster

Hi, I’m using the Broadlink RM Pro to activate my blackout blinds and change TV channels. I could not find anything like a standard TV remote control, so I have been making my own system. It is a crude approach, but at least it works.

Essentially I recorded each digit on the remote so that I can press them in sequence. This works but it gets tricky when you get up to ch 345, not to mention I can’t remember what they are. Out of the hundreds of channels we have, there are only a few I watch, like HBO.

So I am wondering how to combine actions onto one switch. For instance, here is the switch I created for channel 1:

switch 70:
  platform: broadlink
  host: 192.168.1.187
  mac: 'b4:43:0d:ee:f5:88'
  timeout: 15
  switches:
    tv:
      friendly_name: "TV Ch 1"
      command_off: 'JgAoAAABJ5ISRxJIEkcSSBJHEkgSRxJIEkcSSBJHEkcTRxJHEkgSRxIADQU='
      command_on: 'JgAoAAABJ5ISRxJIEkcSSBJHEkgSRxJIEkcSSBJHEkcTRxJHEkgSRxIADQU='

What I’m wondering is how would I combine digits into a single switch, with perhaps a delay between each one, so that I can create an HBO switch? (ch 245). I have studied the automation scripts but it seems they are relatively complicated sequences, and I’m wondering if there is a simple solution for a TV channel changer.

I have an Input Select to have options, and then based on the option selected, it will call the necessary script which is a sequence of IR codes.
Ie one sequence to power on my stereo, one to change the stereo input etc until the action is completed.

Hi, that sounds like essentially the same thing I wanted to do, but I just can’t seem to create the correct code for it. Would you have any tips or sample code? Tks

Hope this helps. just have provided the automation and script for one of the inputs but it should be enough to get you going …

Input Slider:

input_select: 
  denon_input:
    name: 'Denon Receiver Input:'
    initial: "Off"
    icon: mdi:speaker
    options:
      - "Off"
      - "Tuner"
      - "Kodi"
      - "ChromeCast Audio"
      - "CD"
      - "BluRay"
      - "USB"
      - "TV Audio"

Automation:

alias: 'Change CCA'
trigger:
  platform: state
  entity_id: input_select.denon_input
  state: 'ChromeCast Audio'
action:
  service: script.turn_on
  entity_id: script.denon_cca

script:

alias: Change to CCA
sequence:
# Power on Denon AVR 
  - service: broadlink.send_packet_192_168_2_63
    data:
      packet:
       - "JgAQAQsYCTwKGAoZChgKOwoZChgKGQoZCTwJPAk8ChgKGQkABfMLGAk8ChgKGQkZChkJPAk9CjsKOwoYChkJGQo7CjsKAAWtDBcKOwoZChgKGQk8ChgKGQkaCRkJPAo7CjsKGQkZCgAF8woYCjsLGAkZChkJGQo7CjsKPAo7ChkJGQoZCTwKOwoABawLGQo7ChgKGQkZCjsKGQkaCRkJGQk9CjsJPAkZChkJAAXzCxgJPAoYChkJGQoZCTwKOwo8CjsKGAoZCRkJPAk9CQAFrgoXCzsKGQkZChgKPAkaCRgKGQkZCjwJPAo7ChkJGQkABfQKGAo7CxgJGQoZCRkJPAo7CjsKPAoYChkJGQo8CjsKAA0FAAAAAAAAAAA="
  - delay: '00:00:10'
# Change Input to CCA
  - service: broadlink.send_packet_192_168_2_63
    data:
      packet:
      - "JgDMAAkbCD0IGgkaBhwIGwYdBj8HPggaCBsHPgg9CBoJGggABfQIGwg9CBoIGwgaCD0JPQgaCBoJPQc+BxwGHAg9CD4IAAWuCBsHPgkaBhwHHAcbCBoHPwc+CBsGHAc+Bz4IGwgaCQAF9AgaCD0JGggaCRoIPQg9CBoJGgg9CD4GHAcbCD4IPQcABa8JGgg+BxsHGwgbCBoIGwg9CD4GHAgaCD4HPggaBxwGAAX2CBsIPQgaCRoIGgc+CTwJGggbCD0IPQgaCBsIPQg+BgANBQAAAAAAAAAAAAAAAA=="
3 Likes

Hi @switched, thanks for that, it is very helpful. I had been wondering about how to do the input selector too. I was able to make a switch run a script, triggered by the state of the switch being on or off. This is great because now I can make a switch do all kinds of sequential things. A TV channel changer is just one of many applications I can think of.

The other challenge I have is to make the ‘Command Line Cover’ component work. It differs from the switch in that it has 3 ‘buttons’ for OPEN/CLOSE/STOP. I have some Rollertrol blind motors (radio RF type) that work with the Broadlink hub, and I thought it might work in a very similar way to the switch.

Unfortunately I can’t seem to make it work because the state that is normally used as the trigger is not passed to the automation code (shows as ‘unknown’), so no scripts are executed. Any ideas about how to get around this problem and detect a button press on the Cover object?

This would be very helpful in my home theater, so that I can deploy the blackout blinds (using Cover), turn the projector on, deploy the projector screen, crank the audio, select input, etc etc.

Thanks for your help!

  • Make input select with all the channels you want to be able to select
  • Add an automation that is triggered when the input select changes value
  • In the action, have a service call to send a broadlink command or packet whatever it is called
  • use data_template instead of data
  • In the packet, use a template that checks the value of the input select to determine which IR command to use

Possible example:

alias: 'Change Channel'
trigger:
  platform: state
  entity_id: input_select.channels
action:
  - service: broadlink.send_packet_192_168_2_63
    data_template:
      packet: >-
        {% set channel = states.input_select.channels.state %}
        {% if channel == "HBO" %}JgAQAQsYCTwKGAoZChgKOwoZChgKGQoZCTwJPAk8ChgKGQkABfMLGAk8ChgKGQkZChkJPAk9CjsKOwoYChkJGQo7CjsKAAWtDBcKOwoZChgKGQk8ChgKGQkaCRkJPAo7CjsKGQkZCgAF8woYCjsLGAkZChkJGQo7CjsKPAo7ChkJGQoZCTwKOwoABawLGQo7ChgKGQkZCjsKGQkaCRkJGQk9CjsJPAkZChkJAAXzCxgJPAoYChkJGQoZCTwKOwo8CjsKGAoZCRkJPAk9CQAFrgoXCzsKGQkZChgKPAkaCRgKGQkZCjwJPAo7ChkJGQkABfQKGAo7CxgJGQoZCRkJPAo7CjsKPAoYChkJGQo8CjsKAA0FAAAAAAAAAAA=
        {% elif channel == "Discovery" %}JgAQAQsYCTwKGAoZChgKOwoZChgKGQoZCTwJPAk8ChgKGQkABfMLGAk8ChgKGQkZChkJPAk9CjsKOwoYChkJGQo7CjsKAAWtDBcKOwoZChgKGQk8ChgKGQkaCRkJPAo7CjsKGQkZCgAF8woYCjsLGAkZChkJGQo7CjsKPAo7ChkJGQoZCTwKOwoABawLGQo7ChgKGQkZCjsKGQkaCRkJGQk9CjsJPAkZChkJAAXzCxgJPAoYChkJGQoZCTwKOwo8CjsKGAoZCRkJPAk9CQAFrgoXCzsKGQkZChgKPAkaCRgKGQkZCjwJPAo7ChkJGQkABfQKGAo7CxgJGQoZCRkJPAo7CjsKPAoYChkJGQo8CjsKAA0FAAAAAAAAAAA=
        {% endif %}

None of the code is tested and I don’t have broadlink myself, but should give a basis of where to start.

Expected outcome would be you choose a value (channel) in the input select, and then that changes the channel on the tv to what you selected.

edit: Just remembered you are only sending number commands 1 by 1, so this would require some adjustment, possibly write a script for each channel and call the script using service_template instead.

------------------------------ I go off on a tangent below… --------------------

Or write a script that takes in a numeric variable such as 345 which will call itself, sending IR commands for the first digit in the variable. So, script takes in value 345, it looks at the first digit (3) and sends the IR command for the number 3, then it calls itself using the remaining value (45) and does the same until it runs out of numbers. Just spitballin… this one would be better to do in something like a python script if you have experience with that but is the better solution in my opinion.

Ok since I have now written a wall of text ill make a…

TL;DR:
If I were doing this, I would write a python script that takes in channel names as a parameter. The script would be able to determine the channel number from the channel name, then send the IR commands for that channel number. The script would be called anytime the input_select value is changed.

Hi @stunts1337, thanks for that feedback, I can see my way clearly now, except for one final thing …

I’m wondering if you (or anyone) has had any experience with the Command Line Cover component? I would really like to implement that for my projector screen and blackout blinds. If I can make it run a script then I can make the BroadLink hub send the commands to activate the blind motors and screen motor at the same time.

Unfortunately it does not seem to pass the state to the Automation section to trigger a script.

Also, got to say, this is the best forum I have ever used! Tip of the hat to y’all …

Sorry, havn’t used covers yet myself. Hopefully someone else will chime in

I made each number a broadlink switch, then used an automation to select switches in succession.

input select
    tv_channel_pick:
  name: Pick Channel
  options:
   - CBS
   - NBC
   - FOX
   - ABC
   - UPN
   - WB11
   - PBS
  initial: CBS

broadlink switch

tv_sharp_nana_1:
    friendly_name: "TV 1"
    command_on: 'JgAQAQk7CRkJGQkaCRkJOwkZCRkJGQkZCRkJGggaCTsJGQkABjMJOwkZCRoIGQoZCRkJOwk8CTsJPQg8CTwIPAkZCTwJAAVjCTsJGQkaCRkJGQk7CRkJGggZCRkJGggaCRkJPAgZCQAGMwk7CRkJGgkZCRkJGQk7CTwJPAk7CTwJOwk8CRcLPAkABWMJOwkZCRoJGQkZCTsJGQkZCRkJGQkaCBkKGQk7CRkJAAYzCTsJGQkaCRkJGQkZCTwIPAk8CTsJPAk7CT0IGQk8CQAFYwk7CRkJGggaCRkJPAgZCRkJGQkZCRkJGQkaCTsJGQkABjMJOwkZCRkJGgkZCRkJOwk9CDsJPQg8CTkLPAkZCTsKAA0FAAAAAAAAAAA=='
tv_sharp_nana_2:
    friendly_name: "TV 2"
    command_on: 'JgB2AQk8CRkJGQkaCBkJGQk8CBkJGggaCRkJGggZCTsJGggABjQIOwoZCRkJGggZCTsJGQk8CTwJOwk8CTsJOwoaCDwJAAVjCTsJGgkZCRkJGQkZCTsJGQkZCRoIGgkZCRkJOwkZCQAGMwk7CRkKGQkZCRkJOwkZCTwJOwo7CTwJOwk9CBkJPAkABWMJOwkZCRoJGQkZCRkJOwkZCRkJGggZCRoJGQk7CRkJAAYzCTkLGggZCRoJGQk7CRkJPAk7CTwJPAk8CDwJGQk7CgAFYwk7CRkJGQkaCBoIGgk7CRkJGQkZCRkJGQkZCTwJGQkABjMJPAgZCRkJGQkZCTwJGQk9CDsJPQg8CTsJPAkZCTsKAAVjCTwIGQkZCRkJGggZCTwJGQkZCRkJGQkaCBoIPAkZCQAGMwk7CRkJGQkZCRkKOwkZCTwJOwk8CTsKOwk8CRkJOwkABWMKOwkZCRkJGQkZCRkKOwkZCRkJGQkZCRkJGQk8CRkJAA0FAAA=='

and so on to 0

automation

##############################################################################
- alias: "tv channel 11"
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_select.tv_channel_pick
  condition:
    - condition: state
      entity_id: input_select.tv_channel_pick
      state: 'WB11'
  action:
  - service: switch.turn_on
    data_template:
      entity_id: switch.tv_1, switch.tv_1

##############################################################################
- alias: "tv channel 13"
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_select.tv_channel_pick
  condition:
    - condition: state
      entity_id: input_select.tv_channel_pick
      state: 'PBS'
  action:
  - service: switch.turn_on
    data_template:
      entity_id: switch.tv_1, switch.tv_3
2 Likes

Hi @jpenyc, thanks for that, I think using the dropdown input selector for your usual network settings is the way to go. It is very compact, rather than a bunch of switches. Still, it would be nice to have a graphical representation, but does not seem to be HASS’s strong suit.

Now I’m hoping someone will figure out how to make a cover component run a script …

1 Like

Hi all, I have a very similar implementation of this concept but as my TV requires three button presses to select the channel I want I have done the following:

Input_Select:

master_bedroom_tv_channel:
  name: 'Master Bedroom TV Channel'
  options:
   - 'ABC (2)'
   - 'ABC HD (20)'
   - 'ABC2 (22)'
   - 'ABC ME (23)'
   - 'ABC News 24 (24)'
   - '9HD (90)'
   - 'Nine (91)'
   - 'GEM (92)'
   - 'GO! (93)'
   - '9Life (94)'
  initial: '9Life (94)'
  icon: 'mdi:television'

Automation:

- alias: 'TV Channel ABC (2)'
  hide_entity: True
  trigger:
    - platform: state
      entity_id: input_select.master_bedroom_tv_channel
      state: 'ABC (2)' 
  action:
    - service: script.master_bedroom_tv_channel_0
    - service: script.master_bedroom_tv_channel_0
    - service: script.master_bedroom_tv_channel_2


- alias: 'TV Channel ABC HD (20)'
  hide_entity: True
  trigger:
    - platform: state
      entity_id: input_select.master_bedroom_tv_channel
      state: 'ABC HD (20)' 
  action:
    - service: script.master_bedroom_tv_channel_0
    - service: script.master_bedroom_tv_channel_2
    - service: script.master_bedroom_tv_channel_0

Script:

master_bedroom_tv_channel_0:
    alias: Master Bedroom TV Channel 0
    sequence:
      - service: broadlink.send_packet_192_168_1_99
        data:
          packet: 
            - "JgDgAFERKhAXERYRKhAXEBcQFxAqERcQFxAXEBcAA1pRESoRFhEWESoRFhEWERYRKhEWERYRFhEWAANbUREqERYRFhEqERYRFhEWESoQFxEWERYRFgADW1ERKhAXEBcRKhAXEBcQFxEpERcQFxAXEBcAA1tRECoRFhEXECoRFhEWERYRKhEWERYRFhEXAANaUREqERYRFhEqERYRFhEWESoQFxEWERYRFgADW1ERKhAXERYRKhAXEBcQFxEpERcQFxAXEBcAA1tRESkRFxAXECoRFhEWERcQKhEWERYRFhEXAA0FAAAAAAAAAAA="

master_bedroom_tv_channel_1:
    alias: Master Bedroom TV Channel 1
    sequence:
      - service: broadlink.send_packet_192_168_1_99
        data:
          packet: 
            - "JgDgAFERFhEWERYRFhEWERYRFxAqERYRFhEWERcAA4JRERYRFhEWERYRFhEWERYRKhEWERYRFhEWAAOCUBIWERYRFhEWEhUSFhEWESkRFhIVEhUSFQADg1ERFhEVEhYRFhEVEhYRFxEpERYRFhEWERcAA4JRERYRFhEWERYRFhEWERYRKhEWERYRFhEWAAOCUREXEBcQFxEWERYRFhEWESoRFhEWERYRFgADglERFhEWERYRFxAXEBcQFxEpERcQFxAXEBcAA4JRERYRFhEWERYRFhEWERcQKhEWERYRFhEXAA0FAAAAAAAAAAA="

master_bedroom_tv_channel_2:
    alias: Master Bedroom TV Channel 2
    sequence:
      - service: broadlink.send_packet_192_168_1_99
        data:
          packet: 
            - "JgDgAFEQKhEWERcQFxAXEBcRFhEqEBcQFxAXERYAA29RECoRFhEXEBcQFxAXERYRKREXEBcQFxAXAANuUREqEBcRFhEWERYRFhEWESoRFhEWERYRFgADb1ERKREXEBcQFxAXERYRFhEqEBcQFxEWERYAA25SECoRFhEWERYRFhEXEBcQKhEWERYRFxAXAANuUREqEBcRFhEWERYRFhEWESoRFhEWERYRFgADb1ERKREXEBcQFxEWERYRFhEqEBcQFxEWERYAA25SECoRFhEWERYRFxAXEBcQKhEWERcQFxAXAA0FAAAAAAAAAAA="

If anyone in Melbourne metro wants to do something similar I have all our Free To Air channels configured and I’m happy to share this to save others the hassle I went through building this for my use.

6 Likes

Thanks for your sharing.

Would you please tell me how the files( include Input_Select , Automation and script) are organized? Thanks!

I have add the contents to the configuration.yaml. But it did not work with my input_select. I do not know why.

Please help me. Thanks

I have the following in my configuration.yaml and break the files out to make things easier to manage:

automation: !include_dir_merge_list includes/automation/
input_select: !include includes/input_select.yaml
script: !include_dir_merge_named includes/script/

so my automation file for this is includes/automation/automation_tv_channel.yaml
and my scripts are in a file includes/scripts/scripts_tv_channel.yaml

I have a lot going on with my HASS and have found managing lots of files makes it easier to diagnose and switch between files I’m editing.

Looks good but I bet you could probably make it less repetitive using a script with a variable you pass it (being the channel numbers that you can derive from a dictionary value)

For example, in your action you can do

action:
  - service: script.change_channel
    data_template:
      channel: >
        {% set channelList = {'ABC': [0, 0, 2], 'CBS': [0, 0, 3]} %}
        {{ channelList[states.input_select.master_bedroom_tv_channel.state] }}

And change the trigger so it fires after the input_select is changed (so you only need 1 automation now). So now the script should have this array variable that holds the numbers for the selected channel.

Then in the new script you take this variable to send the corresponding IR commands.

sequence:
  - service_template: 'script.master_bedroom_tv_channel_{{channel[0]}}' 
  - service_template: 'script.master_bedroom_tv_channel_{{channel[1]}}' 
  - service_template: 'script.master_bedroom_tv_channel_{{channel[2]}}' 

Honestly im not confident this code will work, im mostly bored so I just decided to write this. But you can see where im going, this is more dynamic and if you want to add more channels all you need to do is update channelList and add the selection to your input_select.

While this specific code may have errors since I have not tested it, I am confident it is possible to do this.

Also you could just use 1 script for master_bedroom_tv_channel that takes in a variable as well instead of having 10 of them for each number.

But at this point it is starting to approach a level of complexity where I personally would just write a python script to do this and call it any time the input select value is changed.

Hi,
My aircon needs to send the IR codes in command_off twice to the switch off the Aircon. How do I do a sequecnce with a delay in between in switch?? Below is my code:

switch:
  - platform: broadlink
    #friendly_name: 'broadlink Mini'
    timeout: 15
    host: 192.168.1.196
    mac: '32:EB:37:BC:F6:AB'
    switches:
      study_ac:
        friendly_name: "Study AC"
        command_on: 'JgAqAZCOETYRNRI1ETYREhMRETUSEhIRExEREhMQEjURNhESEjUREhISERISEhESExASNRE2ETYRNRI1ETYRNhE1EhIREhISERISERISERISEhESEjUREhI1ETYRNRISERISEhESERISNRESEhIREhISERISNRESEhESEhESEhIREhIREhIREhISETUSNRESEhIREhISEfWPjxE2ETYRNRI1ERISEhE2ERISERISERISEhE1EjUREhI1ERMREhIREhIREhIREjURNhE2ETUSNRI1ETYRNhESEhESEhESEhIREhIREhIREhI1ERISNRE2ETUSEhESEhIREhIREjURExESEhESEhESEjUREhISERISERISERISEhESEhESEhE1EjURExESEhESEhEADQUAAAAAAAAAAAAAAAAAAA=='
        command_off: 'JgAqAZGOETUSNRE2ETYREhMREDYRExESExATERIRETYSNRIREjUREhMREBMSERMREhETNBA3ETUTNBE2ETYRNRI1ExESERMQExESERETEhEREhETEjQSEhI1ETUSNRISEhEREhMREhERNhESExESERI1ETYRNRISEBMSERMREhERExATEhERExATEzQSNRATEDcQNxIREfWOkBI1ETYRNhA2EhIQExE2ERISEhIRERMREhA3ETUSEhE2EBMREhMREBMSERETETYRNRE2ETYRNhE1EjURNhESExEQExMRERISERETEhETEBE2ERMRNRE2ETYREhETEBMREhETEDYRExESEhISNBM0ETYSERETEBMQFBESEhERExIREBMRExA3EjQSEhA2EzQRExIADQUAAAAAAAAAAAAAAAAAAA=='

Thank you. I used the remote to capture the packets and filled them in but they didn’t work out for me.

When I turn my TV on, I have to turn my DVR on too, because the DVR acts as the tuner for the TV. So I have to send two ‘on’ codes: one for the TV and one for the DVR. Since the on/off switch is basically a stateless switch, it made no sense for me to use the command_on and command_off statements, because they are the same exact code. So I basically used the script entity instead of switch.

So I did something like this

script: tv and dvr on
tv_on:
broadlink_blah blah
data: Jggggg on code for TV
dvr_on:
broadlink_blah
data: Jggyyyy on code for dvr

So, in your case, if you need to send the same code twice to start your device,
you might want to use script instead of switch…you can even put a slight delay between
commands if needed

I’m very apologize, but can someone explained me how should I wrote it? I don’t understand.
I read thread already and wrote this in automations.yaml:

   - id: temp for changing channel
      alias: change channel templ
      hide_entity: true
      trigger:
        - platform: state
          entity_id: input_select.tv_ir
      action:
        - service: broadlink.send_packet_192_168_11_99
          data_template:
            packet: >
              {% set channel = states('input_select.tv_ir') %}
              {% if channel == "first (1)" %}JgCMAJaSEzY
              {% elif channel == "second (2)" %}JgCMAJeRFD
              {% elif channel == "third(3)" %}JgCMAJeRFDs
              {% elif channel == "other" %}JgCMAJWTEjgSE
              {% elif channel == "OFF" %}JgDSAJeRFDYU
              {% endif %} 

but it doesn’t work. Although in log I didn’t see any error. I see something like this:

[homeassistant.core] Bus:Handling <Event call_service[L]: domain=broadlink, service=send_packet_192_168_11_99, service_data=packet=JgCMAJaSEzY, service_call_id=1100607280-10>

I’m not sure if you want to use Automations to setup channels.

What I did was set up my TV so that each number is a different TV station. This may or not be possible depending on you TV brand.

So for example, CNN is channel 350 for me, but rather than sending the IR code for [CATV] +[3]+[5}+[0], I first set up my TV tuner so that if press the [CATV] button + [6], it takes me to CNN. So I only have send two signal instead of four.

I also used scripts, so that I can add a half second delay between each signal. So my script kind of looks like this:

cnn:
alias: CNN
sequence:
- service: broadlink.send_packet_my_ipaddress
data:
packet:
- <IR code for the [CATV] button
delay: 0.5 sec
-<IR code for the [6] button

The advantage of doing this is that I only have to set define the IR code for the digits that I need to use and not for all [0] - [9]. But you’re set up may be different. The less IR code that you have to define in your YAML the easier.

Thank, I understand you.
I have a really old TV, for switch to some of the channels I must touch “-/–” button that could me to send two IR signals.

I want to use automation because I created input_select to choose channel.
Sorry, I didn’t write it early, I was angry.
Here it is:

input_select:
  tv_ir:
    name: TV remote
    options:
    - OFF
    - first (1)
    - second (2)
    - third(3)
    - other
    initial: OFF
    icon: mdi:television-box

And if I use script I would write a big script for all of the channels. I trying to understand how to write template to get it more shorter. home assistant documentation don’t explained it.