Page 1 of 1

SendNotification API

Posted: Saturday 17 December 2016 12:53
by ultratoto14
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.

Re: SendNotification API

Posted: Saturday 17 December 2016 13:16
by Egregius
What system do you want to use for notifcation?
Most of the services have their own api wich is mostly easy to implement.

Re: SendNotification API

Posted: Saturday 17 December 2016 13:58
by ultratoto14
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.

Re: SendNotification API

Posted: Saturday 17 December 2016 14:30
by Egregius
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.

Re: SendNotification API

Posted: Saturday 17 December 2016 15:45
by ultratoto14
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.

Re: SendNotification API

Posted: Monday 09 January 2017 11:07
by ultratoto14
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

Re: SendNotification API

Posted: Tuesday 10 January 2017 0:28
by G3rard
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?

Re: SendNotification API

Posted: Tuesday 10 January 2017 13:36
by ultratoto14
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.

Re: SendNotification API

Posted: Saturday 21 January 2017 18:52
by ultratoto14
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.

Re: SendNotification API

Posted: Saturday 21 January 2017 19:24
by G3rard
Thanks for implementing this!

Re: SendNotification API

Posted: Monday 23 January 2017 8:58
by antares
Hello,

sorry, but I didn't yet get how to use it in the latest beta with LUA script. Could you please post an example, especially with highest priority (2) where you can set reminder time, etc. according to Pushover API? I want to use it to alert me when the alert system detects intrusion, and thus it should make a lot of noise.

Thanks!

Re: SendNotification API

Posted: Tuesday 24 January 2017 13:49
by ultratoto14
Hi antares,
my pull request have just been merged.

the lua command array is already complicated, i added subsystem:
commandArray['SendNotification']='subject#body#0#sound#extradata#subsystem'

- Subject is .. the subject
- Body is the content of the message
- 0 is the priority that you are talking about
- sound is the sound you want to use if you use pushover
- extradata can be used by some of the notification. Will not describe it

I added subsystem that is a ';' separated list of the notification subsystems you want this notification to bent through.
If you let subsystem empty, it will be sent through all the configured way, like in previous implementation.
The current available subsystems are:

gcm
http
kodi
lms
nma
prowl
pushalot
pushbullet
pushover
pushsafer

For example, if you want to use kodi and pushbullet, you need something like:
commandArray['SendNotification']='subject#body#0#sound#extradata#kodi;pushbullet'

Re: SendNotification API

Posted: Thursday 26 January 2017 12:41
by antares
Hello ultratoto,

thanks a lot. I will try it out. Great job!

Re: SendNotification API

Posted: Wednesday 26 April 2017 11:32
by yfaykya
Trying to change the image using extradata for a kodi notification.

I have tried :
commandArray['SendNotification']='Gates Opened#'..otherdevices['Gate Open Reason']..'#Image=/home/pi/domoticz-binary/www/images/door48open.png###kodi;pushbullet'

and also with IImage in the string. Any ideas?

Thanks.

Re: SendNotification API

Posted: Monday 04 September 2017 18:48
by Kifo
Sorry for my silly question, but how do I install the patch in my Raspberry Domotics system?

SendNotification API

Posted: Tuesday 21 November 2017 7:26
by mvzut
Just found out about this. Wow, works great, thanks! I never really needed it before because I had only set up one notification system. But now I also started using my Sonos speakers for notifications. This gave errors when a generic notification was sent from a LUA script, since the Sonos notification system (Python plugin version) expects special commands like a mp3 file name and a volume. Now these errors are gone!
yfaykya wrote:Trying to change the image using extradata for a kodi notification.

I have tried :
commandArray['SendNotification']='Gates Opened#'..otherdevices['Gate Open Reason']..'#Image=/home/pi/domoticz-binary/www/images/door48open.png###kodi;pushbullet'

and also with IImage in the string. Any ideas?

Thanks.
You may need to add another "#" yfaykya!

Re: SendNotification API

Posted: Monday 19 February 2018 7:21
by ben53252642
Thanks for adding this ultratoto14,

The curl command I'm using for sending messages using the http subsystem (see ultratoto14's post above for a list of subsystem options) is:

BASH:

Code: Select all

curl -s -k 'https://USERNAME:PASSWORD@IPADDRESS/json.htm?type=command&param=sendnotification&subsystem=http&subject=Testing%20Security&body=The%20main%20entrance%20door%20was%20just%20opened.'
PHP:

Code: Select all

shell_exec ("curl -s -k 'https://USERNAME:PASSWORD@IPADDRESS/json.htm?type=command&param=sendnotification&subsystem=http&subject=Testing%20Security&body=The%20main%20entrance%20door%20was%20just%20opened.'");
In case it helps anyone trying to do the same.

Note the curl command is set to allow unsigned SSL certificates.

Cheers :D

Re: SendNotification API

Posted: Monday 19 February 2018 9:03
by ycahome
ultratoto14 wrote: Saturday 21 January 2017 18: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.
Hello,

I ve edited the Wiki in order to be noticed by new users.

https://www.domoticz.com/wiki/Domoticz_ ... _Subsustem'

nice work!!

Re: SendNotification API

Posted: Monday 19 February 2018 9:11
by ben53252642
Spelling error in the wiki entry:

Use Notification Subsustem

Should be:

Use Notification Subsystem