I had a rule using distanceFrom on my Synology NAS installation that worked just fine.
Item iPhone6S_Location changed
Home_L0800.state = new PointType(new DecimalType(00.000000), new DecimalType(00.000000))
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.
Can anyone give me an example please?
May 29, 2022, 11:58pm
You’d usually be interested in the
state of an Item
While that might work, it is recommended to use postUpdate
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
The example with logging added
logInfo("test", "State was "+ itemX.state)
// this will report the OLD value, the update has not happened yet.
// but - we already know what we sent it
logInfo("test", "State will become " + some-value)
It is very rare that you need to code any “wait” for this; just think clearly about what you need and choose rule triggers carefully.
Items are not simple variables.
Thank you very much for your answer. In the meantime I tried various things.
as well as
work just fine.
What seems to be the Problem is the
Means the Line
has no impact on the state of Home_N0803.
Is there something wrong with my code?
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.
May 31, 2022, 9:59am
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
Items do have
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.
I finally found a working solution:
val PointType loc = triggeringItem.state as PointType // for .distanceFrom either both need to be PointType or Location - I guess and don't know, what's the difference between them.
val PointType home = Loc_Home.state as PointType
val String whoDH = who + "_Dist" // distance (item name) from home for who
val whoDHitem = ScriptServiceUtil.getItemRegistry.getItem(whoDH) // distance (real item itself) from home for who
// who's distance from home
val distH = (lo…
July 12, 2022, 2:00am
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.