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.

Moderators: leecollings, remb0

Post Reply
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

SendNotification API

Post 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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: SendNotification API

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

Re: SendNotification API

Post 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.
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: SendNotification API

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

Re: SendNotification API

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

Re: SendNotification API

Post 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
Attachments
notification.patch.txt
(1.13 KiB) Downloaded 207 times
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: SendNotification API

Post 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?
Not using Domoticz anymore
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: SendNotification API

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

Re: SendNotification API

Post 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.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: SendNotification API

Post by G3rard »

Thanks for implementing this!
Not using Domoticz anymore
antares
Posts: 48
Joined: Saturday 24 September 2016 9:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Germany
Contact:

Re: SendNotification API

Post 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!
ultratoto14
Posts: 34
Joined: Thursday 27 October 2016 8:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: SendNotification API

Post 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'
antares
Posts: 48
Joined: Saturday 24 September 2016 9:25
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Germany
Contact:

Re: SendNotification API

Post by antares »

Hello ultratoto,

thanks a lot. I will try it out. Great job!
yfaykya
Posts: 8
Joined: Wednesday 07 January 2015 19:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: SendNotification API

Post 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.
Kifo
Posts: 10
Joined: Wednesday 22 March 2017 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: SendNotification API

Post by Kifo »

Sorry for my silly question, but how do I install the patch in my Raspberry Domotics system?
mvzut
Posts: 443
Joined: Thursday 12 November 2015 10:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

SendNotification API

Post 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!
Raspberry Pi 4 - RFXtrx433 - CC2531 Zigbee - Opentherm Gateway - P1 smart meter - Netatmo - Philips Hue - ELV Max! - ESP8266 DIY water meter - 6 x Sonos - 4 x IP cameras - Wall mounted tablet + Dashticz - Google Home integration - MANY switches/sensors
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: SendNotification API

Post 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
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
User avatar
ycahome
Posts: 248
Joined: Sunday 12 February 2017 10:55
Target OS: Linux
Domoticz version: lat Beta
Contact:

Re: SendNotification API

Post 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!!
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: SendNotification API

Post by ben53252642 »

Spelling error in the wiki entry:

Use Notification Subsustem

Should be:

Use Notification Subsystem
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest