Send Notification from Python Plugin

Python and python framework

Moderator: leecollings

Post Reply
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Send Notification from Python Plugin

Post by febalci »

I have this alarm plugin. And i want to send a zone alarm as a notification to my smart phone; the message should include an integer between 1 to 16 as zone number, like: "Message: Alarm! Body: 12"

Is there a simpler way to send Custom http notification from a Domoticz Python Plugin? Do we need to use urllib2 with a JSON call?
If the only way is to use a JSON call, then is there any way to change User Variable in Domoticz, or is it again only with urllib2?
Logread
Posts: 228
Joined: Sunday 28 August 2016 7:48
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Send Notification from Python Plugin

Post by Logread »

febalci wrote: Sunday 08 October 2017 16:31 I have this alarm plugin. And i want to send a zone alarm as a notification to my smart phone; the message should include an integer between 1 to 16 as zone number, like: "Message: Alarm! Body: 12"

Is there a simpler way to send Custom http notification from a Domoticz Python Plugin? Do we need to use urllib2 with a JSON call?
If the only way is to use a JSON call, then is there any way to change User Variable in Domoticz, or is it again only with urllib2?
My own experience with the python plugin framework is that any action beyond a plugin’s own device(s) needs to go through the Json API (eg. User Variables, other devices, etc...). Then the choice of python module is yours... I am mostly using urllib
Deanm
Posts: 6
Joined: Tuesday 12 August 2014 0:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Send Notification from Python Plugin

Post by Deanm »

I asked a similar question last week. If you do a search for

‪Python Event: Email/Pushbullet Question‬.

It is only possible I have found using the API and JSON (Credit to ben53252642)

‪http://<domoticz_ip>:PORT/json.htm?type=command&param=sendnotification&subject=subject&body=thebody‬

‪I have tested it and it works. You could customise the subject and the body to what you require

Dean
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Send Notification from Python Plugin

Post by Dnpwwo »

@febalci,

The Python Plugin Framework is designed to allow easy addition of external hardware so does not expose other devices or user variables directly. The intention was to encourage creation of reusable plugins rather than ones that one worked with specific setups. Overall I think that approach is valid, with the exception of @Logread's "Smart Virtual Thermostat" plugin, I still haven't seen a valid use of access devices that a plugin does not own.

That said, no attempt was made to prevent people from accessing Domticz's web API directly if they really wanted to.

You can open an HTTP connection to Domoticz using urllib or the framework's in-built HTTP functionality (see https://github.com/domoticz/domoticz/bl ... es/HTTP.py)
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Send Notification from Python Plugin

Post by febalci »

OK, then i believe the best would be NOT to send notification from plugin itself; but send the ZONE alarm to a device or a variable, and use a script or notification itself to handle the notifications. Then, is there any way to update User Variable from a plugin framework, or i have to use JSON again? If yes, then i believe creating a Text Device within the plugin would be the best choice, since during an alarm i can set the zone number to the text device by UpdateDevice (..) , and with a simple commandArray['SendNotification']='subject#devicetext#0' in a script i can send the notification.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest