Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendNotification not working inside DSL script in a rule #4142

Open
Thinqer77 opened this issue Mar 10, 2024 · 1 comment
Open

sendNotification not working inside DSL script in a rule #4142

Thinqer77 opened this issue Mar 10, 2024 · 1 comment
Labels
bug An unexpected problem or unintended behavior of the Core

Comments

@Thinqer77
Copy link

I’m struggling to get sendNotification to work inside a DSL script in a rule built using the UI. I’ve created a very simple rule that fires every minute and have added two actions: the first executes a one line DSL script containing the sendNotification command and the second action uses the built-in UI ‘send a notification’ option. Both target the same email address (I’ve double checked this!) I get the message from the UI ‘send a notification’ but not the one from inside the DSL script.

Issue more fully outlined and explored here:

https://community.openhab.org/t/sendnotification-not-working-inside-dsl-script-in-a-rule/153811/11

Expected Behavior

I should receive the notification on my mobile device from the sendNotification inside the DSL rule.

Current Behavior

Here is the rule definition:

Screenshot 2024-02-11 012255

Inside the script is the following (email address changed but matched the one I sign in to myOpenHAB with):

sendNotification("myemail@address.com", "Hello world!")

When the rule triggers I get the notification from the UI defined send notification, but not the one from the Rule DSL script. If I remove the UI send notification item then I still don't get a notification.

I then further tested by setting up the following:

  1. 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
  1. Rule defined in UI as above 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!")

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 (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.

I also created a Blockly based rule and it delivers the notification without issue.

Possible Solution

Steps to Reproduce (for Bugs)

See above for setup

Context

I'm trying to send a variable text string (based on the values of multiple items, including and excluding some depending on other items) and am trying to build it in Rule DSL scripting because the UI rule definition doesn't allow me to send variables or compose strings.

Your Environment

  • Version used: OpenHAB 3.3.0
  • Environment name and version (e.g. Chrome 111, Java 17, Node.js 18.15, ...): Docker container on a Synology (DSM 6.2.4-25556)
  • Operating System and version (desktop or mobile, Windows 11, Raspbian Bullseye, ...): n/a
  • PiHole running on network but issue still persists when it’s disabled
  • Openhab app is on an android phone (but still not seeing notifications on the Web page)
@Thinqer77 Thinqer77 added the bug An unexpected problem or unintended behavior of the Core label Mar 10, 2024
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/sendnotification-not-working-inside-dsl-script-in-a-rule/153811/19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

No branches or pull requests

2 participants