[SOLVED] Paper UI Rule Engine - greater than not working


I’m new to OpenHab and I really like it so far, but I have a problem with the Rule Engine. I know it’s experimental, but I still wanted to give it a try.
I tried to create a rule which should turn off my wall plug which is connected via MQTT when the Watt consumption is larger than a certain value.

To test this, I created a rule with the value “20 Watt” (see screenshot), which works, but I would like to have something like “greater than 20”. When I change it to “> 20”, nothing happens (with or without space).

Is it possible that “greater than” is not implemented yet?

As the rule engine was not working for me, I tried to create the rule via a .rules-file, but this is also not working. I might have mixed up Items and Channels, but I am not sure… Can anybody help me getting this done?

rule "Watt Test"
	Item mqtt_topic_steckdose_stube_Watt changed 
	if ( mqtt_topic_steckdose_stube_Watt.state >= 20) {


That’s a long item name,:smile: is it defined as a Number?

Maybe try this and post the log info if it doesn’t work.

rule "Watt Test"
	Item mqtt_topic_steckdose_stube_Watt received update 
        var watt = mqtt_topic_steckdose_stube_Watt.state as Number
	if ( watt >= 20) {


I guess it’s not the name of the thing - it’s the name of the channel, so I assume I just took the wrong name? :wink:
And yes, Watt is defined as a number, and everything is working with Habpanel as well as BasicUI

These are my Things:

These are my Channels:

I tried your code and nothing has changed - the only relevant Log-entry I can see in the OpenHAB Log Viewer is this:

2019-04-19 15:36:06.374 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Watt changed from 14 to 28

Do I have to activate the rule somehow? I only created the .rule-file via Visual Studio

Thank you!

You picked up on my hint.:+1:

Try using the items name and not the channel.

rule "Watt Test"
	Item Watt received update 
	if ( Watt.state >= 20) {


When I check my Items in the Paper UI menu, I have these two entries:



So wouldn’t your first code be “more correct” as you were using my Items? :wink:
Unfortunately, your second example is also not working

If using the channel to trigger the rule you will need to define it in the when section.

rule "Watt Test"
	Channel 'mqtt_topic_steckdose_stube_Watt' received update 
	if ( Watt.state >= 20) {


Also, I changed the send command item to Strom as Watt is a number, not an ON/OFF item.

I should mention I use files for all my configs so PaperUI config and rules are not exactly intuitive, at least for me.:laughing:

Post the error message from the logs to help identify the issue.

your are right, this mix is not really intuitive…

Unfortunately, I cannot see any log entry related with the rule - the only one I found is related with the Watt change:

2019-04-19 17:03:57.554 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Watt changed from 2 to 30

Do I have to activate the logging of rules somewhere? Or in general, do I have to activate rules?

No activation needed but looking above you mentioned a .rules-file. Did you name it this way? If so try renaming it to something like test.rules with no hyphens.

It is called exactly like this:

It seems like OpenHAB just doesn’t recognize my rule…

I get the following information out of my log - does it have to do with the rule?
It says something about the Humidity and Temperature, but in BasicUI, I can see the Humidity and Temperature…

2019-04-19 17:39:27.589 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Watt changed from 4 to 31

2019-04-19 17:39:37.496 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Uptime changed from 0T10:30:15 to 0T10:30:25

2019-04-19 17:39:37.570 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Luftfeuchtigkeit changed from 29.4 to 29.3

2019-04-19 17:39:37.579 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Watt changed from 31 to 30

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

2019-04-19 17:39:41.478 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.AM2301.Humidity' in '{"Time":"2019-04-19T16:39:41","ENERGY":{"TotalStartTime":"2019-04-05T17:16:13","Total":0.870,"Yesterday":0.137,"Today":0.198,"Power":1,"ApparentPower":3,"ReactivePower":3,"Factor":0.22,"Voltage":228,"Current":0.012}}'

2019-04-19 17:39:41.480 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"Time":"2019-04-19T16:39:41","ENERGY":{"TotalStartTime":"2019-04-05T17:16:13","Total":0.870,"Yesterday":0.137,"Today":0.198,"Power":1,"ApparentPower":3,"ReactivePower":3,"Factor":0.22,"Voltage":228,"Current":0.012}}' not supported by type 'NumberValue'

2019-04-19 17:39:41.482 [WARN ] [l.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.AM2301.Temperature' in '{"Time":"2019-04-19T16:39:41","ENERGY":{"TotalStartTime":"2019-04-05T17:16:13","Total":0.870,"Yesterday":0.137,"Today":0.198,"Power":1,"ApparentPower":3,"ReactivePower":3,"Factor":0.22,"Voltage":228,"Current":0.012}}'

2019-04-19 17:39:41.484 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload '{"Time":"2019-04-19T16:39:41","ENERGY":{"TotalStartTime":"2019-04-05T17:16:13","Total":0.870,"Yesterday":0.137,"Today":0.198,"Power":1,"ApparentPower":3,"ReactivePower":3,"Factor":0.22,"Voltage":228,"Current":0.012}}' not supported by type 'NumberValue'

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

2019-04-19 17:39:41.493 [vent.ItemStateChangedEvent] - mqtt_topic_steckdose_stube_Watt changed from 30 to 1

Have you added temp and humidity transformation to the Watt item?

You can always create the Watt item in a file and see if that works with the rule.

Based on the channel above this should work for the item. After adding this you may need to remove the one created in PaperUI so you don’t end up having duplicate items.

Number Watt "Watts [%.0f %%]"             { channel="mqtt_topic_steckdose_stube_Watt" }

I have one thing (it’s a power plug with temperature and humidity sensor) and a few channels assigned to this thing - for each channel, I have assigned one item:

Yes, I am using the following incoming value transformation for Watt:

I also tried this, but without any result…I still can’t see anything in the Log…

Any other idea?

I was finally able to “solve” the problem…I don’t know why, but my Visual Studio was connected to the local backup folder instead of the Raspberry Pi… :man_facepalming: :man_facepalming: :man_facepalming:

So actually my original code is working now, but also your first answer works as it should - THANK YOU anyway for your help!! :smiley: