# Nikobus Rule not working

**URL:** <https://community.openhab.org/t/nikobus-rule-not-working/19074>\
**Category:** Scripts & Rules\
**Created:** [December 30, 2016, 8:12am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074 "2016-12-30T08:12:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [December 30, 2016, 8:12am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/1 "2016-12-30T08:12:06Z")

</div>

Hi

I want something simple I guess… I want to switch a light when my sensor detects presence. It worked in OH1, but not in OH2. The system is nikobus and z-wave.

//Sensors  
Number Garage\_Movement “Movement: [%s]” (SENSORS) { zwave=“2:0:command=sensor\_binary” }  
Number Garage\_Alarm “Alarm: [%s]” (SENSORS) { zwave=“2:0:command=sensor\_alarm” }  
Number Garage\_Lux “Lux: [%.2f Lux]” (SENSORS) { zwave=“2:0:command=sensor\_multilevel,sensor\_type=3” }  
Number Garage\_Bat “Battery: [%d %%]” (SENSORS) { zwave=“2:0:command=battery” }  
Number Garage\_Temp “Temperature: [%.1f °C]” (SENSORS) { zwave=“2:0:command=sensor\_multilevel,sensor\_type=1” }  
Switch Garage\_Movement\_Switch “Movement: [%s]” (SWITCHES) { zwave=“2:0:command=sensor\_binary” }

This is my old rule, which was working on OH1, does not work in OH

rule “GarageMovement”

when  
Item Garage\_Movement\_Switch changed  
then  
sendCommand(light\_Garage, Garage\_Movement\_Switch.state.toString)  
end

This is my rule with habmin rule editor

![](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/6/6b2ee1e4ac13bee8f75dd70dbce7f95a222eac62.png)

// This rule file is autogenerated by HABmin.  
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.

// Imports  
import org.openhab.core.library.types.\*  
import org.openhab.core.persistence.\*  
import org.openhab.model.script.actions.\*

// Global Variables

rule “Garage Aan”  
when  
Item Garage\_Movement changed  
then  
if ((Garage\_Movement.state == ON)) {  
sendCommand(light\_Garage, ON)  
}  
end

So I don’t know if it’s me or Nikobus.

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 3, 2017, 7:49am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/2 "2017-01-03T07:49:39Z")

</div>

I think something is wrong with the Nikobus binding in OH2. Ie feedbacks are also not working properly.

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 5, 2017, 3:54pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/3 "2017-01-05T15:54:45Z")

</div>

It depends with me… sometimes when i switch one item, another one gets switched, but I’m not sure if this is Nikobus (and flooded bus) related of HabPanel.

In the mean time i found out why my rule was not working…

It had to be Garage\_Movement\_Switch in stead of Garage\_Movement…

rule “Garage Aan”  
when  
Item Garage\_Movement\_Switch changed  
then  
if ((Garage\_Movement\_Switch.state == ON)) {  
sendCommand(light\_Garage, ON)  
}  
end

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 5, 2017, 7:17pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/4 "2017-01-05T19:17:50Z")

</div>

My item references are correct. The rules worked under 1.8.3.  
I now recreated the rules with next-gen rule engine and they are working, but behaving strange from time to time since I do not kno how to apply conncurrency lock in next-gen rules and feedback is still not working when changing an item.  
It does an item status update after the config file predefined interval (600s) but not after pressing a physical Nikobus button. This was working under 1.8.3

---

<div class="post-metadata">

**Author:** ![Fdewaele](https://community.openhab.org/user_avatar/community.openhab.org/fdewaele/32/105173_2.png) [@Fdewaele](https://community.openhab.org/u/Fdewaele)\
**Post date:** [January 6, 2017, 10:05am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/5 "2017-01-06T10:05:28Z")

</div>

In the meanwile I did a clean install of OH2 beta5 and in this release feedback is working again (also after pushing a physical button).

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 6, 2017, 2:46pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/6 "2017-01-06T14:46:23Z")

</div>

Tonight I will test the feedback with 0H2b5

