# \[SOLVED\] ScriptServiceUtil state Question

**URL:** <https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380>\
**Category:** Beginners\
**Tags:** scriptserviceutil\
**Created:** [April 11, 2020, 5:48pm UTC](https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380 "2020-04-11T17:48:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NCO](https://community.openhab.org/user_avatar/community.openhab.org/nco/32/55938_2.png) [@NCO](https://community.openhab.org/u/NCO)\
**Post date:** [April 11, 2020, 5:48pm UTC](https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380/1 "2020-04-11T17:48:12Z")

</div>

- 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

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [April 11, 2020, 7:09pm UTC](https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380/2 "2020-04-11T19:09:58Z")

</div>

> [@NCO](#):
>
> [ERROR] [org.quartz.core.JobRunShell] - Job DEFAULT.Timer

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.

> [@\[SOLVED\] Unhandled Exception w/o active rules](https://community.openhab.org/t/solved-unhandled-exception-w-o-active-rules/79580/2):
>
> That looks like the sort of report you get from orphaned Timers - typically, a long running timer was spawned by a rule, and the rule file was later edited on other business. When the rule file reloads, the context for the waiting timer is destroyed - but the quartz scheduled timer job is not. Maybe hours later, the now “orphaned” timer code executes and usually fails with a NullPointerException because some variable it references no longer exists.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [April 11, 2020, 7:22pm UTC](https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380/3 "2020-04-11T19:22:29Z")

</div>

> [@NCO](#):
>
> if(itemStrState != NULL) { // does this work with state NULL to String: “NULL” / “” did not work

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”

> [@NCO](#):
>
> With ScriptServiceUtil I retrieve the state of Loc\_Home\_Str as a String,

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

---

<div class="post-metadata">

**Author:** ![NCO](https://community.openhab.org/user_avatar/community.openhab.org/nco/32/55938_2.png) [@NCO](https://community.openhab.org/u/NCO)\
**Post date:** [April 13, 2020, 7:09am UTC](https://community.openhab.org/t/solved-scriptserviceutil-state-question/96380/4 "2020-04-13T07:09:08Z")

</div>

> [@rossko57](#):
>
> You _can_ of course get the `.state.toString` , which would be “NULL”

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!
