Personally I use Tasmota for this. Tasmota does the Wifi configuration, has a web interface, MQTT interface and I have a dozen other devices which also run Tasmota.
A UI rule for receiving an IR command from a Tasmota device looks like this (Note that I don’t use an MQTT trigger channel, instead I store the info received from Tasmota in a String item):
triggers:
- id: "1"
configuration:
itemName: Wifiremote01_ReceivedIRcommand
type: core.ItemStateUpdateTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/vnd.openhab.dsl.rule
script: >
// Example1: Wifiremote01_irrecv.state.toString == "{\"IrReceived\":{\"Protocol\":\"SONY\",\"Bits\":12,\"Data\":\"0x750\",\"DataLSB\":\"0xE00A\",\"Repeat\":0}}"
// Example2: Wifiremote01_irrecv.state.toString == '{"IrReceived":{"Protocol":"PANASONIC","Bits":48,"Data":"0x400401007C7D","DataLSB":"0x022080003EBE","Repeat":0}}'
val String json = Wifiremote01_ReceivedIRcommand.state.toString
val String proto = transform("JSONPATH", "$.IrReceived.Protocol", json)
val String data = transform("JSONPATH", "$.IrReceived.Data", json)
val String datalsb = transform("JSONPATH", "$.IrReceived.DataLSB", json)
//logInfo("irsend.rules", "proto: " + proto + " data: " + data + " datalsb:" + datalsb)
if (proto == "PANASONIC" && data == "0x400401007C7D") {
//logInfo("irsend.rules", "MythTV switched ON")
NetworkPingMythTV_Online.sendCommand(ON)
}
type: script.ScriptAction
The rule is triggered when the item Wifiremote01_ReceivedIRcommand
changes. The rule the extracts the protocol and the data from the json string. If both protocol and data match a pattern (currently I only receive one command), the command NetworkPingMythTV_Online
is sent, which triggers another rule.
Sending an IR command to a Tasmota device is done by sending a JSON string to an item that is connected to the IR command mqtt channel of the Tasmota thing (my item is called Wifiremote01_irsend
). Then in a rule use the command
sendCommand(Wifiremote01_irsend,"{'Protocol':'PANASONIC','Bits':48,'Data':'0x400401007C7D'}")
Note this is all in “Rules DSL” language, but is equally possible using Javascript.