[SOLVED] ScriptServiceUtil state Question

  • Platform information:
    Raspberry Pi 3B+ with openhabian 1.5 and OH 2.5.3 stable

I have a rule looking up the human readable adress for a geolocation.
For some fixed items (Home & Work Location) I would like to skip this.
However, because Location data is not persisted, I would like to initialize the human readable location for these just once.
This is the according rule:

rule "Lookup Address for Geolocations"
when
    Member of G_Loc changed
then
    val itemName = triggeringItem.name.toString // geo location item
	var location = triggeringItem.state.toString // geo location item state
	var String itemNameStr = itemName + "_Str" // human readableaddress item
	val itemStrState = ScriptServiceUtil.getItemRegistry.getItem(itemNameStr).state // state of the human readable address

	logInfo("+++ GEOFENCING", "Location update: " + itemName + ": location: >" + location + "<")

// skip processing for some Locations
	if(itemName == "Loc_Home" || itemName == "Loc_Work") {
	
		// just end here if the initial address lookup for fixed locations (home / work) has not been done
		logInfo("+++ GEOFENCING", "Location_Str of item " + itemNameStr +" +++++ DEBUG +++++ itemStrState: >" + itemStrState + "<")
		
		if(itemStrState != NULL) { // does this work with state NULL to String: "NULL" / "" did not work
			logInfo("+++ GEOFENCING", "G_Loc changed - " + itemName + " Address eval skipped")
			return; // failing fast
		}
	}
	...

I get the following errors:

2020-04-11 16:23:49.504 [INFO ] [marthome.model.script.+++ GEOFENCING] - Location_Str of item Loc_Home_Str +++++ DEBUG +++++ itemStrState: >NULL<
2020-04-11 16:23:49.504 [ERROR] [org.quartz.core.JobRunShell         ] - Job DEFAULT.Timer 16 2020-04-11T16:23:49.182+02:00: Proxy for org.eclipse.xtext.xbase.lib.Procedures$Procedu$
  logInfo(<XStringLiteralImpl>,<XStringLiteralImpl>)
  ! <XMemberFeatureCallImplCustom>
  <XFeatureCallImplCustom>.postUpdate(<XConstructorCallImplCustom>)
  ! <XMemberFeatureCallImplCustom>
  <XFeatureCallImplCustom>.postUpdate(<XConstructorCallImplCustom>)
  ! <XMemberFeatureCallImplCustom>
  <XFeatureCallImplCustom>.postUpdate(<XConstructorCallImplCustom>)
  ! <XMemberFeatureCallImplCustom>
  <XFeatureCallImplCustom>.postUpdate(<XConstructorCallImplCustom>)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@14bd53f (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@d86c31 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1515843 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1779762 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@12e40e (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@c0eb22 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@12a40e5 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@fa89de (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1a931ce (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@8fa4a0 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@e7deb2 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1ee4ac8 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@f4343f (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1483c20 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@19b3d5 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@edb0d5 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@1b3190d (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@b9cda4 (conditionalExpression: false)
  org.eclipse.xtext.xbase.impl.XIfExpressionImpl@66a112 (conditionalExpression: false)

So my question is:
If the state of the item for the Human readable address (Loc_Home_Str) is not initialized (NULL), how to check this?
With ScriptServiceUtil I retrieve the state of Loc_Home_Str as a String, so shouldn’t it be:
if(itemStrState != NULL) ?

I also tried
if(itemStrState != "NULL")
and
if(itemStrState != "")
None of these seem to work

This a timer failure. If you’ve just been editing a rules file with other rules that launch timers, you probably ran into the nuisance only “orphaned timer” thing.

You got the .state of the original Item to variable itemStrState
If that Item has had no update since system boot, it will be the special constant value NULL and not the string “NULL”

No, it’s a state object.
You can of course get the .state.toString, which would be “NULL”

1 Like

Excellent! I will play around with it and see what’s best for my case.

And thank you very much for the explanation of the timer error!