Z-Wave rule not working as it should

I am trying to controll my fibaro wall plug with with the button from fibaro on a single press but the rule didn’t even start and at the moment I don’t know why.

Maybe someone finds an obvious mistake that I don’t see and can help me.

c_f_tb_01" is the button and "c_f_wp_01” is the wall plug.
The fibaro button can have the states: 1 / 1.1 / 1.2 / 1.3 / 1.4 / 1.5 / 1.6

My items:

Switch c_f_wp_01 "Fibaro WallPlug 01" <none> (zwave) {channel="zwave:device:XXXXXXXXd:node2:switch_binary"}

Number c_f_tb_01 "Fibaro The Button 01" <switch> (zwave) {channel="zwave:device:XXXXXXXX:node3:scene_number"}

My rule:

var int c_f_wp_01_state = 0

rule "c_f_tb_01_pressed"

	Item c_f_tb_01 received command

	logInfo("zwave", "[c_f_tb_01] c_f_tb_01 was pressed")
	if(receivedCommand == 1 && c_f_wp_01_state == 0) {
		sendCommand(c_f_wp_01, ON)
		c_f_wp_01_state = 1
	if(receivedCommand == 1 && c_f_wp_01_state == 1) {
		sendCommand(c_f_wp_01, OFF)
		c_f_wp_01 = 0


Another question: Am I able to get the state of the wallplug with something like “c_f_wp_01.state”?

This is what I use:

Number  FibBut01_Scene		"FB01 Scene"		<contact>	(gZWave)	{channel="zwave:device:ZW090C:node5:scene_number"}
Number	FibBut01_Alarm		"FB01 Alarm: [%s]"	<fire>		(gZWave)	{channel="zwave:device:ZW090C:node5:alarm_general"}
Number	FibBut01_Bat		"FB01 Battery: [%d %%]"	<energy>	(gZWave)	{channel="zwave:device:ZW090C:node5:battery-level"}
rule	"Fibaro Button 01 Pushing"
	Item FibBut01_Scene received update
	if (FibBut01_Scene.state == 1.0) {
		logInfo("FB01", "FB01 1x pushed")
	if (FibBut01_Scene.state == 1.1) {
		logInfo("FB01", "FB01 let go")
	if (FibBut01_Scene.state == 1.2) {
		logInfo("FB01", "FB01 kept in")
	if (FibBut01_Scene.state == 1.3) {
		logInfo("FB01", "FB01 2x pushed")
	if (FibBut01_Scene.state == 1.4) {
		logInfo("FB01", "FB01 3x pushed")
	if (FibBut01_Scene.state == 1.5) {
		logInfo("FB01", "FB01 4x pushed")
	if (FibBut01_Scene.state == 1.6) {
		logInfo("FB01", "FB01 5x pushed")

It’s not a very “clean” rule… maybe I can use switch function to clean it up :slight_smile:

Ps: WDim01_Dim is a dimmer item controlling some LEDs accepting values from 0 to 100. In your case (Switch), you would send c_f_wp_01.sendCommand(ON) (or OFF)

Dimmer	WDim01_Dim		"Staircase LED Dim [%d %%]"	<slider>	(gZWave,GF_P02_Corridor)			{channel="zwave:device:ZW090C:node4:switch_dimmer"}

Yes, of course. No need to use the c_f_wp_01_state variable.

Also, after you c_f_wp_01.sendCommand(ON), there is no need to further postUpdate the state of the item. The command will take care of that.

Thanks for the example! “received update” solves the problem and the .state thing works well too. :slight_smile:

1 Like

Now something strange is happening.

If the plug is turned on and I press the button it turns off as it should. But if I now press the button again openhab turns on the plug but half a second later it is off again which is really weird.

[c_f_tb_01] Button was pressed indicates that I pressed the button. The first time to turn the plug off the second time to turn the plug on but it turned off again.

14:45:15.132 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 145 to 146
14:45:15.158 [INFO ] [eclipse.smarthome.model.script.zwave] - [c_f_tb_01] Button was pressed
14:45:15.183 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'c_f_wp_01' received command OFF
14:45:15.192 [INFO ] [marthome.event.ItemStateChangedEvent] - c_f_wp_01 changed from ON to OFF
14:45:15.205 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_ack changed from 68 to 69
14:45:15.214 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 146 to 147
14:45:15.228 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 147 to 148
14:45:16.643 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 148 to 149
14:45:16.664 [INFO ] [eclipse.smarthome.model.script.zwave] - [c_f_tb_01] Button was pressed
14:45:16.680 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'c_f_wp_01' received command ON
14:45:16.691 [INFO ] [marthome.event.ItemStateChangedEvent] - c_f_wp_01 changed from OFF to ON
14:45:16.707 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'c_f_wp_01' received command OFF
14:45:16.719 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_ack changed from 69 to 70
14:45:16.726 [INFO ] [marthome.event.ItemStateChangedEvent] - c_f_wp_01 changed from ON to OFF
14:45:16.728 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 149 to 150
14:45:16.739 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 150 to 151
14:45:16.751 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_ack changed from 70 to 71
14:45:16.756 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 151 to 152
14:45:16.766 [INFO ] [marthome.event.ItemStateChangedEvent] - zwave_serial_zstick_8364744d_serial_sof changed from 152 to 153

My rule again:

rule "c_f_tb_01_pressed"

	Item c_f_tb_01 received update

	logInfo("zwave", "[c_f_tb_01] Button was pressed")
	if(c_f_tb_01.state == 1.0 && c_f_wp_01.state == OFF) {
	if(c_f_tb_01.state == 1.0 && c_f_wp_01.state == ON) {


Fast response: Strange… Your rule seems to be ok to me and I don’t see why it would fire a second time by itself to send the OFF command without pressing the button…
Try to play around with the logic to see if the issue is fixed (or wait for a more expert rule fixer to reply to the thread :slight_smile:)
You could add a logInfo under each sendCommand line to log the actions also.

I solved it by using the good old “else if” :smiley:
For some reasons both if-conditions were accepted for turning on the plug and so it turned on and off but I still don’t know why.

1 Like