Control openhab functions via IR (NOT VICE VERSA)

You could use the Linux input binding and Flirc USB

I’m doing what you have asked about with a d1 mini flashed with tasmota and an IR eye that is used to plug into an IR blaster. You can buy the eye alone from Amazon for less than $10. I’m using MQTT as the protocol. Tasmota has a sketch in the standard .bin for this and I just picked and old remote and watched the console when pressing various buttons. Then I use the console output as my CMD line in MQTT on openhab. Happy to share some more info if anyone would find it useful.

Hi there :slight_smile:
I have now a working Tasmota IR Receiver, and I can see the codes I send from my Logitech Harmony in the tasmota console. Those messages are in this form :

{“Time”:“2023-02-20T11:23:40”,“IrReceived”:{“Protocol”:“NEC”,“Bits”:32,“Data”:“0x00FF00FF”}}

Now: How can I link this message to an already existing switch so when this string is received the switch changes state from OFF to ON or vice versa?

Thank you :slight_smile:

  1. Install MQTT - Bindings | openHAB.
  2. Add bridge.
  3. Read MQTT Things and Channels - Bindings | openHAB.
  4. Add Generic MQTT Thing (name it ‘Tasmota IR Receiver’).
  5. Add string channel command received to Thing.
  6. Configure channel: use JSONPATH to extract 0x00FF00FF from message.
  7. Link item to channel.
  8. Create an openHAB rule that converts 0x00FF00FF to whatever you are going to accomplish by using the item as input for the rule.

Hi Ap15e, thanks for answering me. A quick update :

1-2 ok Binding installed, bridge Mosquitto running on QNAP/container station. Connection ok. Tasmota device connected to Mosquitto (i guess…there’s no way for me to tell if everything’s fine since I have 0 experience with MQTT)

3 It’s extremely confusing. And has no reference to my specific needs.

4 done!

5 can this channel be used to receive different IR codes for different switches? I should send 4 different IR codes to 4 different switches. I should extract other information as well from the data received via IR, since many codes are received via Tasmota and I must pass “Protocol” and “Bits” as well if I wanna be sure not to trigger any unwanted action.
I have no idea about how to do this from this point forward :slight_smile:
Thanks for your kind help :slight_smile:

5 Yes.

My setup for a cheap 433 Mhz 4 button ON/OFF remote:

Channel (Button = command received)

You would have to use advanced settings (tick ‘Show advanced’):

Something like $.IrReceived.Data will transfer the hexadecimal data to your channel.

Setup a rule:

grafik

It might be possible to use $.IrReceived instead of $.IrReceived.Data to catch all three dimensions of the IR command. Of course, you would have to adjust the Command in the rule trigger accordingly.

Thank you for your quick answers Ap15e, but I think I need to give you some more context to understand the problem I have.

  1. I have an extremely basic knowledge of OpenHab, and NO knowledge at all about MQTT
  2. I suppose OpenHab and Mosquitto are able to communicate since OpenHab says the broker is online and “greenlit” in the things list, but I have no clue if the Tasmota device and the MQTT broker are actually communicating. Tasmota has no logs on its small website telling me if something went wrong with MQTT, and I have no idea about how to check the communication between Tasmota and the broker from the broker console itself using mosquitto_sub (I tried but got nothing out of it)
  3. this is the situation: i have 4 lights in my home theatre, all of them connected to my BTicino MyHome home automation. The “openwebnet” binding in OpenHab is configured and working as intended, all my items and things are correctly configured using configuration files (in items, things and sitemaps).
  4. In my Logitech Harmony Remote I have programmed a device using these 4 codes : “NEC”,“Bits”:32,“Data”:“0x00FF00FF” for light 1, “NEC”,“Bits”:32,“Data”:“0x00FF40BF” for light 2, “NEC”,“Bits”:32,“Data”:“0x00FFA05F” for number 3 and finally “NEC”,“Bits”:32,“Data”:“0x00FF609F” for the fourth light.
    I have checked, pointing the remote towards the Tasmota IR Receiver I see the codes appearing in the console when I push the buttons (but I have no idea about the MQTT broker).
  5. I need to link the 4 commands received from the remote to the aforementioned 4 light switches to turn those on and off using my Logitech Harmony.
    I hope I have given you more infos to work on :slight_smile:
    Thank you again for your kind help, I hope I described the situation clearly but I am not an English native speaker and explaining technical problems in a language different than mine it’s a challenge all by itself :slight_smile:

Thank you again !

ad 2) Try the MQTT-Explorer . This tool will let you see which changes happen on the MQTT side by subscribing to topics on mosquitto. Makes live much easier.

Just for the record that many roads lead to Rome:
I’m doing something similar in a somehow exotic way.
There is a (discontinued) IR receiver from Siemens, that is connected to my knx bus. The IR receiver is supported by the Harmony remote and capable of receiving multiple IR codes. Through the knx bus I trigger switching on my subwoofer. As OH is connected to knx as well I’m able to switch channels on e.g. EnOcean or ModBus. Life finds a way :wink:

Yes! this helped me ! The software you linked allowed me to check that Tasmota is in fact sending data to the MQTT Broker. I see my device in the list as tasmota_AA0EEC and from there the messages sent by the device itself. Now I am a step closer. I just have to figure out :

  1. how to format correctly the string for the receiver in OpenHab
  2. how to create that rule to change the switch status based on the IR codes received :slight_smile:

