Rule: How to be triggered by negative value of Number-Item

Hi there,
just a short question. Didn’t find a solution yet after googling for it quite a while:

How can I set a rule to be triggered by a negative value of a Number-Item?

rule "Negative Number"       
  Item Numberitem changed to -1

Writing it as -1 or (-1) triggering following error message:

[WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model ‘dus.rules’ has errors, therefore ignoring it: [3,31]: no viable alternative at input ‘-’

And “-1” is obviously not a valid value for a Number Item, since it doesn’t trigger anything, not even an error message.

How do I code the trigger correctly?

You could try:

rule "Negative Number"       
  Item Numberitem changed
 if (Numberitem.state == -1)  Light.sendCommand(ON)

Yes, this should work, but is very different to the original rule, as it is triggered through every change.

I think, if it’s not possible to define a negative value as a trigger, this is an issue.

1 Like

I think that is currently broken. As far as I know right now you can only trigger a rule with a specific state like that with enum types (e.g. ON/OFF, OPEN/CLOSED, etc).

-1 IS a valid value for a NumberItem. You just can’t use it in a trigger right now.

There are actually two issues at play here.

  1. The known issue I discussed above. Thom D. and I had a long discussion about it a while back and I have some alerts in my Rules that will tell me when it gets fixed. I think it was on his Washing Machine State Machine thread. There is an issue open for this I’m 80% certain.

  2. It will be hard to tell until problem 1 gets fixed, but there might be a problem with the Rules Language Parser that is preventing negative numbers from being used in Rule Triggers. There is no way to really test this though, let along fix it until 1 gets corrected as well.

As far as I know @lfs_alp5’s solution is the only one until both of these issues get fixed.

If I remember right it is a bit cranky about simple assignments (maybe only in global space) e.g.
var blah = -1

Is there an issue filed already?
I’m playing around with some kind of low key monitoring. I’d like to use { expire="1h,state=-9999", ... } as I know, that value is not common in my devices. I don’t like to just { expire="1h", ...}, because then I don’t know, if UNDEF was triggered by the expire or just after a reboot (or some new saved .items file).

of course I could use { expire="1h,state=9999", ... }, still it’s a value, which could be reached in some devices. As I use it mainly for “Number” items, a String would not do.

Same problem still exists in v2.5.
My work-around Item Numberitem changed to "-1" seems to work. Not nice, but it works.