Getting error "The name 'sendMail' cannot be resolved to an item or type;" after upgrade to 2.4 Release Build

  • Platform information:
    • Hardware: Docker Container x84_64/1GB RAM
    • OS: Linux openhab-2.4.0-final-deb-12.2018 4.4.59+ #23824 SMP PREEMPT Fri Oct 12 18:31:34 CST 2018 x86_64 GNU/Linux
    • Java Runtime Environment: openjdk version “1.8.0_192”
      OpenJDK Runtime Environment (Zulu 8.33.0.1-linux64) (build 1.8.0_192-b01)
      OpenJDK 64-Bit Server VM (Zulu 8.33.0.1-linux64) (build 25.192-b01, mixed mode)
    • openHAB version: Upgrade from OH 2.3 Release Build to OH 2.4 Release Build

Issue of the topic: Getting error in karaf console:

22:32:37.933 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Checking Devolo Sensor On- or Offline': The name 'sendMail' cannot be resolved to an item or type; line 31, column 7, length 85
22:32:37.940 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Checking Fibaro Sensor On- or Offline': The name 'sendMail' cannot be resolved to an item or type; line 54, column 5, length 85
22:32:37.940 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Checking Fibaro Sensor On- or Offline': The name 'sendMail' cannot be resolved to an item or type; line 54, column 5, length 85
22:32:37.941 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'Checking Devolo Sensor On- or Offline': The name 'sendMail' cannot be resolved to an item or type; line 31, column 7, length 85

Affected rules are:

rule "Checking Devolo Sensor On- or Offline"
	when
		Thing "zwave:device:73a3cf04:node2" changed
	then
		var wz_status = getThingStatusInfo("zwave:device:73a3cf04:node2").getStatus()
    ZwaveWzStat.postUpdate(wz_status.toString())

		if (wz_status.toString() == 'OFFLINE')
		{
      logInfo("FILE", "***** ZWAVE: zWave Thing: Devolo Sensor is " + wz_status)
		  val message = "From ZWAVE Rule: Devolo Sensor is >> " + wz_status + " <<. Please consider rebooting the Docker container !!!"
		  sendMail("bla@yahoo.kx", "From ZWAVE Rule: Devolo Sensor is " + wz_status + " ...", message)
		}
		else
    {
      logInfo("FILE", "***** ZWAVE: zWave Thing: Devolo Sensor is " + wz_status)
      val message = "From ZWAVE Rule: Devolo Sensor is >> " + wz_status + " <<."
      sendMail("bla@yahoo.kx", "From ZWAVE Rule: Devolo Sensor is " + wz_status + " ...", message)
		}
end

rule "Checking Fibaro Sensor On- or Offline"
	when
		Thing "zwave:device:73a3cf04:node3" changed
	then
    var gh_status = getThingStatusInfo("zwave:device:73a3cf04:node3").getStatus()
    ZwaveGhStat.postUpdate(gh_status.toString())

		if (gh_status.toString() == 'OFFLINE')
		{
      logInfo("FILE", "***** ZWAVE: zWave Thing: Fibaro Sensor is " + gh_status)
		  val message = "From ZWAVE Rule: Fibaro Sensor is >> " + gh_status + " <<. Please consider rebooting the Docker container !!!"
      sendMail("bla@yahoo.kx", "From ZWAVE Rule: Fibaro Sensor is " + gh_status + " ...", message)
		}
		else
    {
      logInfo("FILE", "***** ZWAVE: zWave Thing: Fibaro Sensor is " + gh_status)
      val message = "From ZWAVE Rule: Fibaro Sensor is >> " + gh_status + " <<."
      sendMail("bla@yahoo.kx", "From ZWAVE Rule: Fibaro Sensor is " + gh_status + " ...", message)
		}
end

The mails are sent even though the error occurs. Unfortunately these rules are only triggered at startup hence I can not see if behaviour changes during runtime. But I am using the sendMail function in a lot of other rules but I only see the errors in these two rules.

Everything worked fine on version “OH 2.3 Release Build” !!!

Any idea what goes wrong?

Cheers
Justus

This is the key.

So it probably worked in 2.3 as a fluke as I think this bug has been around since then. Depending on timing during startup your Rules may start executing before the Rules engine is ready. Consequently some symbols may not yet exist when the Rule triggers, and hence the error.

There is at least one Issue already open on this problem, but fixing the startup behavior of ESH/OH is a big and complicated job and hasn’t been successfully tackled yet.

1 Like

Hi Rich,

thank you for your quick response. Would it make sense to simply add a delay through a timer like

Thread::sleep(3000)

as a workaround at the beginning of the rule to delay the system initialization a bit to wait for the symbols to become available? My OpenHAB environment is turned off during the night and hence I start it every morning and it would not be a problem to wait 5 more seconds before it gets up and running …

Just to be clear on vocabulary, Thread::sleep is not a Timer. They work differently.

Having said that, I don’t know if adding a sleep or a Timer would solve the problem. I would guess that a Timer might work better, though there is no guarantee. The problem is when the Rule starts running it gets a context. That context doesn’t change while it is running. So if a symbol doesn’t exist when the Rule starts running, sleeping or scheduling the code to run later won’t necessarily bring back in the stuff that was missing.

I would create a System started Rule to set a Switch Item to ON a certain amount of time after OH starts. Then in these Rules exit if that Switch Item is OFF.

This isn’t guaranteed to work every time either but it might make the error occur less often. Other solutions involve moving the .rules files out of the rules folder and only moving them back after OH has fully come up.

Or you can just live with the error until it get’s fixed. You did mention that the code is working despite the errors.