433mhz, infrared IR to and from MQTT on ESP8266

Hello,

Continuing my work on MQTT gateway with cheap component you can find below a tutorial to build a bidirectional one with IR transmitter, IR receiver, 433mhz emitter and 433mhz receiver.

You can integrate it with HA by using MQTT, more information on this topic

14 Likes

This is amazing. Well done!
I’ve been looking for ways to integrate IR and 433 into HASS. Quick question if you don’t mind, is it possible to state pulse length when transmitting 433, or the frequency burst of IR?

Thanks, for my understanding why do you want to change pulse length or frequency burst?

Hi I’d like to use this to control a 433 motorised projector screen.

I have the codes for ON and STOP

The screen takes 22 seconds to lower to a desired height.

Is it possible to use MQTT to 433 to send [code for ON] wait 22 seconds then send [code for STOP]

With one single command?

Thank you.

There is several ways to handle this:
-the best for me should have a sensor stop included into the projector screen directly, but as you are asking for this I suppose it is not the case
-a second way could be to handle it into HA, by setting up a timer when the switch pass to ON, and at the end of the timer pass the switch to OFF, as I’m not an HA expert I prefer to let the other answer
-a third way but the worst I think would be to handle it into the gateway source code by adding a condition and a timer when an ON signal is received

Only the first one is working with one single command at home automation level

Hi, thanks for doing this. I built this following your guide and is working very well at receiving commands and sending messages to HASS via MQTT but I have a problem which may be to do with pulse length and frequency burst but I’m not 100% certain. I originally follwed Bruh automations guide https://www.youtube.com/watch?v=5UUazFbK-Hg&t=132s to run this on the pi itself but changed over to your MQTT solution and I can’t get the plugs to switch on. I know its all working fine as I also have my wireless rf doorbell connected and this works via the mosquitto_pub command, the doorbell rings but the switches do not switch at all - do you have any ideas? The only things I can think of is the pulse length all the switches were at 186 and the doorbell is 321 using Bens guide.

Hi 1technophile it was the pulse length. I added mySwitch.setPulseLength(186);
to the line above mySwitch.send(data, 24); in your code and its working great and the doorbell works too. Loving your work, thanks!

Great, thanks for sharing the info

I’m using just the IR parts (have RF running nice on pi). I have captured all the codes for remotes but I’m not sure on my next step.
I have a mosquitto broker running fine but not sure about topics. I want to take these codes and have them in HA as switches and have them controllable through my Echo. Is this possible?

I already have 5 rf sockets working with Hue emulation, will I be able to to the same with mqtt commands as switches?

hello,

Once you captured your code you can try to emit them by publishing the following MQTT topic into mosquitto:
mosquitto_pub -t home/commands/sendNEC -m 99999999
99999999 = the captured code value

If it is working the next step is the HA integration.
Here are some example that you have to adapt to the IR topic

1 Like

Hi 1technophile,

while already having a MQTT broker running on HA (simple DHT22 on a nodemcu dev board), I liked your solution and tried it on a similar module as the geekcreit (doit.am with 12F) to get 433 MHz sockets into HA.
The RF RX/Tx modules are standard ones: MX-RM-5V (MX-05V)/FS1000A, but I couldn’t get it to work.
When I publish a command “1315156” on topic “home/commands/rf” through MQTT Spy, I get a callback (reproducable).

Do you have any idea what I might be doing wrong here?

.
WiFi connected
client mqtt not connected, trying to connect
Attempting MQTT connection…
connected
subscription OK to
home/commands/#
Hey I got a callback

Exception (2):
epc1=0x3ffe87c4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x3ffe87c4 depc=0x00000000

ctx: cont
sp: 3fff00a0 end: 3fff04a0 offset: 01a0

stack>>>
3fff0240: 401003b8 00000030 00000013 ffffffff
3fff0250: 40100537 3fff0f58 3fff0f58 01520000
3fff0260: 00000152 000000a5 ff000000 00363531
3fff0270: 00000021 3fff1670 00000000 3ffef420
3fff0280: 00000a68 00000010 3ffeef14 00000030
3fff0290: 40100537 00000004 3fff02f0 3fff0301
3fff02a0: 401072e8 00000000 3fff15e3 00000010
3fff02b0: 3ffeef14 3fff1670 000000a5 3ffef420
3fff02c0: 00000988 00000000 00000000 3fff0250
3fff02d0: ffffffff 00000020 00000001 00000000
3fff02e0: 3fff0300 3fff02f0 00000004 00000022
3fff02f0: 3fffc200 3ffe88d4 3fff15e3 00000000
3fff0300: 000000a5 ff000000 00000013 ffffffff
3fff0310: 40203e98 3ffeef90 3ffeef03 4010031d
3fff0320: 00000007 000010e0 3ffef420 40100426
3fff0330: 0000002c 00000001 3ffe8a55 40100537
3fff0340: 00000020 00000007 00000010 401006c2
3fff0350: 3ffeef03 00000015 3fff03d4 40206aaa
3fff0360: 3fff15dc 00000007 3fff03d4 40206b02
3fff0370: 3ffef420 0000022c 3fff03d4 40206b32
3fff0380: 3ffeef03 3fff15e3 3fff03d4 40206b80
3fff0390: 3fff15dc 00000007 00000013 401006d8
3fff03a0: 3ffe8a54 0000000f 3fff15dc 40202911
3fff03b0: 00000000 00000000 00000000 00000002
3fff03c0: 00000016 3ffeeefc 00000019 40203919
3fff03d0: 3f36001b 00000000 00000000 00000000
3fff03e0: 3fff0410 00000001 00000010 00000001
3fff03f0: 00000010 00001d5f 3ffeeefc 402056e4
3fff0400: 3ffeeefc 00001d5f 3ffeeefc 40203e98
3fff0410: 3ffef301 40105c27 3ffef480 3ffef380
3fff0420: 00000004 3ffeeeff 0000001b 3ffef480
3fff0430: 4020152a 00000064 00000064 3ffef46c
3fff0440: 3ffeeefc 00000001 3ffef465 40202a94
3fff0450: 00000000 00000000 00000000 3ffef480
3fff0460: 402047cf 3ffef1b4 000005dc 402040c4
3fff0470: 00000000 00000000 00000001 40205581
3fff0480: 3fffdad0 00000000 3ffef465 402055ac
3fff0490: feefeffe feefeffe 3ffef480 40100958
<<<stack<<<

