I had a rule using distanceFrom on my Synology NAS installation that worked just fine.
Items:
Location Home_L0800
Number Home_N0803
Location iPhone6S_Location
Rule:
rule “Distance”
when
Item iPhone6S_Location changed
then
Home_L0800.state = new PointType(new DecimalType(00.000000), new DecimalType(00.000000))
Home_N0803.postUpdate(Home_L0800.distanceFrom(iPhone6S_Location))
end
Since Openhab is no longer supported on Synology NAS I am now running openhab on a raspberry pi.
I can’t figure out how to use distanceFrom in a rule on the raspberry pi.
You’d usually be interested in the state of an Item
While that might work, it is recommended to use postUpdate Home_L0800.postUpdate(whatever)
That should be a reminder that this Item is not a simple variable, and results take time.
Don’t expect to use the new state in the next line, it will not have happened yet.
You might want to look at this
By the way: is there something like a log file which shows errors in scripts/rules on the raspberry pi? This was very helpful to me while I was running OH on the NAS.
Yes, it’s essential that you find that. It’ll be openhab.log just as it was on the NAS, but the folder structure is a bit different.
You can’t get the distance from an Item. A general Item might represent a phone number or temperature. It just doesn’t have a distanceFrom() method.
Items do have state, though.
Some Items may have a state that represents a location or point.
You can get distance from that - the state, not the whole Item.
And of course you would need to compare with another point, not a whole Item.