Accéder au contenu principal

Interfacing the 433mhz bidirectional MQTT Gateway with Openhab

In this article I’m going to detail how to integrate the OpenMQTTGateway with OpenHAB using MQTT protocol.
We will explore two kind of integration :
-a cheap socket wall switch (on/off)
-a voltage sensor ( values between 0 to 5000mV) based on this tutorial

Before continuing you must have :

·         An MQTT broker running (for example mosquitto)
·         An OpenHAB instance running with the MQTT addon binding configured to talk to your MQTT broker
·         The 433mhz Gateway setup (either arduino or esp8266 one)


Cheap wall socket

The wall socket that we will be using are these ones

Be carefull not all the wall sockets are compatible with RCSwitch (Library used by the 433Mhz Gateway). For example blyss ones are not compatible.


Learning the codes of your plug

First step will be to learn the code that are used by the plug.
So as to that open your command line and subscribe to the following subject :
home/433toMQTT
Press the ON button of the remote control of your plug
You should see a value on the command line (example 678720), take note of it
Press the OFF button and note the value that appears.


Integrating with OpenHAB 1.8.x

The integration has to be done in the sitemap and the item file.
On the sitemap file just add a normal switch like below :
Switch item=PlugSwitch1

On the item file we will precise how OpenHAB will link the switch to the mqtt subject, the following text must be in one line :
Switch PlugSwitch1         "Test"
{mqtt=">[broker: home/MQTTto433:command:ON:1312081],
>[broker:home/MQTTto433:command:OFF:1312084],
<[broker: home/433toMQTT:command:ON:1312081],
<[broker: home/433toMQTT:command:OFF:1312084]"}
Where broker is the name of your broker defined in your openhab config file.
home/MQTTto433 is the subject for outgoing command and home/433toMQTT for the incomming command.
This definition enable to power ON and OFF the switch from OpenHAB and also to update the state of the switch into OpenHAB if you use the remote control.


Voltage sensor or sensor sending continuous data

In the case of continuous data the main issue is that we need to differentiate these data between the different sensors, for example if we have two sensors sending voltage between 0 and 5V we want to have a way to differentiate the data between the two sensors. As the Gateway is giving raw data coming from 433mhz sensor without Node identification we have to find away to differentiate the sensors.
This difference will be made by giving an offset to the both sensor at sensor level. For sensor A we will give an offset of 10000 and 20000 for the sensor B. The received values in milli volts will vary between :
10000 and 15000 for the sensor A
20000 and 25000 for the sensor B
With this method we can consider that the first number of the value is an identification of the sensor, 1 for sensor A and 2 for sensor B

Integrating with OpenHAB 1.8.x

The integration has to be done in the sitemap and the item file. We will need also to add a mapping into the transform folder.
On the sitemap file just add number items like below :
Number item=voltageA
Number item=voltageB

Into the transform folder add two files :
voltageA.map containing
10000=0
10001=1
10002=2
… (fill the mapping between 10002 and 14999, you can use an excel file to produce the mapping easily)
14999=4999
15000=5000
voltageB.map containing
20000=0
20001=1
20002=2
… (fill the mapping between 20002 and 24999)
24999=4999
25000=5000

On the item file we will precise how OpenHAB will link the number items to the mqtt subject by using a mapping file, the following text must be added :
Number voltageA    "voltage A[%.1f mV]" {mqtt="<[broker:home/433toMQTT:command:MAP(voltageA.map)]"}
Number voltageB    "voltage B[%.1f mV]" {mqtt="<[broker:home/433toMQTT:command:MAP(voltageB.map)]"}

You should see this way the number item updated in your OpenHAB setup.









Commentaires

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:

MosquittoArduino IDE latest version (tested ok with 1.6.10)esp8266 board added to t…

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 OpenMQT…

433toMQTTto433 - Bidirectional Arduino gateway between RF 433Mhz signal and MQTT

The goal of the Arduino 433toMQTTto433 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 with software like openhab.

The interest of putting this gateway to an arduino and not on a raspberry pi is to be able to manage security actions at arduino 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:
Arduino UNO W5100 Ethernet shield 433Mhz Receiver XD RF 5V and transmitter FS1000A 
Transmitter VCC must be p…