Accéder au contenu principal

Infrared IR, 433mhz and MQTT on ESP8266 bidirectional gateway OpenMQTTGateway

Following discussions on the home assistant forum people gave me the idea to add Infrared communication to the 433mhz gateway. 

The goal is to act as a gateway between 433Mhz sensors, infrared remote controls and a MQTT broker or between the MQTT broker and 433Mhz actuators, infrared devices, It enables to:
  • receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data 
  • publish MQTT data to a different topic related to received 433Mhz signal 
  • receive MQTT data from a topic and send infrared signal corresponding to the received MQTT data 
  • publish MQTT data to a different topic related to received infrared signal 

It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets), your tv, home cinema, hifi ... with software like openhab or home assistant.


List of compatible RF sensors here

[EDIT] all infos are now centralized into the github repository take a look at it you will find up to date info about OpenMQTTGateway

You need:

Software:
  • Mosquitto
  • Arduino IDE latest version (tested ok with 1.6.10)
  • esp8266 board added to the arduino IDE board manager version >= 2.3.0
  • OpenMQTTGateway
Hardware (here is a list of compatible parts)
433mhz Transmitter signal to pin D2, 433mhz Receiver signal to pin D1, transistor to pin D5, IR receiver to pin D4
Here is the schematic:




If you want to increase the range of the receiver XD RF 5V plug its vcc directly to a 5V power supply like on the schema below and not to Vin of your nodemcu, it will considerably increase the range. In this case I disconnect the usb cable as I don't know if the nodemcu can handle the both source of power.





Some pictures:






Download the following libraries from your arduino environment:
Install Mosquitto to your server.

Download the code of the gateway , the wiki contains this tutorial and all the updated infos


Upload the sketch to your ESP8266 and open the serial monitor with a speed set to 9600b.
Launch or verify that you mosquitto broker is up and running

If the connexion to mosquitto is ok you should see on the serial monitor of the arduino "connected" & "subscription OK to home/commands/#"
Now you can do some tests to verify that all is working as expected, here is some usefull commands to test gateway with mosquitto from the server, on your mosquitto server:
  • Subscribe to the # subject so as to check the data received eitherr by RF either by IR
mosquitto_sub -t home/# -v

Testing the RF gateway

  • Send data by MQTT to convert it on RF signal 
mosquitto_pub -t home/MQTTto433/ -m 1315156

Arduino IDE serial data received when publishing data by MQTT


We see that the Arduino receive the value 1315156 on the MQTT subject "MQTTto433" and send the data by RF


Arduino IDE serial data received when receiving data by 433Mhz




MQTT subject follow from command line:

pi@raspberrypi ~ $ sudo mosquitto_sub -t home/# -v
home/433toMQTT 1312084
home/433toMQTT 1312095

Testing the IR infrared gateway

If you already subscribed to 
mosquitto_sub -t home/# -v
And press your IR remote control in front of the receiver led you should see the following message for example:

home/sensors/ir 3609272523



You can take this code and try to reproduce it with the gateway. With the IR gateway you need to put on the topic the protocol you want to use to send the signal, the different protocols implemented are the following, the MQTT subject is between "":

subjectMQTTtoIRLG "home/commands/IR_LG"
subjectMQTTtoIRSony "home/commands/IR_Sony"
subjectMQTTtoIRCOOLIX "home/commands/IR_COOLIX"
subjectMQTTtoIRWhynter "home/commands/IR_Whynter"
subjectMQTTtoIRNEC "home/commands/IR_NEC"
subjectMQTTtoIRDISH "home/commands/IR_DISH"
subjectMQTTtoIRSharp "home/commands/IR_Sharp"
subjectMQTTtoIRPanasonic "home/commands/IR_Panasonic"
subjectMQTTtoIRSAMSUNG "home/commands/IR_SAMSUNG"

For example if I want to send a command to a sony TV you can use the following command:

mosquitto_pub -t home/commands/IR_Sony -m 
3609272523

The code after the -m represent the value you want to send.

Enjoy!




