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.
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 …
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 …
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:
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.
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)
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.
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:
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 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.
You can still use automation, but you should use it with the script.yaml. All you need to do is give you script an alias like “channel 11”, and use it to populate you input select list. Its the best way to send multiple IR signals simultaneously to a single device IMO