…and Ian Malcolm seems to find a way in this topic as well :slight_smile: welcome to Jurassic Park then !

grafik

translates to MQTT topic sensors/rtl_433/P3/I171; to get the temperature use $.temperature_C as JSONPATH transformation.

Edit:
ad 2: Rules - Basic | openHAB

So how do I use this ? The channel is a string right?
topic : tele/tasmota_AA0EEC/RESULT
and to get those parameters I have to set in JSONPATH $.Protocol,$.Bits,$.Data
and then set a rule that evaluates data from Protocol Bits and Data ?
Or I am missing something ? :slight_smile:
Thank you all for your kind help :slight_smile:

The type of your channel is String.

Your topic looks fine. Use it to set the State Topic of your channel:

Let’s keep it simple for now and use JSONPATH:$.IrReceived.Data as Incoming Value Transformation:

grafik

Then link an item to your channel and test the item. Then create an openHAB rule to link your IR codes to whatever you are going to accomplish, see Control openhab functions via IR (NOT VICE VERSA) - #11 by Ap15e.

:frowning: hen I try to link the channel to an existing item, I can select the parent thing but once I do that, no channel is displayed to select :frowning:

Create a new item:

Press buttons on your remotes, the new item should reflect the data part of the MQTT messages.

Make sure that
grafik
is installed.

To capture all three dimensions (protocol type, bit length, data) install RegEx transformation
grafik

and use the following Incoming Value Transformation (untested - it might be necessary to escape some characters …):

REGEX:s/.*ol":"(.*)","Bits":(.*),"Data":"(.*)"}}/$1_$2_$3/g

to get

NEC_32_0x00FF00FF instead of 0x00FF00FF.

Explanation:

I did this by creating a tasmota rule on the d1 itself through tasmota web console. When I get to my computer next I can send the rule I use so you can change it to your needs.

The rule essentially acts as follows:

  • I use the DATA from your string mentioned above and have that publish an MQTT message that toggles another MQTT device of my choosing. For example: cmnd/Lamp-1/POWER TOGGLE
  • So now that I think of it, this solution is openhab agnostic (except that my pi with openhab is running my MQTT broker) and is more along the lines of device to device via MQTT.

The Tasmota Rule:

ON IrReceived#Data=0xA2AD807F DO publish cmnd/LR-Lamp-1/POWER TOGGLE ENDON

Replace your data string after “IrReceived#Data=” and replace everything between “publish” and “ENDON” with whatever MQTT message you want to publish.

Then I believe since your devices you are trying to control are not MQTT devices you could use openhab MQTT binding and rule to control your device. This is where the MQTT message you create in tasmota would be used.

UPDATE: I have solved a couple problems thanks to you.

  1. I now have a working connection between OpenHab and the broker, and a working tasmota thing reading the correct status. I have created a channel inside that thing, and a “fake item” showing the string of text I receive from tasmota. This is what I see now when I trigger a command on my Logitech Harmony:

so as you can see now I have my output string there.
2) I have found why I couldn’t add any channel to the existing items. It was due to the fact that the “openwebnet” items were coded in a .items file, so the only way I could add the channel from tasmota was to add it into the configuration file and now

Now only 2 problems remain:

  1. do I have to set the rules in a .rules file since all my configurations for “openwebnet” is done through text files or I can create it via wizard from the administration interface?
  2. I’d like to use the same IR command to trigger ON/OFF to avoid code and button duplication. Can I do that in the rule ? I have no experience at all about rule writing so I’m 100% blind :slight_smile:

Thank you for all your contributions helping me getting to this point !

UPDATE: I got a rule working to turn ON the lights (but I have no idea how to switch them off using the same command to update the status :slight_smile: getting closer!! )
UPDATE 2: the rule works only once, because it operates on the change of the string iIRTasmStatus, but that string stays the same, buffered until I send a different command and clean up the string. I should “reset” that state from the rule as soon as I have applied the correct command.
It should work something like this : IR command received → action toggle switch from ON to OFF or vice versa depending on the state → set the string state to NULL and wait for another command. This is the ideal scenario, I have no idea if I can implement it like that…
UPDATE 3: I added an action to change the item state to NULL after executing a command. But now I have to solve the problem of switching from ON to OFF since the rule allows me to set either ON or OFF but not toggle between them.

Is it possible to toggle a switch without changing item definition, for example through a script like
" if itemLight1 state is ON then set itemLight1 state to OFF else set itemLight1 state to ON " and trigger the script instead of sending a command to the switch directly? (I know I can fire up a script from the rule, but I have no idea about how to write a script like the one I have sketched here)

I’m almost there I know!!
Thank you all for your help!!

PROBLEM SOLVED !!
I have created a script inside the rule like this

type: application/javascript
script: |-
if (itemRegistry.getItem(‘iP2_Vetrine’).getState() == ‘ON’)
{
events.sendCommand(‘iP2_Vetrine’,‘OFF’)
}
else events.sendCommand(‘iP2_Vetrine’,‘ON’)
type: script.ScriptAction

Using this snippet 4 times in 4 different rules, parsing the corresponding IR codes from Tasmota, now I am able to turn my lights on and off using a Harmony Remote ! Cheer up !!!
Thanks everybody for your precious help and patience in helping me solve this problem !!
:blush:

2 Likes