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.
Post Reply
ultratoto14
Posts: 38
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

SendNotification API

Post by 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.

User avatar
Egregius
Posts: 2446
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: SendNotification API

Post by 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: 38
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by 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.

User avatar
Egregius
Posts: 2446
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: SendNotification API

Post by 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: 38
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by 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: 38
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by 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 43 times

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

Re: SendNotification API

Post by 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.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

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

Re: SendNotification API

Post by 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: 38
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by 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: 826
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: SendNotification API

Post by G3rard » Saturday 21 January 2017 20:24

Thanks for implementing this!
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

antares
Posts: 56
Joined: Saturday 24 September 2016 9:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Germany
Contact:

Re: SendNotification API

Post by antares » Monday 23 January 2017 9:58

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!

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

Re: SendNotification API

Post by ultratoto14 » Tuesday 24 January 2017 14:49

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'

antares
Posts: 56
Joined: Saturday 24 September 2016 9:25
Target OS: Raspberry Pi
Domoticz version: beta
Location: Germany
Contact:

Re: SendNotification API

Post by antares » Thursday 26 January 2017 13:41

Hello ultratoto,

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

yfaykya
Posts: 26
Joined: Wednesday 07 January 2015 20:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by yfaykya » Wednesday 26 April 2017 11:32

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.

Kifo
Posts: 2
Joined: Wednesday 22 March 2017 13:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: SendNotification API

Post by Kifo » Monday 04 September 2017 18:48

Sorry for my silly question, but how do I install the patch in my Raspberry Domotics system?

mvzut
Posts: 295
Joined: Thursday 12 November 2015 11:55
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Marum, The Netherlands
Contact:

SendNotification API

Post by mvzut » Tuesday 21 November 2017 8:26

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!
Raspberry Pi 2B - RFXtrx433 - Aeon Z-Stick gen5 - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - Sonos Connect & PLAY:1 - Kodi - Wall mounted tablet + Imperihome - MANY switches/sensors

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests