IR OPENHAB (help finding a decent guide)

Hi everyone

Could someone point me in the direction of a simple sketch for ESP8266 nodemcu board that allows openhab too send and receive ir remote commands over wifi

I have been trying too follow a guide all day for a mqtt ir blaster

Its been causing me nothing but trouble errors from the IDE i think most of them are due too librarys changing since this sketch was written 3 years ago i have managed too get most of them sorted but i still get errors being inexperienced using the IDE etc is not helping here

Looking for a tried and tested method or some pointers in the best direction

TIA

Would be interesting what kind of errors the IDE throws.
are you using the arduino IDE or platform.io?

The required libraries (webserver, MQTT, …) are the ones i’m using as well, so there shouldn’t be an issue with them. Maybe it’s one of the IR libs?

1 Like

currently im getting these errors

Arduino: 1.8.15 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:3MB OTA:~512KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"





















C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:41:20: warning: 'BUILTIN_LED' is deprecated: use LED_BUILTIN [-Wdeprecated-declarations]

   41 | const int ledpin = BUILTIN_LED;                               // Built in LED defined for WEMOS people

      |                    ^~~~~~~~~~~

In file included from C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\variants\nodemcu/pins_arduino.h:52,

                 from C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/Arduino.h:295,

                 from sketch\mqttirblaster.ino.cpp:1:

c:\users\admin\appdata\local\arduino15\packages\esp8266\hardware\esp8266\3.0.2\variants\generic\common.h:79:11: note: declared here

   79 | const int BUILTIN_LED __attribute__((deprecated("use LED_BUILTIN"), weak)) = LED_BUILTIN;

      |           ^~~~~~~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino: In function 'void lostWifiCallback(const WiFiEventStationModeDisconnected&)':

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:354:64: warning: unused parameter 'evt' [-Wunused-parameter]

  354 | void lostWifiCallback (const WiFiEventStationModeDisconnected& evt) {

      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino: In function 'bool setupWifi(bool)':

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:386:7: warning: 'SPIFFS' is deprecated: SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems. [-Wdeprecated-declarations]

  386 |   if (SPIFFS.begin()) {

      |       ^~~~~~

In file included from C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1:

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/FS.h:275:15: note: declared here

  275 | extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));

      |               ^~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:388:9: warning: 'SPIFFS' is deprecated: SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems. [-Wdeprecated-declarations]

  388 |     if (SPIFFS.exists("/config.json")) {

      |         ^~~~~~

In file included from C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1:

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/FS.h:275:15: note: declared here

  275 | extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));

      |               ^~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:391:25: warning: 'SPIFFS' is deprecated: SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems. [-Wdeprecated-declarations]

  391 |       File configFile = SPIFFS.open("/config.json", "r");

      |                         ^~~~~~

In file included from C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1:

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/FS.h:275:15: note: declared here

  275 | extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));

      |               ^~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:510:23: warning: 'SPIFFS' is deprecated: SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems. [-Wdeprecated-declarations]

  510 |     File configFile = SPIFFS.open("/config.json", "w");

      |                       ^~~~~~

In file included from C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1:

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2\cores\esp8266/FS.h:275:15: note: declared here

  275 | extern fs::FS SPIFFS __attribute__((deprecated("SPIFFS has been deprecated. Please consider moving to LittleFS or other filesystems.")));

      |               ^~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino: In function 'String blastJson(ArduinoJson::JsonArray&, int)':

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:829:21: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'unsigned int'} [-Wsign-compare]

  829 |   for (int x = 0; x < root.size(); x++) {

      |                   ~~^~~~~~~~~~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino: In function 'void mqtt_calback(char*, byte*, unsigned int)':

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1609:25: warning: unused parameter 'topic' [-Wunused-parameter]

 1609 | void mqtt_calback(char* topic, byte * payload, unsigned int length) {

      |                   ~~~~~~^~~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:1609:61: warning: unused parameter 'length' [-Wunused-parameter]

 1609 | void mqtt_calback(char* topic, byte * payload, unsigned int length) {

      |                                                ~~~~~~~~~~~~~^~~~~~

In file included from C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:21,

                 from C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:10,

                 from C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino:11:

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp: In static member function 'static void ArduinoJson::Internals::JsonSerializer<Writer>::serialize(const ArduinoJson::JsonVariant&, Writer&) [with Writer = ArduinoJson::Internals::JsonWriter<HardwareSerial>]':

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:93:22: warning: this statement may fall through [-Wimplicit-fallthrough=]

   93 |       writer.writeRaw('-');

      |       ~~~~~~~~~~~~~~~^~~~~

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:94:5: note: here

   94 |     case JSON_POSITIVE_INTEGER:

      |     ^~~~

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp: In static member function 'static void ArduinoJson::Internals::JsonSerializer<Writer>::serialize(const ArduinoJson::JsonVariant&, Writer&) [with Writer = ArduinoJson::Internals::JsonWriter<fs::File>]':

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:93:22: warning: this statement may fall through [-Wimplicit-fallthrough=]

   93 |       writer.writeRaw('-');

      |       ~~~~~~~~~~~~~~~^~~~~

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:94:5: note: here

   94 |     case JSON_POSITIVE_INTEGER:

      |     ^~~~

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp: In static member function 'static void ArduinoJson::Internals::JsonSerializer<Writer>::serialize(const ArduinoJson::JsonVariant&, Writer&) [with Writer = ArduinoJson::Internals::JsonWriter<ArduinoJson::Internals::DynamicStringBuilder<String> >]':

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:93:22: warning: this statement may fall through [-Wimplicit-fallthrough=]

   93 |       writer.writeRaw('-');

      |       ~~~~~~~~~~~~~~~^~~~~

C:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Serialization/JsonSerializerImpl.hpp:94:5: note: here

   94 |     case JSON_POSITIVE_INTEGER:

      |     ^~~~

C:\Users\Admin\Documents\Arduino\mqttirblaster\mqttirblaster.ino: In function 'int rokuCommand(String, String, int, int)':

mqttirblaster:899:15: error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

  899 |     http.begin(url);

      |     ~~~~~~~~~~^~~~~

exit status 1

call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

OK, it really seems that there are old deprecated libraries used. But in order to get it running, you can ignore the warnings and should look onto the error messages:


But, to be honest, i’m not sure if searching for something else like that would be more efficient: GitHub - piotrC4/mqtt-ir-transceiver: ESP8266 based bidirectional bridge between MQTT and IR (change MQTT message to IR signal and change received IR signal to MQTT message)

1 Like

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.

1 Like

Another option is to purchase a broadlink rm4 pro or the smaller and cheaper model that only does IR and not RF. Binding is available and going through review at the moment and the hardware is cheap, granted it is not as cheap as a esp8266.

this is one of the first projects i looked into when starting but needed too use platformIO not too sure about that gave it ago today also getting errors for the build process

easy things are sometimes the hardest :frowning:

i have finally got this working just need too work out how too publish the mqtt message too the device and all done this is my first time using mqtt also been alot of new bits here

Would make a good write up in the forum if your willing to do it and a guess as to the time to get it working if you follow such a guide. Even a general how to with some advice is always good to read.

I used to be more into the diy approach but now only go that way if it is cheaper when time is factored in or if it gives more features to make the time cost worth it. Sometimes the better feature is better security as it is open source coding.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.