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
Enregistrer un commentaire