Ok, I set up the following:
- Text file rule in a file called ‘TestNotification.rules’ with the following rule in it:
rule "TestSendNotification"
when
Time cron "0 * * * * ? *"
then
logInfo("Alerts", "About to send my notification 2")
sendNotification("myemail@address.com", "Hello World 2!")
logInfo("Alerts", "My notification 2 sent!")
end
- Rule defined in UI as before but with the UI notification set up as well as the DSL script notification as follows:
logInfo("Alerts", "About to send my notification")
sendNotification("myemail@address.com", "Hello world!")
logInfo("Alerts", "My notification sent!")
Note that in the original log I sent, the entry saying ‘notification sent’ came from the logInfo I had added to the script - sorry for the confusion!
Anyway, here are the log entries I get with the above two rules set up:
2024-02-12 16:43:00.206 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger '0' of rule 'TestNotification-1' is triggered.
2024-02-12 16:43:00.207 [TRACE] [ore.internal.scheduler.SchedulerImpl] - Scheduled a task to run in 59 seconds.
2024-02-12 16:43:00.208 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'application/vnd.openhab.dsl.rule' with identifier: 331718c7-5873-48aa-9306-77fafe330dc3
2024-02-12 16:43:00.209 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/rules/TestNotification-1/state, source=RuleEngineImpl, type=RuleStatusInfoEvent, payload={"status":"RUNNING","statusDetail":"NONE"}, timestamp=1707756180208}
2024-02-12 16:43:00.209 [DEBUG] [time.internal.engine.DSLScriptEngine] - Script uses context 'TestNotification-1'.
2024-02-12 16:43:00.210 [TRACE] [automation.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2024-02-12 16:43:00.210 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.metrics.RuleMetric).
2024-02-12 16:43:00.211 [DEBUG] [.monitor.internal.metrics.RuleMetric] - Rule TestNotification-1 RUNNING - updating metric.
2024-02-12 16:43:00.213 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.EventLogger).
2024-02-12 16:43:00.213 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.rest.sse.internal.listeners.SseEventSubscriber).
2024-02-12 16:43:00.214 [TRACE] [.openhab.core.io.rest.SseBroadcaster] - broadcast to potential 2 sinks
2024-02-12 16:43:00.214 [TRACE] [internal.events.ThreadedEventHandler] - wait for event
2024-02-12 16:43:00.222 [INFO ] [org.openhab.core.model.script.Alerts] - About to send my notification 2
2024-02-12 16:43:00.223 [DEBUG] [b.io.openhabcloud.NotificationAction] - sending notification 'Hello World 2!' to user myemail@address.com
2024-02-12 16:43:00.223 [DEBUG] [o.openhabcloud.internal.CloudService] - Sending message 'Hello World 2!' to user id myemail@address.com
2024-02-12 16:43:00.224 [DEBUG] [io.openhabcloud.internal.CloudClient] - No connection, notification is not sent
2024-02-12 16:43:00.224 [INFO ] [org.openhab.core.model.script.Alerts] - My notification 2 sent!
2024-02-12 16:43:00.225 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'TestNotification-1' is executed.
2024-02-12 16:43:00.225 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/rules/TestNotification-1/state, source=RuleEngineImpl, type=RuleStatusInfoEvent, payload={"status":"IDLE","statusDetail":"NONE"}, timestamp=1707756180225}
2024-02-12 16:43:00.636 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger '1' of rule 'afd0b389b6' is triggered.
2024-02-12 16:43:00.636 [TRACE] [ore.internal.scheduler.SchedulerImpl] - Scheduled a task to run in 59 seconds.
2024-02-12 16:43:00.636 [INFO ] [org.openhab.core.model.script.Alerts] - About to send my notification
2024-02-12 16:43:00.637 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Event [topic=openhab] {topic=openhab/rules/afd0b389b6/state, source=RuleEngineImpl, type=RuleStatusInfoEvent, payload={"status":"RUNNING","statusDetail":"NONE"}, timestamp=1707756180636}
2024-02-12 16:43:00.637 [DEBUG] [b.io.openhabcloud.NotificationAction] - sending notification 'Hello world!' to user myemail@address.com
2024-02-12 16:43:00.637 [DEBUG] [o.openhabcloud.internal.CloudService] - Sending message 'Hello world!' to user id myemail@address.com
2024-02-12 16:43:00.637 [TRACE] [automation.internal.RuleEventFactory] - creating ruleEvent of type: RuleStatusInfoEvent
2024-02-12 16:43:00.637 [DEBUG] [io.openhabcloud.internal.CloudClient] - No connection, notification is not sent
2024-02-12 16:43:00.637 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.metrics.RuleMetric).
2024-02-12 16:43:00.638 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.monitor.internal.EventLogger).
2024-02-12 16:43:00.638 [DEBUG] [.monitor.internal.metrics.RuleMetric] - Rule afd0b389b6 RUNNING - updating metric.
2024-02-12 16:43:00.638 [INFO ] [org.openhab.core.model.script.Alerts] - My notification sent!
2024-02-12 16:43:00.638 [TRACE] [ab.core.internal.events.EventHandler] - Delegate event to subscriber (class org.openhab.core.io.rest.sse.internal.listeners.SseEventSubscriber).
2024-02-12 16:43:00.638 [TRACE] [internal.events.ThreadedEventHandler] - wait for event
2024-02-12 16:43:00.638 [TRACE] [.openhab.core.io.rest.SseBroadcaster] - broadcast to potential 2 sinks
2024-02-12 16:43:00.638 [DEBUG] [o.openhabcloud.internal.CloudService] - Sending message 'This is a notification from the UI action' to user id myemail@address.com
2024-02-12 16:43:00.639 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'afd0b389b6' is executed.
2024-02-12 16:43:00.641 [TRACE] [internal.events.ThreadedEventHandler] - inspect event: org.osgi.service.event.Eve
The first block of the log shows the text file based rule running. You can see there are two lines in there, one saying ‘sending notification’ and one saying ‘Sending message’, which seems a bit odd. In any case, the next line says no connection as before (then my logInfo line gets inserted).
The second block is for the UI defined rule and it also has the two ‘sending Notification’ and ‘Sending message’ lines and the ‘no connection’ message (all of which I assume relate to the script based action, which is triggered first). Then a few lines later the UI defined message gets sent with a log entry of ‘Sending message’ but not followed with a ‘no connection’ error.
I don’t get any of the notifications from the two script based rules but I do get the one from the UI defined one. I need to use the script based one as I want to include variable text in the message depending on the state of certain items which isn’t possible using the UI defined notification.
Do I need to create a connection of some sort before using the sendNotification command?
Not sure I’m much further along but maybe the above can provide some insight to someone?