The rules problem has been fixed. more changes are needed to migrate from OH1 to OH2 than indicated in the documentation.  
Changes that were needed:

1. variable defintion changes from

> var java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock()

to

> var ReentrantLock lock = new ReentrantLock()

1. Defining the variables globally does not work. All variables need to be in the “then”-block

Rule working in 1.8.3

> ```
> import org.openhab.core.types.*
> import org.openhab.core.library.types.*
> import org.openhab.core.library.items.*
> import java.util.concurrent.locks.Lock
> import java.util.concurrent.locks.ReentrantLock
> import org.openhab.model.script.actions.*
> import org.openhab.action.squeezebox.*
> import org.openhab.model.script.actions.Timer
> import org.joda.time.*
> import java.lang.Math
> import java.util.Calendar
> import java.util.Date
> import java.util.TimeZone
> import java.text.SimpleDateFormat
> import org.openhab.core.persistence.*
> import org.openhab.core.library.types.PercentType
> import org.openhab.core.library.items.SwitchItem
> import java.util.HashMap
> import java.util.LinkedHashMap
> import java.util.ArrayList
> import java.util.Map
> import org.eclipse.xtext.xbase.lib.*
> 
> ```

> ```
> var java.util.concurrent.locks.ReentrantLock lock = new java.util.concurrent.locks.ReentrantLock()
> 
> ```

> ```
> rule "Link LPgarageStatus to LP_garage"
> when
> Item LPgarageStatus changed
> then
> lock.lock()
> try {
> if(LP_garage.state != LPgarageStatus.state && SystemStarting.state == OFF) {
> LP_garage.sendCommand(LPgarageStatus.state.toString())
> logDebug("vera", "Vera switch LPgarageStatus has been synced to state " + LPgarageStatus.state.toString() + " with Nikobus switch LP_garage")
> }
> } finally{
> lock.unlock()
> }
> end
> 
> ```

Rule adapted and working in OH2B5

> import java.util.concurrent.locks.ReentrantLock  
> rule “Link LPgarageStatus to LPgarage”  
> when  
> Item LPgarageStatus changed  
> then  
> var ReentrantLock lock = new ReentrantLock()
> 
> ```
> lock.lock()
> try {
> if(LPgarage.state != LPgarageStatus.state && SystemStarting.state == OFF) {
> LPgarage.sendCommand(LPgarageStatus.state.toString())
> logDebug("vera", "Vera switch LPgarageStatus has been synced to state " + LPgarageStatus.state.toString() + " with Nikobus switch LPgarage")
> }
> } finally{
> lock.unlock()
> }
> end
> 
> ```

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 11, 2017, 10:22am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/7 "2017-01-11T10:22:03Z")

</div>

I think my issue is solved.  
In my items file I had no bindings for all the buttons, therefor button feedback was not recorded.  
I defined all buttons in my items file and now feedback is working.

I also noticed that in automation rules switching on a light does behave correctly when giving the ON command through a Nikobus button binding in stead of to the schakelmodule channel.

When giving the ON command to a schakelmodule channel item in a rule, the lights behave strangely (putting on/off different lights), which works correctly when giving the ON command to a Nikobus button item.

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 11, 2017, 9:01pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/8 "2017-01-11T21:01:29Z")

</div>

