With the demise of ninjablocks, I had all these RF433 sensors that I wanted to make use of. Especially temperature sensors that use Manchester encoding, which the RCSwitch library cannot handle.
So I found RFLink online and was impressed that they had a large and growing number of protocols supported. The only thing is it assumes you are connected via USB to a computer that listens to its output and deals with it.
I have taken a slightly more agnostic approach to using the RFLink RF433 reciever/transmitter. Rather than trying to build a component in HASS to handle every possibility, I wanted to just have the data from the RFLink exposed on the MQTT broker and then HASS (or anything else) can decide what to do with it.
I have treated the RFLink as a black box - the people there have an excellent number of protocols supported including Manchester encoding (which you cant do with RCSwitch and I need for temperature sensors etc).
This little bridge connects to the arduino Mega running RFLink to a NodeMCU V1.0 via software serial. The NodeMCU (ESP8266) takes the output of the RFLink and converts it to a JSON payload in MQTT for consumption from anyone who has access ā¦ which in my case is HASS!
The ESP8266 is programmed using arduino IDE - the arduino file and relevant HASS yaml sections are includid in my github project.
The arduino code works but likely needs a little touching up.
Open to constructive comments.
Assumes you have the hardware - Arduino Mega 2560, RF433 RX/TX per RFLink requirements, NodeMCU ESP8266. If you have different hardware, you may need to tweak.
Nice. I designed my own mqtt rf gateway years ago and adapted it to HA when I started using it. In fact I dumbed it down because previous to HA it ran my whole automation. HA now does that but I am limited in codes and protocols and itās a pain to add new ones quickly. I also wrote an mqtt receiver for my Oregon Scientific v3 sensors to be able to use the data in HA but theyāre 2 separate units. I have seen the RFLink software but didnāt like the fact that itās serial. All mine are ethernet/mqtt. I like what youāre doing though and will follow closely. May be a nice replacement one day
EDIT: Saw your payloads. The other thing I did was to do most of the raw processing in the RF gateway and only pass basic data down to HA. That way I didnāt have to template in HA, rather do it in C in the Arduino and send clean data to HA sensors etc. Also I used really weird RF switches when I first started. They used a rolling code and couldnāt find anything to decode them so I modified RCSwitch and added my protocol. I nearly have replaced all of them with Sonoff switches now and almost use the gateway to receive mainly.
I am trying to keep the ESP work as light as possible so it does not miss another RF code coming in ā¦ And I am consciously leaving RFLink alone as a stock āblack boxā so that changes can be uploaded to the mega it runs on if you want those changes to protocols.
My arduino/MQTT temp sensors I already use do post a separate topic per reading (ie one for temp, one for hum), but given the array of data coming out of the RFLink, I decided to jump the shark and embrace JSON with the idea it might be more efficient to build a āblobā of data and post it in one. It also then keeps the data together in a time sense.
I have not bumped into rolling codes yet - hence my MQTT topic section being name-ID concatenated. Was trying to have a way for some persistence of MQTT messages for HAS digestion. Putting it all in a single branch per name would not work for me with 4 WT450 devices reporting temp/hum as different IDs of the same name.
The RFLink gets pretty busy when you have several chatty RF devices! I have a digitor weather station transmitting every 48 sec, plus 2-4 WT450 doing the same, plus 3 plant moisture monitors. I think it is why OTA refuses occasionally - because something distracts the ESP at a crucial point in the loading process.
Open to improvements ā¦ especially for sending commands to the RFLink for execution via callback in the code.
Oh I know. Thatās the other reason I wrote a separate weather sensor receiver. On windy days, the Oregon sensors go crazy, and if you add rain to that ā¦ WooHoo. When you have a dedicated weather station receiving the info itās fine because itās doing nothing else, but when itās an all-in-one receiver and transmitter and Doorbells, PIRās Smoke Detectors were going off as well as transmitting, there were times when it would miss events so decided to make them separate especially the Oregon that was doing all the Manchester stuff. 1 bit wrong and you get some weird results. Iād sometimes get wind gusts of 59Km/h and think WTF until I realized what was happening.
Again, great what your doing though. Will watch with anticipation
In theory you could port the code to a nodemcu. However the software from rflink is designed to be dropped on to an Arduino mega 2560.
I couldnāt work out how to change it, so I installed on the Arduino mega using their installer, attached the receiver, transmitter etc as per their instructions and then just added the nodemcu and my code to interpret the serial Comms from the rflink into the nodemcu and pass that on to mqtt.
So, for wiring etc, follow the rflink Instructions and it will work as a black box. Then just attach the Tx/Rx serial pins of the mega to the relevant pins on the nodemcu.
The advantage is you can load updates to the rflink system straight on to the Arduino mega if you stick to their recommended setup, which seems a more efficient way to go if you are after leveraging their development.
The exact pins to link the nodemcu to are in the instructions on my GitHub (donāt have at hand at the moment), but it is effectively only 2 wires between the Arduino mega setup and the nodemcu.
Iām trying to use you RFlink to MQTT with an ESP-12, but can you confirm that itās working the R46 ? In test mode or in normal mode I never received data in a topic.
I have looked at my downloads - looks like I am using R45 (and originally used R44)
I thought I checked their site the other day and noted that there was no new version - but looks like it has been there since March!
Will try and have a look tomorrow.
I cant think why it would not work due to version.
Have you had success with an earlier RFLink version?
Do you see codes via USB on your computer after flashing RFLink only on the mega (ie not havng the ESP in the mix)
Also watch out what pins you use for the serial link to the ESP ā¦ some are reserved for serial data etc so may cause clashes if you are trying to monitor via USB at the same time as using the soft serial link to the ESP. What kind of ESP-12 are you using? I have used a NodeMCU V1.0 board in my case.
Let me know if you solve it. I will try and upload the new version in my morning (about 8 hours from now)
I would like convert it to MQTT. So I remove usb cable, I use a 12v power on my RFLink. Connect the wires on 0,1 to D5,D6 and upload the sketch with updated SSID, password and mqtt host.
When I was in testing mode, Iāve tried to copy/paste some of your example in Arduino IDE Serial to ESP but there is no actions : 20;0D;UPM_Esic;ID=test;TEMP=00df;HUM=67;BAT=OK;
Also, check you are getting enough power to the esp. I have it powered by usb seperately to the Arduino in the first instance as I have had dropouts if the power source was not supplying enough to power both.
beware using multiple espās with the same firmware - you have to make their mqtt client id unique - which is why I added ātestā mode as I would test on an esp first before rolling it onto the āproductionā esp. If you have a second esp trying to connect to mqtt with the same id, it will be refused.
is 127.0.0.1 a valid mqtt server? I assume it is from the command line on the machine your mqtt server runs on? maybe try the address you would use from external. I tried equivalent to your command line and got no response either ā¦ but the HASS config below works!
The other āfeatureā of the arduino code is that a āmalformedā command will make it reset - hence adding the \n to the end to ācorrectā the package. So beware that you might be making the esp reset, then sending a ācorrectā command whilst it is still restoring from a reset sp it is being missed. (Maybe I should work for Microsoft or Apple with that subtle shift of blame for my poor coding to the user!)
so my HASS config for a wattsclever socket based upon the raw data collected is:
Have you ever transmitted successfully from the RFLink? did you try from their load tool to confirm transmit is working? I have an antenna on my receiver, but not on my transmitter, so sometimes range to the device to be controlled is an issue also.
I have many esp, and yes the client id is unique. 127.0.0.1 is ok my RPi, iām using 192.168.1.10 in the ESP config.
So at this point I make the same configuration as you.
My RFLink can transmit when connected via USB, this part is OK. But I think I canāt when iām using the TX Pin on the Arduino.
Iāve tried a minimal sketch on the Arduino to check both RX and TX Pins, and it works. So itās strange.
Iām quite sure the problem is now TX on the Arduino, I think I will check a R44 or R45 to see if I have the same behavior.
ā
Last news, I tried R44, R45,R46, same issue.
On the RFLink Loader, Iāve tried to send a command like 10;PING; it works.
Now Iāve tried esp-link. I can received code. When I send data I never get an answer.
So Iāve connected the MEGA to an UNO, link RX and TX between each other to be sure a 2nd time with another sketch. RX & TX are OK in both way. RX TX Check i use
Any ideas why Iāve got this problem? On Mega 0 is RX and 1 is TX
This problem is solved, I connect I CP1202 on RX/TX and I can send data.
But I still canāt with ESP. So I put my serial between TX ESP and RX Arduino.
So if I copy paste data from serial ESP to Arduino, itās ok.
But it doesnāt work directlyā¦
thx @phileep for all your help and your work, I finally have a working RFLink to MQTT.
I have clean flash on ESP and Arduino, re upload sketch, power the Arduino with 12v, used and ESP-12F (generic one) with 3.3v from Mega. Wirong has not changed.
I canāt say exactly why it works now, but it works and I have my first switch in HASS Next step, hass config for all my RF.