Hello,

Is it a nodemcu board? If yes could you indicate me the version? I had a similar bug with 0.9 version of nodemcu.
Maybe you have a link that refer your board.

Please check also that you are running the latest library versions.

@1technophile i would like to buy a nodemcu at aliexpress but how i knows if the board is 0.9 version? I dont want problems.

I just checked back at the order (Oct-2016), it’s the geekcreit as well:

It says “ESP12E DEVKIT V2” on the back but has an 12F already installed.

The nodemcu FW is from today:

NodeMCU custom build by frightanic.com
branch: dev
commit: 7c9fdef77a89be76d4dfc1a15c4c94ad17a34f7c
SSL: false
modules: dht,file,gpio,mqtt,net,node,rfswitch,tmr,uart,wifi
build built on: 2016-12-25 20:41
powered by Lua 5.1.4 on SDK 2.0.0(656edbf)

The libs are:

ESP8266WiFi.h - 1.0.0
PubSubClient.h - 2.6.0
RCSwitch.h - 2.6.2
IRremoteESP8266.h - 1.0.0

RCSwitch.h - 2.6.0 was installed and didn’t update yesterday, so I removed it to make sure 2.6.2 is used and compiled/uploaded the ino again (on IDE 1.6.12), same result (callback) after a submitted rf command via mqtt.

What is the exact requirement of the Nodemcu 1.0 board? How can i obtain the version (I thought it’s a 1.0 but I don’t know how to check it)?

I think we have the same board, this doesn’t seem to be a board compatibility issue, i ordered it also from banggood.

Some other questions:
-did you used the same pins as described
-could you add some trace to the code after the “hey i got a callback” to see exactly where it stop.

Pins are exactly the same used.
I also connected an IR Rx to check the IR-to-MQTT reception, beside the garbage codes posted, this works as expected.

Back to the traces, I added the following:

// Callback function, when the gateway receive an MQTT value on the topics subscribed this function is called
void callback(char* topic, byte* payload, unsigned int length) {
  // In order to republish this payload, a copy must be made
  // as the orignal payload buffer will be overwritten whilst
  // constructing the PUBLISH packet.
  trc("Hey I got a callback ");
  // Allocate the correct amount of memory for the payload copy
  byte* p = (byte*)malloc(length);
  trc("malloc");
  // Copy the payload to the new buffer
  memcpy(p,payload,length);
  trc("memcpy");
  // Conversion to a printable string
  p[length] = '\0';
  trc("conv");
  String callbackstring = String((char *) p);
  String topicNameRec = String((char*) topic);
  //launch the function to treat received data
  receivingMQTT(topicNameRec,callbackstring);

  // Free the memory
  free(p);
}

and get the following:

…
Hey I got a callback
malloc
memcpy

Exception (2):
epc1=0x3ffe87e4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x3ffe87e4 depc=0x00000000

ctx: cont
sp: 3fff00c0 end: 3fff04c0 offset: 01a0

stack>>>
3fff0260: 40100543 00000030 00000010 fff…

Could you try:
-to add this piece of code before p[length] = ‘\0’;
trc(String(length));
-to put a value of signal shorter like 99, or 6666
-try with mosquitto instead of MQTT Spy

hello, the board from banggood with the link provided by prefectionist is working, nevertheless as it is written on the spec esp 12E and in reality it is a 12F it is difficult to be sure that you will receive the same as us.

Even with:

mosquitto_pub -u <removed> -P <removed> -t home/commands/rf -m 1315156

I get the exception (string length included now):

…client.loop
Hey I got a callback
malloc
memcpy
7

Exception (2):
epc1=0x3ffe87e4 epc2=0x00000000 epc3=0x00000000 excvaddr=0x3ffe87e4 depc=0x00000000

ctx: cont
sp: 3fff00c0 end: 3fff04c0 offset: 01a0

stack>>>
3fff0260: ffffffff 00000020 3ffeef34 00…

Message payloads of “99” or “6666” produce the same result, just the string length changes to 2 and 4.

The only “custom” setup in my mosquitto broker is the “allow_anonymous false” along with a password file.
I am running out of ideas what might be so specific to my setup.
I also changed the FS1000A with the second one I ordered, same result.

Just for completion, here is the IDE setup.

Yeah me to, and i don’t have my dev env to test some tracks, could you try to change the compilation options (boards and flash sizes)