Does the Python plugin framework have any command for sending a notification by email, similar to the DzVents "domoticz.notify" command ?
I want to send an email from a python plugin when a critical error occurs that requires attention.
I could create a JSON call with the "sendnotification" parameter, but am wondering whether there is a more elegant method.
how to send email from python plugin?
Moderator: leecollings
- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: how to send email from python plugin?
I dont think that should be a feature of a plugin.
You can create and update an alert device with the plugin and have the user decide what he wants to do with the alert (to what notification system it needs to go etc).
You can create and update an alert device with the plugin and have the user decide what he wants to do with the alert (to what notification system it needs to go etc).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
willemd
- Posts: 735
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: how to send email from python plugin?
Well, if the sole purpose of the plugin is to collect data and it determines that the communication is broken, why not send an alert ? I am making sure it only does it once, until the problem is solved and then reoccurs.
The route via a device is possible, maybe more flexible and less depending on presence of an email setup, but since I am maintaining the plugin I can just add that requirement to the documentation (or, maybe better, I can include a choice in the plugin startup config so the user can choose whether such alerts are desired or not).
In the meantime, I have tested the route via a JSON call and it works without problems.
/json.htm?type=command¶m=sendnotification&subject=SUBJECT&body=THEBODY
The route via a device is possible, maybe more flexible and less depending on presence of an email setup, but since I am maintaining the plugin I can just add that requirement to the documentation (or, maybe better, I can include a choice in the plugin startup config so the user can choose whether such alerts are desired or not).
In the meantime, I have tested the route via a JSON call and it works without problems.
/json.htm?type=command¶m=sendnotification&subject=SUBJECT&body=THEBODY
- waltervl
- Posts: 6676
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2025.1
- Location: NL
- Contact:
Re: how to send email from python plugin?
The plugin framework is designed to connect with external devices and update/command them, not to send notifications. Sending notifications is a function of Domoticz based on devices.
In the build-in hardware gateways there is also no option to send notifications from the hardware gateway.
Alternatively you can also put an Error message in the Domoticz log when this issue occurs and that (when configured) also sends an email notification.
When using Domoticz API calls in python plugins (there are more plugins that use that workaround) you also need to define the IP of the domoticz server in the plugin configuration as the plugin does not know it and can not query it.
In the build-in hardware gateways there is also no option to send notifications from the hardware gateway.
Alternatively you can also put an Error message in the Domoticz log when this issue occurs and that (when configured) also sends an email notification.
When using Domoticz API calls in python plugins (there are more plugins that use that workaround) you also need to define the IP of the domoticz server in the plugin configuration as the plugin does not know it and can not query it.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
FlyingDomotic
- Posts: 463
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: how to send email from python plugin?
You also can send directly mail using Python library from plugin.
-
willemd
- Posts: 735
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: how to send email from python plugin?
Thanks, I will use the Domoticz notification system. Below JSON call works fine.
Code: Select all
http://127.0.0.1:8080/json.htm?type=command¶m=sendnotification&subject='ATTENTION: communication timeout'&body='Please check and restore the connection 'Who is online
Users browsing this forum: No registered users and 1 guest