Page 1 of 1
Send Notification from Python Plugin
Posted: Sunday 08 October 2017 16:31
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?
Re: Send Notification from Python Plugin
Posted: Sunday 08 October 2017 22:12
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
Re: Send Notification from Python Plugin
Posted: Sunday 08 October 2017 22:25
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¶m=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
Re: Send Notification from Python Plugin
Posted: Monday 09 October 2017 11:56
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)
Re: Send Notification from Python Plugin
Posted: Monday 09 October 2017 17:10
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.