Commentaires

  1. Would it be possible to base this on the RFLink Gateway firmware instead as it have support for many more devices? See http://www.nemcon.nl/blog2/easyha

    RépondreSupprimer
    Réponses
    1. Hello, the last version of the RFlink is not anymore opensource unfortunately but I'm agree with you if we add to a MQTT gateway the RFlink protocols list it would be awesome

      Supprimer
  2. Stumbled upon this and have to say that this bridge project could be a good business idea for Kickstarter/Indiegogo:
    If someone would just steal that concept and make it into cheap enough nicely boxed appliance product that only acted as a “IR and 315/433 MHz to WiFi + MQTT Bridge ” then I think that alone could sell pretty well in some home automation niche markets.
    “315 MHz /433 MHz and InfraRed to MQTT WiFi Bridge”
    Reason for that is I really believe there is a commercial market for a such specific “315 MHz /433 MHz and InfraRed to MQTT WiFi Bridge” product because most existing commercial home automation hubs do not feature 315/433 MHz or InfraRed receivers or transmitters, but as most existing commercial home automation hubs does support MQTT there is a large potential market for customers who don’t want to use expensive ZigBee and Z-Wave sensors.
    To keep cost down you would make and sell one 315 MHz model for North America and one 433 MHz model for Europe and Asia. So one model that is; “315 MHz and InfraRed to MQTT WiFi Bridge” and one model that is “433 MHz and InfraRed to MQTT WiFi Bridge”, and possibly you could also make a third product model that is a 868MHz bride; “868 MHz and InfraRed to MQTT WiFi Bridge”.
    As listed there all that you really need as far as hardware components goes is a ESP8266 or ESP32 chip, InfraRed and 315 or 433 MHz transmitters, and InfraRed and 315 or 433 MHz receivers. The source code for protocols and more could be copied from other firmware project (and shared with that project) as long as you keep it open source under the same license. Regardless it would be a good idea to make the whole firmware open source as then you have the possibility of getting help with the code from the community, and open source projects also often get more passionate communities than those who keep their code proprietary and closed.
    You could possibly make cheaper by making a receiver only model as a “lite” version, but personally I don’t think there would be a large enough market for a such stripped down version to make it worth the little extra cost that a 315/433 MHz transmitter adds, (as proven with Telldus Tellstick ZNet Lite v1 which did not sell so well because it only had a 433 MHz receiver, so Telldus Tellstick ZNet Lite v2 also added a 433 MHz transmitter too).
    As stretch goals Kickstarter/Indiegogo you could add a DHT22 humidity + temperature sensor and a light sensor.
    In any case I think that this concept alone have the potential of becoming a proper commercial product if someone here have both the coding skills and enough business sense to push a such idea.

    RépondreSupprimer
  3. Great project. I was wondering if the output of the IR receiver and the Rf receiver is not too high for the esp chip when those modules are supplied to 5Volt.

    Having said that, I have fed an rf transmitter with 3.3Volt and that still had a good range... with a proper antenna

    RépondreSupprimer
    Réponses
    1. Hello,
      Thanks, in theory yes esp8266 accept 3,3V and the receivers are returning 5V signal, but in real life it works and I never had issue about this.

      Supprimer
  4. The SantaMedical RY-230 Non-Contact Infrared Thermometer is designed to take accurate temperature readings of areas such as the forehead or tear ducts. It reads forehead temperature from 1” to 4” away, and has a large LCD screen and backlight for easy night time usage. Buy Now at amazon.com
    2 in 1 Professional Clinical Infrared Thermometer

    RépondreSupprimer
  5. I wonder if you could help me.
    This picture shows pin D1 and D2.
    Based on the code for ESP8266, it seems like I should use D3 and RX?

    So far I cannot receive any signal.
    I also am not sure to convert the binary based code to the decimal base code to verify the transmit works.

    What can I try to diagnose this... :(

    Wifi, subscription to MQTT, is working.

    I disabled IR in my code.

    RépondreSupprimer
  6. Ce commentaire a été supprimé par un administrateur du blog.

    RépondreSupprimer

Enregistrer un commentaire

Posts les plus consultés de ce blog

433toMQTTto433 - Bidirectional ESP8266 NodeMCU gateway between RF 433Mhz signal and MQTT

The goal  is to act as a gateway between 433Mhz sensors and a MQTT broker or between the MQTT broker and 433Mhz actuators, It enables to: receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data  publish MQTT data to a different topic related to received 433Mhz signal  It can be an interesting part in an home automation system so as to interface sensors and actuators (wall sockets) with software like openhab . List of compatible sensors here The interest of putting this gateway to an ESP8266 and not on a raspberry pi is to be able to manage security actions at gateway level (power on a siren, cut power to certain devices) following RF data received by sensors without being dependent to the PI for security related actions. [EDIT] all infos are now centralized into  the github repository  take a look at it you will find up to date info about OpenMQTTGateway You need: Software: Mosquitto Arduino IDE latest versio...

Get your BLE sensors data into Home Assistant in 5 minutes

You can now upload your board directly from the web browser!  So let's imagine you want to read data from a sensor like a Mi Flora, an LYWSD03MMC, a weight scale, or any other BLE sensor from this list  Plug an ESP32 dev board to your computer USB port Go to this website: https://docs.openmqttgateway.com/upload/web-install.html Select esp32dev-ble Click the install button Depending on your board you may have to press the BOOT button Choose the port that the ESP is connected to. Wait until the process is complete. Release the BOOT button That's it, OMG is now loaded into your ESP32 board without Arduino IDE, platformIO or a binary flasher. Here are the steps in images: Now comes the Home Assistant part: Add the MQTT integration and activate auto discovery Create a user and a password (Configuration->Users) without administrator right for the gateway Well, this is enough for Home Assistant. So let's now connect both: Check the Wifi Access points available with your smartph...