> [@stefaanbolle](#):
>
> I think my issue is solved.  
> In my items file I had no bindings for all the buttons, therefor button feedback was not recorded.  
> I defined all buttons in my items file and now feedback is working.

bindings for al the buttons? Do you mean items? I don’t have all buttons defined, still have some left…

> [@](#):
>
> I also noticed that in automation rules switching on a light does behave correctly when giving the ON command through a Nikobus button binding in stead of to the schakelmodule channel.
> 
> When giving the ON command to a schakelmodule channel item in a rule, the lights behave strangely (putting on/off different lights), which works correctly when giving the ON command to a Nikobus button item.

Nice to hear for you both it’s working too 🙂

---

<div class="post-metadata">

**Author:** ![Fdewaele](https://community.openhab.org/user_avatar/community.openhab.org/fdewaele/32/105173_2.png) [@Fdewaele](https://community.openhab.org/u/Fdewaele)\
**Post date:** [January 11, 2017, 9:59pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/9 "2017-01-11T21:59:21Z")

</div>

I also had probems when directly changing the channel state on the Nikobus modules. Quite often Openhab commands didn’t change the state on the modules and therefore the state in Openhab and the real state didn’t correspond anymore.  
Therefore I started using virtual buttons (generieke bedieningspunten) in the Nikobus software. Now an item in my sitemap changes a virtual button and the virtual button changes the real state in the Nikobus module (which also starts the feedback process)  
This works very reliable.

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 12, 2017, 9:22am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/10 "2017-01-12T09:22:52Z")

</div>

I can confirm that @Fdewaele. I defined all Nikobus buttons as separate items (and there are a lot of them 😓 )  
Howebver the feedback is not working anymore since the snapshot version. It was ok with beta5 but I needed to upgrade do to startup rules issues with beta5  
[https://community.openhab.org/t/solved-rule-when-system-started-executed-more-than-one-time/20016/4?u=stefaanbolle](https://community.openhab.org/t/solved-rule-when-system-started-executed-more-than-one-time/20016/4)

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 12, 2017, 2:36pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/11 "2017-01-12T14:36:42Z")

</div>

‘generieke bedieningspunten’. where can i find these in the nikobus software? and how to model these? i have each button as a separate item.

i also want to use my detector in the hallway as trigger for my hue lightstrips, but i can’t get my head around that how to do this. do i need a rule ?

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 12, 2017, 2:39pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/12 "2017-01-12T14:39:19Z")

</div>

Seems to be only Belgians struggling with Nikobus binding. We should create a “zelfhulpgroep” 😅

---

<div class="post-metadata">

**Author:** ![bdv](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/8baadc/32.png) [@bdv](https://community.openhab.org/u/bdv)\
**Post date:** [January 12, 2017, 6:52pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/13 "2017-01-12T18:52:32Z")

</div>

Ik was thinking the zelfde thing 🙂

10 years later i think nikobus wasn’t the solid investment i thought it would be. I’m for sure happy that openhab exists,I looked at domoticz and home automation because of the learning curve of openhab for an ethusiast like me who lacks the ability of programming (I have a basic if… then… ruleand that’s it, when I see your rules 😊 ) but nothing more. No bindings however for those. I can only be very grateful for the work of @davy because without that I would probably have spent the last year with RF2IR and iRule solutions in stead of ‘serious’ domotics.

I found it in meanwhile, the virt02/04/64 generics. Now time to find out how it works.

---

<div class="post-metadata">

**Author:** ![Fdewaele](https://community.openhab.org/user_avatar/community.openhab.org/fdewaele/32/105173_2.png) [@Fdewaele](https://community.openhab.org/u/Fdewaele)\
**Post date:** [January 12, 2017, 11:05pm UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/14 "2017-01-12T23:05:41Z")

</div>

Do you have PC-link and PC-logic?You will need 1 serial port to push the virtual button (in the Nikobus software) and 1 serial port to capture at the same time the address of it (by using Openhab debug) …

---

<div class="post-metadata">

**Author:** ![stefaanbolle](https://community.openhab.org/user_avatar/community.openhab.org/stefaanbolle/32/12687_2.png) [@stefaanbolle](https://community.openhab.org/u/stefaanbolle)\
**Post date:** [January 13, 2017, 9:05am UTC](https://community.openhab.org/t/nikobus-rule-not-working/19074/15 "2017-01-13T09:05:05Z")

</div>

@bdv: I am very happy with my Nikobus installation because it is a very stable, reliable and programmable with a screw driver and thus quite a simple system. So no regrets about my investment. However it is only thanks to @davy (much appreciiated!!) that we now can control the system with our smartphones/tablets using Openhab. i do this already for more than 2 years. It’s a pity (and shame) that Niko never offered something to make it smartphone controllable.
