Problem with rule that acts according to bluetooth signal strength

Hello,

I have this simple rule that checks if RSSI value is strong enough. Beacon_RSSI type is number that is defined in an .items file.

rule “Check phone distance with RSSI”

when
Item Beacon_RSSI changed
then
if (Number Beacon_RSSI > -30.0) {
TP_Switch.sendCommand(ON);
}
end

and it gives this error message:

[WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘blue.rules’ has errors, therefore ignoring it:
[7,13]: missing ‘)’ at ‘Beacon_RSSI’
[7,32]: mismatched input ‘)’ expecting ‘end’

Any idea what I’m doing wrong?

Cheers,
Jesse

Let’s try this:

if (Beacon_RSSI.state != Uninitialized) { 
   if (Beacon_RSSI.state > -30.0) {
      _do-whatever-is-needed_
   }
}

@gs4711

Beacon_RSSI.state != Uninitialized

This OH1 syntax and very deprecated.

@Alexa_Dot
To query the state of an item you need to use: myItem.state
There is no need to use ; at the end off code line EXCEPT after return
(return exits the rule without further ado)

Try this:
The first line checks if Beacon_RSSI is valid and if not exits the rule

rule “Check phone distance with RSSI”
when
    Item Beacon_RSSI changed
then
    if (Beacon_RSSI.state == UNDEF || Beacon_RSSI.state == NULL) return; //Do nothing 
    if (Beacon_RSSI.state > -30.0) {
        TP_Switch.sendCommand(ON);
    }
end
1 Like

@vzorglub Thank you it worked perfectly!

Hmm. I wonder how much OH1 syntax differs from OH2 if it parts of it are still used.

Cheers,
Jesse

Not much. A lot has been added.
OH1 rules should work out of the box in OH2 apart from the case above
There maybe other breaking changes but none that I can remember of, right now.
It’s a VERY long time I have use OH1

It’s been a long time since I wrote this, but the list of major changes between the two are documented in the Migration from 1.x Tutorial: https://www.openhab.org/docs/configuration/migration/#rules