Fibaro Wall Plug (UK) Gen5 immediately turns off when rule exists

I’ve just started with OpenHAB, and I like it so far. I’m adding a rule to prevent a pump running for more than about 3 minutes. Trouble is, when the rule file exists, the plug will generally turn off almost immediately (2 seconds) when it’s actuated by the button. When the plug is actuated by PaperUI then the rule seems to behave itself.

If I remove the rule file, then the on/off switch on the plug behaves as expected. Simplifying the rule file to only log an event doesn’t seem to change the unwanted behaviour.

The plug device was added via the PaperUI, and the rule I added using a text editor.
Here’s the rule file - there are no corresponding .items, and I’ve reduced the timer to a minute for testing

var Timer Water_Timer = null

rule "Hot water timeout"
when
    Item HotWaterPump_Switch             received update or
    Item HotWaterPump_ElectricMeterWatts received update or
    Item HotWaterPump_Switch             received command or
    Item HotWaterPump_Switch             changed from OFF to ON
then
    logInfo("Test", "Rule triggered - Hot Water Pump state has changed")
    if (HotWaterPump_Switch.state == ON) {
        logInfo("Test", "Hot Water Pump is ON - Creating Timer for Hot Water Pump")
        Water_Timer = createTimer(now.plusMinutes(1))
            [|
                logInfo("Test", "Sending command to turn hot water pump OFF after timer delay")
                HotWaterPump_Switch.sendCommand(OFF)
                Water_Timer = null
            ]
    } else {
        logInfo("Test", "Hot Water Pump is already OFF")
    }
end

Any ideas?

Edit: Here is the log output from a single button press of the plug - it turned off about a second after I press the button.

==> /var/log/openhab2/openhab.log <==
2018-10-21 18:34:16.428 [INFO ] [.eclipse.smarthome.model.script.Test] - Rule triggered - Hot Water Pump state has changed
2018-10-21 18:34:16.440 [INFO ] [.eclipse.smarthome.model.script.Test] - Hot Water Pump is ON - Creating Timer for Hot Water Pump

Have you tried using this only in the rule?

Item HotWaterPump_Switch changed from OFF

I think the problem may be in the above snippet of code. The combination of parentheses and brackets, as well as the location of these, are incorrect.

Please re-write to the following, and give it a try:

Water_Timer = createTimer(now.plusMinutes(1), [| 
  logInfo("Test", "Sending command to turn hot water pump OFF after timer delay") 
  HotWaterPump_Switch.sendCommand(OFF) 
  Water_Timer = null 
])

For reference, take a look at this page:

@KjetilA I agree this is the preferred way to write rules, but in my experience this doesn’t prevent the rule from running, or am I wrong?

I have a feeling you are talking about the way I split the code on several lines using indentation, or? This was only for improved readability.

My real comment was about the way that the createTimer call was incorrectly written (wrt. the procedure/ lambda-part). They way it was written, I am pretty sure the code that was supposed to run when the timer expired, would instead run immediately - and this could very well account for the behavior observed by the OP.

This

Water_Timer = createTimer(now.plusMinutes(1), [| 
  logInfo("Test", "Sending command to turn hot water pump OFF after timer delay") 
  HotWaterPump_Switch.sendCommand(OFF) 
  Water_Timer = null 
])

and this

Water_Timer = createTimer(now.plusMinutes(1))
            [|
                logInfo("Test", "Sending command to turn hot water pump OFF after timer delay")
                HotWaterPump_Switch.sendCommand(OFF)
                Water_Timer = null
            ]

Are the same except the ) was moved and the , added. Functionality is the same, I can’t say for sure, one way is better than the other (proper coding practice aside) but I have tested several rules and both ways work.

Hi all,

Thanks for the replies so far, but I’m pretty convinced it’s not due to the syntax of the rule. The problem appears even if I use the following rule:

rule "Hot water timeout"
when
    Item HotWaterPump_Switch changed from OFF to ON
then
    logInfo("Test", "Hot Water Pump has been turned ON")
end

Ok, now, when switching between the above passive rule and the original timer-based rule, the problem has changed. I think I probably need to narrow this down to a single cause or problem.

PaperUI is not for controlling, create a sitemap and use something like BasicUI for control. Also, you may want to create a things file, for your wall plug, and remove what was created from PaperUI.

Not sure if doing the above will solve your issue but it won’t hurt to try. If still having the issue set the log to DEBUG and post the results.

In your active urle the triggers are a problem

rule "Hot water timeout"
when
    Item HotWaterPump_Switch             received update or
    Item HotWaterPump_ElectricMeterWatts received update or
    Item HotWaterPump_Switch             received command or
    Item HotWaterPump_Switch             changed from OFF to ON
then

For example if the switch receives an ON command, your rule will run 3 times.

Now your use case is simple and there is an already build in solution for your problem.
As your time delay is fixed, we can use the expire binding and not need ANY rules.

Install the expire binding!!

Define your item as such:

Switch HotWaterPump_Switch "your label" <yourIcon> (Your groups) { yourbinding, expire="1m, command=OFF" }

The item will automatically start a timer when ON for 1 minute and send a command OFF to itself.

See:

1 Like

Thanks @vzorglub - the expire binding looks like it’ll do exactly what I want. I’ve installed it and deleted the rule. Now, however, while the timeout works when the plug is turned on via OpenHAB UI methods, it doesn’t seem to “notice” when the plug is powered on by pushing the button on the plug.

Here’s my item (timeout lowered for testing impatience):

Switch HotWaterPump_Switch "Hotwater" { zwave="zwave:device:401c57b2:node4:switch_binary", expire="1m,command=OFF" }

There’s nothing in the log files indicating the “manual” power-on event has been logged or noticed in any way; do I need to do anything to connect that to the Switch?

thanks

It’s zwave, I don’t use that tech. Sorry

Some but not all Zwave devices report to the controller when they are manually triggered. For those that do support it, you often need to go into the Thing configuration and make sure that Controller is configured as the Association Group in the Thing Config for that device. Note that not all devices have Association Groups. If your’s doesn’t then OH will not know that you have manually triggered the switch until the next polling period. I forget how long the default period is.

1 Like

@rlkoshak and @vzorglub Thank you, your solutions have fixed my problem.

For future reference, and in case anyone finds this via google, here’s the answer.

Don’t use Rules for this purpose, instead install the Expires binding and then create a .item file inside $OPENHAB_CONF/items/ (I called my file hotwater.items) with the following content (obviously switching values as appropriate):

Switch HotWaterPump_Switch "Hotwater" { zwave="401c57b2:node4:switch_binary", expire="3m,command=OFF" }

If the plug doesn’t trigger an update when you press the switch, you need to link that event with an Association Group. Go into the edit configuration page of the Thing and scroll down until you see “Association Groups”. On my plug all I had to do was connect “2: On/Off (Button)” to “Controller”, and this allowed the OpenHAB service to receive and respond to events on the button, in my case turning it off after 3 minutes.