In your case the error log indicates that the variable CircularGeofenceRegion is already defined. Since this is a class, I guess that the class definition is not the problem here but the constant definitions inside them.
When I change the const variables to var the same error happens on the second run of the rule. Interestingly when I disable and re enable the rule it again runs fine for the first execution then gives the error on the second run.
Maybe the class declaration is an issue as well.
Are there any potential workarounds for this at the moment?
Multiple execution of the same rule / script will share the same context.
Only if you update/save a rule or restart OH it’s considered to run in a new context. Therefore it’s working the first time, but the 2nd time you run the rule, your rule will do something that can only be done once.
Maybe the script is failing because you try to define a class that’s already existing in the 2nd run
I also started converting my rules to ECMAScript 2021 rules recently. To work around the “Variable already declared” error I went old school: I wrapped the rule in an anonymous function that is run immediately. So, something like
//rule code added here...
I don’t know if it’s the best way of doing things but my rules run without a problem.
And, if I need to persist a value between rule-runs I use the cache key-value store.
A rectangular geo-fence might work ok, do you happen to have an example of JS code for that?
I have the GPS coords coming into items via the iCloud binding for a few family members and was thinking a simple time based trigger would be suitable. The location data seems to be coming in every 5-10 minutes. Perhaps that it is better trigger.
You can simple check if the provided lat & lon values are within the range (=someone is on or near the island) or not.
The only thing you need are < & > operators and the lat / lon definition of your rectangular geofence
If you want to check on multiple geofences than I would put the min & max values into a map and loop through the map:
I ran a test rule every second for about 30 minutes and saw no increase of the memory usage of my docker container that runs openhab. The rule consisted of getting a few items, settings some variables, caching an item state and printing to the console.
Running the experiment in combination with the handful of other ecmascript-2021 rules that run continuously for me without issues, makes me conclude that the garbage collector is doing its job.