Initial startup: Rules with "sendNotification" don't work

Hi,
rules with the notification (sendNotification("user@email.com", “Willkommen zu Hause.”) - I’ve changed the mailadress!) command in it don’t work after fresh reboot of OH2. After first rule-initialization there are the following error message in the log:

2016-08-10 16:43:08.811 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Anwesenheit: Komme nach Hause oder verlasse es’: An error occured during the script execution: The name ‘sendNotification(,)’ cannot be resolved to an item or type.

The solution till now:
I open up the rule-file with the eclipse smart home designer and re-save it. OH2 automatically reloads the file an after that the rule triggers without error. Also the notification is send to the smartphone.

Is there something wrong with the initial startup process?

The error and behavior implies to me that the rule is executing before OH has fully come up. So it is trying to call sendNotification before those libraries have been loaded and made available.

You can try to put in a latch to prevent or delay to call to sendNotificaiton for a few seconds or minute after OH first starts.

Switch Starting
rule "Set the latch"
when
    System started
then
    Starting.sendCommand(ON)
    Thread::sleep(60000)
    Starting.sendCommand(OFF)
end

...
    while(Starting.state == ON) Thread::sleep(500)
    sendNotification("user@email"...

If you have lots of sendNotifications, I would recommend using the Separation of Behaviors design pattern to centralize your call to sendNotificaitons in one place so you can put this while loop or any other logic you may want around notification sending on one place.

Hi,
first of all thanks … but why doesn’t it work some minutes / hours after initial start … Maybe isn’t working at the startup process because some libraries are not fully loaded, okay! Shouldn’t it work automatically after OH2 is fully come up? Is this because OH2 ignores the rule after that first error?

If my theory is right it would only not work for a minute or so after a restart of OH which is what it sounded like was going on based on your original description.

If it is not working for many minutes or hours after a restart then that isn’t the problem and I’ve no idea what it is.

OH2 will not ignore a rule after an error. In fact, if the same error is persisting then you should see the same error in the log file every time the rule triggers.

In the past all rules with notifications worked perfectly. I didn’t change anything (just updating OH2 to the newest build from time to time). I can’t figure out the point that behavior changed.

Always, after restarting OH2 i manuell have to reload all rule-files with notifications in it. Without this the rules are not working - never! Strange if i’am the only with this problem.

1 Like

Having the same issue with build 443.
Any way in which can debug or troubleshoot this?
Thanks!

I also had this problem.
Got fixed by updating java version to oracle 1.8.0-101

Regards, S

Hi,
till weeks i’m running

java version "1.8.0_101"
Java™ SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot™ Client VM (build 25.101-b13, mixed mode)

Problem is still there.

Same here. I updated to build 463 and now have to save the rules-file - after that notifications start to work again.

Hi,
Same problem here with OH2b4 build 477. Java version is 1.8.0_101. Any solution besides reloading the rules?
Also, in SmartHome Designer, I’m getting the warning "The method sendNotification(String, String) is undefined. How can I fix this?
Regards.

SmartHome Designer is a little broken right now. Depending on when you downloaded it it is more or less broken. For example, mine will not recognize any Items, actions, or Joda classes. The rules run fine though. There are issues already submitted so it should get fixed but I wouldn’t spend too much time worrying about it until they get fixed.

That’s what happens to me in 0.9, but in 0.8 that’s the only waring I get. It already happened in OpenHAB Designer.

sendNotification has never worked, see https://github.com/openhab/openhab/issues/1164.
So just ignore the warning and keep using it…

Ok, this issue is not important, I can live with it :slight_smile:
But, any idea about why sendNotification doesn’t work until rules are reloaded?
By the way, @Kai, I think this is the first time I talk to you: thank you very much for all your work, openHAB is awesome!!!

Updated Java to 1.8.0_111 and the problem still persists.

doenst the issue just say it does not work in the designer?

currently its not working in OH2 … it throws errors on execution … it did work until something like 10 days or so? it stopped with one the latest builds

Thanks for the kudos, glad you like it :slight_smile:

Ok, sorry, my comment was only about the syntax markers in the designer.

Hm, then I doubt that it is about any code change because I am not aware of any changes in the past months that could be related to this.

What exactly is the exception that is thrown?

I have just upgraded from OpenHab 2b4 to latest snapshot today. And I was getting notifications just before the upgrade, and nothing after. Sendmail is working in rules, and access via myOpenhab.org is working.

I am checking the logs, but don’t seem to be getting an exception. The only thing I see is:
2016-10-29 15:50:48.970 [WARN ] [o.myopenhab.internal.MyOpenHABClient] - Jetty request 5111 failed: null

but that doesn’t coincide with when a notification should be sent.

This is my rule:
rule “Back Roboguard Triggered"
when
Item Roboguard_Back received update OPEN
then
if (Roboguard_Notification.state == ON) {
sendNotification("myemail@emailco.com”, “Back Roboguard triggered”)
}
end

Hi, I have updated from OH2 B3 to OH2 Build #560 (past B4).

Notifications did not work in any of the two versions

I have made a base installation, without any bindings or extra things. Just the necesary for notifications to work.
The rule is triggered and no error is logged, but notifications are not send and not even logged at my.openhab.com.

Can you provide the command so as to increase verbosity of notifications module or myopenhab module. Thanks
Regards.

Hi @Kai,
No exception is thrown. We’re getting this error:

2016-11-03 13:05:47.579 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Some rule': An error occured during the script execution: The name 'sendNotification(<XStringLiteralImpl>,<XStringLiteralImpl>)' cannot be resolved to an item or type.

If you force the reloading of the rules by editing the file, notifications start to work.
Regards.