Serial binding and mysensors binding

So I’m a beginner so I hope this belongs here. Also I hope this is enough info but not to much.

Raspberry pi 2 Ubuntu
Mysensors Arduino with relay nodeid 2 sensor id 1, Mysensors serial gateway

Ubuntu 15.10, Openhab 1.8
Mysensors 1.5

So I’ve been getting things going and have gotten stuck. I just want to have Openhab control and get data from the mysensors serial gateway.
My first question: Is currently with my setup what I want to do possible?
Running under the assumption that it is, my second question:
I watch the log when I start openhab from a seperate terminal, tail -f /var/log/syslog, I edited this to show only what I think is relevent which I realize may be a mistake, so let me know.

Serial binding has been started.
Loading model 'home.rules'
RXTX Warning:  Removing stale lock file. /var/lock/LCK..ttyAMA0
[DEBUG] [b.serial.internal.SerialDevice:136  ] - Serial port '/dev/ttyAMA0' has been found.
[DEBUG] [.b.m.internal.MySensorsBinding:96   ] - activate
RXTX fhs_lock() Error: opening lock file: /var/lock/LCK..ttyAMA0: File exists. It is mine
�#�_/ttyAMA0 testRead() Lock file failed
[ERROR] [.o.b.m.internal.gateway.Serial:70   ] - Unable to find Serial port '/dev/ttyAMA0'
[INFO ] [.service.AbstractActiveService:169  ] - MySensors Refresh Service has been started
[ERROR] [.service.AbstractActiveService:175  ] - Error while executing background thread MySensors Refresh Service
java.lang.NullPointerException: null
org.openhab.binding.mysensors.internal.gateway.Serial.write( ~[na:na]
org.openhab.binding.mysensors.internal.MySensorsBinding.execute( ~[na:na]
org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute( ~[na:na]
org.openhab.core.service.AbstractActiveService$ ~[na:na]

Is this a problem?
Because then when I push a switch everything seems to work except that the relay state never changes (also watching on the serial monitor from my laptop where nodeid 2 is being powered)

    Executing rule 'testswitch Switch Rule'
    [INFO ] [runtime.busevents             :22   ] - testswitch received command ON
    Function: switchOperation >> 2;1;1;1;2;1
    [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Arduino sends to Openhab'
    [DEBUG] [b.serial.internal.SerialDevice:282  ] - Writing '2;1;1;0;2;1
    Mar 20 19:34:39 homecontrol[26773]: ' to serial port /dev/ttyAMA0
    [INFO ] [runtime.busevents             :22   ] - Arduino received command 2;1;1;0;2;1
    [DEBUG] [o.o.i.r.i.b.GeneralBroadcaster:46   ] - broadcaster '$1@1883158' is empty
    [DEBUG] [.r.i.resources.SitemapResource:146  ] - Received HTTP GET request at 'sitemaps/home/0004' for media type 'null'.

So everything looks correct, and what I mean is all the things like the serial port, what the Arduino commands should be.

Also here is what happens if I hit the reset button on the gateway

Received message '0;0;3;0;9;gateway started, id=0, parent=0, distance=0
0;0;3;0;14;Gateway startup complete.
 ' on serial port /dev/ttyAMA0
[DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Arduino sends to Openhab'
[INFO ] [runtime.busevents             :26   ] - Arduino state updated to 0;0;3;0;9;gateway started, id=0, parent=0, distance=0
0;0;3;0;14;Gateway startup complete.

Could someone nudge me in the direction of what I need to do next?


One missing piece of information is how did you install, manually or through apt-get? The apt-get method is by far the preferable approach, particularly for beginners.

One other thing, when posting code or logs, please use the code formatting options. You can highlight your lines and press the </> button above, indent each line by four spaces, or surround your text with three backticks `

your pasted code or logs

This makes is WAY easier to read.

Yes. Whatever user openHAB is running under does not have permission to open ttyAMA0 for writing because some other software running on your box has it locked. Only one process at a time can write to a tty device.

The binding isn’t able to actually send the command out over the tty device per above.

Except that OH doesn’t have permission to actually write that to the tty.

Thanks for the tips,

Installed through apt-get

Ok, wanna see if I got what your saying, not only does the user: openhab have to be in the dialout group, but also the user who I am logged in as, need to be in the dialout group?

…So while I waited I did add my current user to the dialout group, restarted openhab

Sudo service openhab restart

and am still recieving everything like before, errors look the same, actions perform the same, nothing has changed.
Also I thought of something else, you said that openhab can’t connect to the serial port, does that mean that openhab can listen, but when it needs to write something it fails because something is preventing it from specifically writing to the port?

No, just the openhab user.

Like I said above, it doesn’t look like just a file permission problem per se. It looks like there is something else running on your machine that has a lock on the device. As long as there is a lock on the device OH will not be able to write to it.

Mostly. It can read from the device but because something else has a lock on it OH cannot write to it.

I have another question, is this not some sort of conflict with the two bindings? First the serial binding grabs the port, then later the mysensors binding trys to get the port and fails because it is locked by the serial binding? Or do I miss understand what’s going on? I ask because previous posts talked about removing stale lock files, so I do that, no lock file, start openhab lock file is created, otherwise no lock file.

Seems to be the likely problem to me. I’ve no experience with either of these bindings but it seems likely to me that you cannot use them both on the same device because one binding puts a lock on the device then the other is forbidden from writing to it. Why are you trying to use both binding on the same device?

I so far have been under the impression that I needed both, I’m not sure where I got that idea. So now I have mysensors disabled, and just the serial binding (now seemingly working). So when I push a button on my android phone I get.

[m.r.internal.engine.RuleEngine:305  ] - Executing rule 'testswitch Switch Rule'
[INFO ] [runtime.busevents             :22   ] - testswitch received command ON
Function: switchOperation >> 2;1;1;1;2;1
[DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Arduino sends to Openhab'
[INFO ] [runtime.busevents             :22   ] - Arduino received command 2;1;1;0;2;1
[DEBUG] [b.serial.internal.SerialDevice:282  ] - Writing '2;1;1;0;2;1
' to serial port /dev/ttyAMA0
[INFO ] [runtime.busevents             :26   ] - testswitch state updated to ON
Light Item: testswitch Light: ON

Still no state change on the relay, is there anyway I can see what the serial port is receiving, basically to see if openhab is able to write and that its just something wrong with my hardware?

Ok, got rid of everything related to the serial binding, only put


in openhab.cfg and now have no errors. No errors at all,

testswitch received command ON
[DEBUG] [.b.m.internal.MySensorsBinding:230  ] - internalReceiveCommand(testswitch,ON) is called!
[DEBUG] [o.i.r.i.resources.ItemResource:205  ] - Received HTTP POST request at 'items/testswitch' with value 'OFF'.
[INFO ] [runtime.busevents             :22   ] - testswitch received command OFF
[DEBUG] [.b.m.internal.MySensorsBinding:230  ] - internalReceiveCommand(testswitch,OFF) is called!

Still no change in relay state.

Did you change your Item that was trying to write through the serial binding to use the mysensors binding instead?

so here is my latest idea, sense this is a raspberry pi, and I have seen that at least with other distros for the pi people do some things to set it up so that the serial port can be used by users. Of course this process is automated in the posts that I have seen, so I am going to keep digging and see if somethings else can be done to make it writable. Im drawn to this conclusion because I use

screen /dev/ttyAMA0 115200

I can see the arduinos talking but my machine never writes anything so I am sure you are right, something is locking up the port. I feel like I am just missing something, guess this is why everyone says this is not a project for just anyone.

Is the device owned by the group dialout?

Here’s mine:

root@OpenHAB:~# ls -la /dev/ttyUSB0 
crw-rw---- 1 root dialout 188, 0 Mär 24 08:44 /dev/ttyUSB0


crw-rw---- 1 root dialout 204, 64 Mar 23 18:52 /dev/ttyAMA0

So I have been trying to make sure I got rid of getty running on the serial port. I read on a trip through google that this would tell me if getty was running

ps aux | grep ttyAMA0
gundark  30465  0.0  0.1   3728  1524 pts/1    S+   19:42   0:00 grep --color=auto ttyAMA0

Not sure if this is true, because I can’t confirm any of the things going on because the post is about systems not similar to mine. Ubuntu is running systemd and I haven’t found a post yet talking about getty and systemd.

Hi I am new to openhab and just don’t get my relay and dimmer mysensor nodes to work. All my other sensor report back to my dashboard. If I look and the logs I see that I do send the command to the relay but the relay dont turn on. what I am doing wrong?

16:37:19.665 [INFO ] [runtime.busevents :22 ] - LightSwitch_GF_Study received command ON 16:37:19.680 [DEBUG] [.b.m.internal.MySensorsBinding:230 ] - internalReceiveCommand(LightSwitch_GF_Study,ON) is called! 16:37:19.849 [INFO ] [runtime.busevents :22 ] - LightSwitch_GF_Study received command OFF 16:37:19.864 [DEBUG] [.b.m.internal.MySensorsBinding:230 ] - internalReceiveCommand(LightSwitch_GF_Study,OFF) is called! 16:37:20.041 [INFO ] [runtime.busevents :22 ] - LightSwitch_GF_Study received command ON 16:37:20.049 [DEBUG] [.p.rrd4j.internal.RRD4jService:132 ] - Stored 'LightSwitch_GF_Study' with state '1' in rrd4j database 16:37:20.098 [DEBUG] [.b.m.internal.MySensorsBinding:230 ] - internalReceiveCommand(LightSwitch_GF_Study,ON) is called! 16:37:20.225 [INFO ] [runtime.busevents :22 ] - LightSwitch_GF_Study received command OFF 16:37:20.243 [DEBUG] [.b.m.internal.MySensorsBinding:230 ] - internalReceiveCommand(LightSwitch_GF_Study,OFF) is called! 16:37:20.449 [INFO ] [runtime.busevents :22 ] - LightSwitch_GF_Study received command ON 16:37:20.466 [DEBUG] [.b.m.internal.MySensorsBinding:230 ] - internalReceiveCommand(LightSwitch_GF_Study,ON) is called! 16:37:20.890 [DEBUG] [.b.m.internal.MySensorsBinding:263 ] - I_LOG_MESSAGE: read: 66-66-0 s=1,c=1,t=17,pt=5,l=4,sg=0:308 16:37:20.893 [INFO ] [runtime.busevents :26 ] - Watt_GF_Power state updated to 308 16:37:20.892 [DEBUG] [.b.m.internal.MySensorsBinding:307 ] - Watt_GF_Power = 308 16:37:20.894 [DEBUG] [.b.m.internal.MySensorsBinding:263 ] - I_LOG_MESSAGE: read: 66-66-0 s=1,c=1,t=24,pt=5,l=4,sg=0:3316482


Hey Francois,
I am relatively new to mysensors and openhab myself. It turns out though related to this problem my hardware didn’t work, I gave up on the serial port, and the mysensors binding. Instead I have my pro mini now hooked up through a ttl to usb converter and am using the serial binding.

If you want to post your .items file, and at least your .rules file, or at least the relevant sections you may get more of a response from everyone as what you posted unfortunately doesn’t show much.

Hopefully I can help with more information.

Hi Sean

Do you have have rules in place to send something to the relay? As currently I don’t have any rule file

Here is the line in the .item file for the relay.

Switch LightSwitch_GF_Study "Study Light" <socket> (GF_Study) { mysensors="21;1;V_STATUS" }



So I have been doing alot of tinkering and need to do a whole write up on what I learned, but to answer your question no I do not anymore. What I found was that I think I was having the same problem as you, with different symptoms. It turns out that my serial gateway was using a crappy part and wasn’t sending or receiving all the signals, and even though I have debug running I couldn’t tell. So I attached my second sensor and watched through the serial monitor, turns out it was working sometimes, but most of the time every message was failing, and because of the crappy part none of that was passed to openhab. So make sure all of your parts are good, that your connections are solid and that your radios have the 10uf capacitor, and that your radios are all oriented in the same way.