I’ve been using this post to help me communicate between RFLink for OpenHAB using Serial and MQTT. I’ve done so using NodeJS which happened to be pretty straight forward. I initially wrote something in C using sockets but found this solution much easier to write and debug. Anyway, this code is based on bbubble62’s python code. So big thanks to him!
On the Pi first install node, then install the mqtt and serialport modules. I have installed node v6.11.0 which gave me npm v3.10.10. Once Node was installed I ran
Here is my code for NodeJS SerialPort to MQTT bridge (error handling removed to keep it simple). Save the text as bridge.js and run using: sudo node bridge.js
'use strict'
var SerialPort = require('serialport');
var mqtt = require('mqtt');
var serialDevice = "/dev/ttyUSB0";
var serialBaud = 57600;
var client = mqtt.connect("mqtt://192.168.1.80");
var port = new SerialPort(serialDevice, {
baudrate: serialBaud,
dataBits: 8,
stopBits: 1,
parity: 'none',
parser: SerialPort.parsers.readline('\r\n')
});
client.on('connect', function () {
client.subscribe('rflink/tx');
console.log("--- MQTT connected ---");
});
client.on("message", function (topic, message) {
SerialPort.write(message.toString() + "\r\n");
})
port.on("data", function(data) {
console.log(data.toString());
client.publish("rflink/rx", data.toString());
});
port.on("open", function() {
console.log("Serial port opened: " + serialDevice);
port.flush();
});
The advantage to get RFlink to MQTT is that several systems could get/send the messages (like Nodered) That is more complicated with Openhab maybe…
Found now best solution for me is the NODE RED addon:
Looks like this thread started out as an RfLink binding thread.
As an FYI to those still interested, I’ve added initial support for outbound messages, switches/contacts (Tested with X10 equipment) Oregon Temp sensor and RTS/Somfy blinds.
Great! I will have a look at the new code after I am done moving to my new house. I am planning to do some development on this binding once I am fully settled. Would be nice to support several of the many protocols RFLink supports.
I have a problem though…
I have some cheap wall socket switches I try to control…the switching on/off works without any problems with openhab…
But I also use the original remote…and I want the state of the object to be updated in openhab when using the original remote…
So the mqtt-output is this when I use the remote:
/RFLINK/Kaku/41/R/SWITCH 1
/RFLINK/Kaku/41/R/CMD ON
/RFLINK/Kaku/41/R/SWITCH 2
/RFLINK/Kaku/41/R/CMD ON
/RFLINK/Kaku/41/R/SWITCH 3
/RFLINK/Kaku/41/R/CMD ON
The problem here is that the lines with the CMD-part is identical for all the switches…so I dont have any uniqe string to connect to the item in openhab…
Can I solve this somehow ?
Why don’t you only use the SWITCH message in order to control what you want instead of CMD since they are all the same?
If you do also have CMD OFF, you can use Nodered to consume everything under /RFLINK/Kaku/41/R/ and merge messages arriving in a short period. That way, you end with a message containing both SWITCH information and CMD information.
Hey David, Im using your enhanced version of RFLinkGateway … but in the original as well as in your version I have trouble with temperature readings… example:
RFLINK/Digitech/00ba/R/BAT OK
RFLINK/Digitech/00ba/R/TEMP 38.3
RFLINK/Digitech/00ba/R/message 20;04;Digitech;ID=00ba;TEMP=017f;BAT=OK;
RFLINK/Prologue/9742/R/TEMP 3277.1
RFLINK/Prologue/9742/R/message 20;05;Prologue;ID=9742;TEMP=8003;
Why is the value that is sent to the controller changed (corrupted?)?
In the first example I would have wanted “017f” to be the value to get to the controller… and “8003” in the second example… Am I missing something?
Edit:
Well I think I understand now… the hex value is translated to decimal… that seems to work as long as we have positive degrees (Celcius)… but when the temperature drops below 0 C it should have calculated 3276.8 (8000h) - 3277.1 (8003h) = -0.3 (my second example)…