rule “Tvswitcher”
when
Item Channel_select changed
then
if (Channel_select.state == “NULL”) return; // If NULL do nothing
val topic = “broadlink/tvswicher/select/tv” + Channel_select.state
publish(“mosquitto”, topic, “play-0d43b4e42518”)
end
when i select one of the channels, i get this (for example channel 001)
broadlink/tvswicher/select/tv001
and i want it to send 3 command with the first, second and third number, like this
First things first, please use the code fences when publishing code, thanks
There are several solutions to your problem.
Solution 1: Use timers (Recommended)
var topic = "" //AT THE TOP OF THE RULES FILE!!
rule “Tvswitcher”
when
Item Channel_select changed
then
if (Channel_select.state == “NULL”) return; // If NULL do nothing
topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(0, 1)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
createTimer(now.plusSeconds(1), [ |
topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(1, 2)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
|]
createTimer(now.plusSeconds(2), [ |
topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(2)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
|]
end
If the string was longer we would use a loop through the string an increment the substring indexes when looping but as you only have 3 characters this should be enough and writing the loop will not save lines of code
When the rule executes it will send the find message straight away and create 2 timers to be executed 1 seconds after and 2 seconds after with the respective topics. Because the timers are execute outside the rule, we need to move the declaration of the topic variable to the top of the rules file and that it’s scope becomes global and can be accessed by the timers.
Solution 2: Use Thread::sleep (Not recommended)
rule “Tvswitcher”
when
Item Channel_select changed
then
if (Channel_select.state == “NULL”) return; // If NULL do nothing
var topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(0, 1)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
Thread::sleep(1)
topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(1, 2)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
Thread::sleep(1)
topic = “broadlink/tvswicher/select/tv” + Channel_select.state.toString.substring(2)
publish(“mosquitto”, topic, “play-0d43b4e42518”)
end
i ask the devloper to add macros, dont know if he will, but i love the gui where i can record and see all commands list, also can check fast and easy if i have problem with my commands
THat one above, the commands and macros are recorded as files, which makes them transferable…and with some conversion you can convert them to other broadlink formats (ie the broadlink binding)
when I press to activate a channel, that is to say, they change from one channel to another already predetermined
What I do is the following
My Rules
rule "FOX LIFE HD 1212"
when
Item TV1_Ch1212 received command ON
then
sendCommand(Uno_DirecTv, ON)
Thread::sleep(500)
sendCommand(Dos_DirecTv, ON)
Thread::sleep(500)
sendCommand(Uno_DirecTv, ON)
Thread::sleep(500)
sendCommand(Dos_DirecTv, ON)
Thread::sleep(500)
sendCommand(Enter_DirecTv, ON)
sendCommand(TV1_Ch1212 , OFF)
sendCommand(InfoCanal, "State")
end
rule "TNT SERIES HD 1213"
when
Item TV1_Ch1213 received command ON
then
sendCommand(Uno_DirecTv, ON)
Thread::sleep(500)
sendCommand(Dos_DirecTv, ON)
Thread::sleep(500)
sendCommand(Uno_DirecTv, ON)
Thread::sleep(500)
sendCommand(Tres_DirecTv, ON)
Thread::sleep(500)
sendCommand(Enter_DirecTv, ON)
sendCommand(TV1_Ch1213 , OFF)
sendCommand(InfoCanal, "State")
end
what he does in the rules is by emplo if the channel is “1114”
sendCommand (one_DirecTv, ON)
time 500
sendCommand (one_DirecTv, ON)
time 500
sendCommand (one_DirecTv, ON)
time 500
sendCommand (four_DirecTv, ON)
the problem is that there are more than 270 telvision channels, which has generated me a file with 270 rules over 4000 lines of code.
this works for me but the rules take more than 20 minutes to load
You’d be better to use groups to turn off all the old switches
There a way of figuring out what particular item of a group was activated…and from that you could pull the name ie TV1_Ch1212 and split it into the 1,2,1,2 for sending.
hello everyone good night I have made the following rule to control multiple television channels through broadlink,
I use DIRECTV and has declared approximately 40 television channels as Switch, when it is activated the code or channel number is sent to a rule which sends number by number to the broadlink
the problem is that the programming guide of my television is more than 200 TV channels for each television decoder or for each DIRECTV in my house I have 3 televisions and this generates a rule file of more than 9000 lines of code and 600 rules for each channel and that can make me independent of each of the 3 encoders
this works for me, the problem is that I have a rules file that is too large and when the raspberry restarts it takes approximately 45 minutes to load
this is my configuration
my Things
Bridge mqtt:broker:mosquitto [ host="192.168.0.30", port=1883, clientID="Domitic", secure=false]
{
Thing mqtt:topic:directvsala "DIRECTV SALA" {
Channels:
Type switch : Cero_DirecTv [ commandTopic="broadlink/televisor/saladirectv/cero", on="play-780f77b943fb"]
Type number : Uno_DirecTv [ commandTopic="broadlink/televisor/saladirectv/uno", on="play-780f77b943fb"]
Type number : Dos_DirecTv [ commandTopic="broadlink/televisor/saladirectv/dos", on="play-780f77b943fb"]
Type number : Tres_DirecTv [ commandTopic="broadlink/televisor/saladirectv/tres", on="play-780f77b943fb"]
Type number : Cuatro_DirecTv [ commandTopic="broadlink/televisor/saladirectv/cuatro", on="play-780f77b943fb"]
Type number : Cinco_DirecTv [ commandTopic="broadlink/televisor/saladirectv/cinco", on="play-780f77b943fb"]
Type number : Seis_DirecTv [ commandTopic="broadlink/televisor/saladirectv/seis", on="play-780f77b943fb"]
Type number : Siete_DirecTv [ commandTopic="broadlink/televisor/saladirectv/siete", on="play-780f77b943fb"]
Type number : Ocho_DirecTv [ commandTopic="broadlink/televisor/saladirectv/ocho", on="play-780f77b943fb"]
Type number : Nueve_DirecTv [ commandTopic="broadlink/televisor/saladirectv/nueve", on="play-780f77b943fb"]
}
}
I have seen an example in this community where they use toString.substring (0, 1) to create a single rule in which it receives the command in string and then separates it and sends data by command data but it has not worked for me
rule "SEND COMMAND ONLY ONE RULE"
when
Item Channel_select changed
then
if (Channel_select.state == "NULL") return; // If NULL do nothing
var topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(0, 1)
publish("mosquitto", topic, "play-780f77b943fb")
createTimer(now.plusSeconds(1)) [ |
topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(1, 2)
publish("mosquitto", topic, "play-780f77b943fb")
]
createTimer(now.plusSeconds(2)) [|
topic = "broadlink/televisor/saladirectv/" + Channel_select.state.toString.substring(2)
publish("mosquitto", topic, "play-780f77b943fb")
]
end
in this example I base myself to try to reduce my code but it didn’t work for me
I put my example of how I have configured everything …
to extract the chain I understand what you say and apply it but it did not work could you help me with just one example for a single channel
exposing the mqtt.things, rules, and Items for a single channel … I don’t know if it’s necessary but I’m using this broadlink integration in my system … https://github.com/fbacker/broadlink-mqtt-bridge
I don’t know if this has something to do if the way to receive the command is different