Set a switch with a rule based off of a number

Hey all,

I have the alpha icloud binding working fine on openhab 2.2. I have written the following rule to set my presence based on the distance from home in Meters. The problem is I get this error in the smarthome designer:
Multiple markers at this line

  • The method or field SteveSIPhoneIPhone7_DistanceFromHome is
    undefined
  • no viable alternative at input ‘51’
  • Type mismatch: cannot convert from DecimalType to boolean

Here’s my code:
rule "Steve Presence"
when
Item SteveSIPhoneIPhone7_DistanceFromHome received update
then

    if(SteveSIPhoneIPhone7_DistanceFromHome.state as DecimalType < 51){
    sendCommand(Steve_is_home, ON);
       
    }
    else
    {
        
        sendCommand(Steve_is_home, OFF)
    }

end

How did you define SteveSIPhoneIPhone7_DistanceFromHome? In a .items file or in PaperUI?

If you defined it in PaperUI, than unfortunately, Designer is not going to know anything about that Item. In that case you can safely ignore these errors.

If you defined it in a .items file then look for a typo in the name. Pay close attention to case.

Makes sense! I got it working shortly after i logged this case. Thanks!

If anyone wants to use the iCloud binding to do iOS device presence, here’s
my code:

rule "Lori Presence"
when
Item LoriSIPhoneIPhone6_DistanceFromHome changed
then
if ((LoriSIPhoneIPhone6_DistanceFromHome.state <= 50)) {

sendCommand(Lori_is_home, ON);

}
else
{

        sendCommand(Lori_is_home, OFF)

    }

end

Shortcut:

rule "Lori Presence"
when
    Item LoriSIPhoneIPhone6_DistanceFromHome changed
then
    Lori_is_home.sendCommand(if(LoriSIPhoneIPhone6_DistanceFromHome.state <= 50) ON else OFF)
end

:smiley: