SendNotification API

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

SendNotification API

Postby ultratoto14 » Saturday 17 December 2016 13:53

For a dedicated scenario, i would like to use my domoticz to send notifications.

I looked at the API and didn't find any related to notification. I took then a look to the source code and saw the registered "sendnotification" command code.

Looking at the Cmd_SendNotification method, i found that using subject and body do almost what i want. But the message is sent to all the configured way of notification (NOTIFYALL).
Looking deeper, i found that the sendMessage is also used in the notification testing. You can here choose the subsystem but not the body and the subject.

I'm not able to provide a patch in C++ but it could be great to have a common sendNotification API that could be then used by the test system also.

Do you know another way to do it ?
Thanks for the help.
U.

Egregius
Posts: 1919
Joined: Thursday 09 April 2015 12:19
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: SendNotification API

Postby Egregius » Saturday 17 December 2016 14:16

What system do you want to use for notifcation?
Most of the services have their own api wich is mostly easy to implement.

ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Postby ultratoto14 » Saturday 17 December 2016 14:58

Hi Egregius,
I'm ok with the fact that most of the systems can be used externally. My concern is to have a configuration of notification systems in domoticz and use them independently. On any device, we can choose the enabled notification systems and we have two APIs that cover each a half of the feature, one enables the use of a specified system, the other one the posibility to define the subject and the body.

I do not know C++ but i will try to understanf how it works and propose a patch.

About your question, i use the domoticz app on my phone that send notifcations on my smartwatch, it could be one i want to use.

Egregius
Posts: 1919
Joined: Thursday 09 April 2015 12:19
Target OS: NAS (Synology & others)
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: SendNotification API

Postby Egregius » Saturday 17 December 2016 15:30

Don't understand what you mean by half of the feature.
I use telegram for all notification. Text is displayed on a Pebble, pictures not.

ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Postby ultratoto14 » Saturday 17 December 2016 16:45

Take a look there:

https://github.com/domoticz/domoticz/bl ... .cpp#L2521
Let you set up a subject and body but send the notification to every subsystem setup in domoticz

and there

https://github.com/domoticz/domoticz/bl ... .cpp#L3739
Let you test the notification subsystem but the subsject and body is not modifiable.

U.

ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Postby ultratoto14 » Monday 09 January 2017 12:07

Just took the time to try the compilation and slightly modify the code to enable the choice of the notification system based on the notification test call:

Code: Select all

From a284c3cf45641f559aa60db394edd848cb2b9f37 Mon Sep 17 00:00:00 2001
From: Ultratoto14 <[email protected]>
Date: Mon, 9 Jan 2017 11:00:23 +0100
Subject: [PATCH] Change notification API to allow choice of subsystem.

---
 main/WebServer.cpp |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/main/WebServer.cpp b/main/WebServer.cpp
index 53b421f..c94f613 100644
--- a/main/WebServer.cpp
+++ b/main/WebServer.cpp
@@ -2538,13 +2538,15 @@ namespace http {
       {
          std::string subject = request::findValue(&req, "subject");
          std::string body = request::findValue(&req, "body");
+         std::string subsystem = request::findValue(&req, "subsystem");
          if (
             (subject == "") ||
             (body == "")
             )
             return;
+         if (subsystem == "") subsystem = NOTIFYALL;
          //Add to queue
-         if (m_notifications.SendMessage(0, std::string(""), NOTIFYALL, subject, body, std::string(""), 1, std::string(""), false)) {
+         if (m_notifications.SendMessage(0, std::string(""), subsystem, subject, body, std::string(""), 1, std::string(""), false)) {
             root["status"] = "OK";
          }
          root["title"] = "SendNotification";
--
1.7.10.4


With this patch, you can use the API to send notifications using the domoticz configuration from the outside. The addition is the ability to choose the subsystem in: email,gcm,http,kodi,lms,nma,prowl,pushalot,pushbullet,pushover,pushsafer,clickatell

Note: if no subsystem is set, the default configuration is used and all the configured system are used (NOTIFYALL)
Best regards,
U
Attachments
notification.patch.txt
(1.13 KiB) Downloaded 5 times

User avatar
G3rard
Posts: 558
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.5877
Location: The Netherlands
Contact:

Re: SendNotification API

Postby G3rard » Tuesday 10 January 2017 1:28

Should it be used like this?
commandArray['SendNotification']='subject#body#0#subsystem'

Where 0 is the priority used with Pushover. See https://www.domoticz.com/wiki/Events

Are you going to make a pull request for this?
Ubuntu Server 14.04 | Domoticz v3.5877 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos

ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Postby ultratoto14 » Tuesday 10 January 2017 14:36

Hi G3rard,
it's not intended to be used in lua but more in an HTTP request like:

currently:
http:// <domoticz_ip>:8008/json.htm?type=command&param=sendnotification&subject=subject&body=thebody

With my patch: you can still use the previous one, the behavior is the same and you can add the subsystem like:
http:// <domoticz_ip>:8008/json.htm?type=command&param=sendnotification&subject=subject&body=thebody&subsystem=email

Even if it works on my install, I built this code by mimetic. So i do not think i'll do a pull request.
Best regards,
U.

ultratoto14
Posts: 10
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Postby ultratoto14 » Saturday 21 January 2017 19:52

Hi G3rard,
Did a pull request and now it's included in the latest beta.

Plan to do the same for the commandArray in lua. Need a fix to be accepted first, will keep you posted.

Best regards,
U.

User avatar
G3rard
Posts: 558
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.5877
Location: The Netherlands
Contact:

Re: SendNotification API

Postby G3rard » Saturday 21 January 2017 20:24

Thanks for implementing this!
Ubuntu Server 14.04 | Domoticz v3.5877 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos


Return to “Suggestions”

Who is online

Users browsing this forum: No registered users and 3 guests