RFLink binding

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. :smiley: 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

npm install mqtt
npm install serialport

Try this for installing node on PI.

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();
});



got this script working. Thanks!
Recognized two things:

  1. Temperature is missing the number after decimal sign. Example message: 20;9E;LaCrosse;ID=0c07;TEMP=00e1; Temp is parsed as 22 instead of 22.5
  2. Minus temperatures are not handled at all.

Any chance to get this supported? Maybe you can activate the issues module for your GIT repo? I am to lousy in python to fix my self.

@biobier No need to use script, python, etc.
You can use serial binding as described earlier.

1 Like

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:

You can try the latest version. I’ve fixed it.

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.

As my Java skills leave a lot to be desired, its not a pretty implementation, but its working for me. A test / dev version of the jar file can be downloaded from dropbox,
https://www.dropbox.com/s/n1tfm9asi9btpgg/org.openhab.binding.rflink_2.0.0.jar?dl=0 or compile from git, https://github.com/cyrilcc/org.openhab.binding.rflink

JJ

2 Likes

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.

1 Like

Hi Martin! I tried your gatway… very nice !

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.

Thanks for your advice… I have no experience with node red…but I’ll look into it !

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

@Johan_F Can you try the fix I’ve committed?

hm I get

RFLinkGW.SerialProcessing - run - ERROR - Receive error: name 'signedhex2dec' is not defined

Ok, sorry about that. I’ll investigate later today and fix this.

@Johan_F : should be fixed now. Let me know if something is still wrong

1 Like

works like a charm now! Thanks a lot man :slight_smile:

a question about this:

im new in OH2 (OHian). How can i add this binding
to OH2?

i see here different solution to bind a rflink device, eg

works they all with the last OH2 revision?

rflink-page shows a link to cyrilcc/org.openhab.binding.rflink

regard

Another one is described earlier in this thread, you don’t have to install a special binding.

1 Like

ok, how can i log my devices? if i copy your code, i get a error

==> /var/log/openhab2/openhab.log <==

2018-01-04 17:38:42.185 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'home.rules'

2018-01-04 17:38:42.204 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' is either empty or cannot be parsed correctly!

2018-01-04 17:38:42.300 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'home.rules' has errors, therefore ignoring it: [12,1]: missing EOF at 'val'

im new in OH. can anyone help, that on my system rflink runs?

at the moment i ve a clean openhabian installed. only samba and ssh works.

how must i install the script or the addon?