Rule File: Need help with val declaration of an Item's state trigger value

Hello,

I have a working Openhab2 (Openhabian 2.3.0-1) .rule file that has some hard coded item state trigger values that I want to change to “val” types. I’ve run into what appears to be a type conversion issue.

Here is the an example of the working code:

rule "TURN ON Washer Buzzer with Voice Ack"
when 
    Item NextionIDX changed to 23
then
<snip>

I would like to change the hard coded state trigger value to a val. Here is what I mean:

val Number WashStartAck = 23

rule "TURN ON Washer Buzzer with Voice Ack"
when 
    Item NextionIDX changed to WashStartAck
then <snip>

There are no errors in the log, but the revised rule never executes. I’ve tried several different type conversion casts on the val without success. The only thing that works is to replace the val with a hard number.

After a couple hours of hair pulling it’s become clear that I need advice on the proper syntax to do this.

Thanks!
Thomas

I am afraid you can’t do that
The way around it is:

val Number WashStartAck = 23

rule "TURN ON Washer Buzzer with Voice Ack"
when 
    Item NextionIDX changed
then
    if (NextionIDX.state == WashStartAck) {
       ...
    }
 <snip>
1 Like

Thank You! Your suggested workaround did the trick.

  • Thomas