how to use notifications
Moderators: leecollings, remb0
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
how to use notifications
Pushsafer is my app to send pushmessages to inform me about 'a status'.
I am facing next problem.
The availability of voltage on an endcircuit is monitored by a relay. If the circuit breaker of that end-circuit trips the relay goes to 'off'
The on/off signal is interfaced using an esp and published using MQTT to Domoticz.
This status is sent every 10 seconds for test and can later be set to longer time.
In domoticz the status is shown as an on/off device. Both On and Off positions are pushed to my phone by pushsafer.
As a matter of facts every (domoticz receives regular updates from esp) 10 seconds the status is pushed by pushsafer to my phone even if the status has not been changed.
Question: How can I prevent from pushing every 10 seconds same status. I profer to receive only a pushmessage once the status has changed.
Hopefully my problem is described well to understand.
-Bart
ps: the notification settings of device show up most right 'recover'. Can't find meaning. Any idea?
I am facing next problem.
The availability of voltage on an endcircuit is monitored by a relay. If the circuit breaker of that end-circuit trips the relay goes to 'off'
The on/off signal is interfaced using an esp and published using MQTT to Domoticz.
This status is sent every 10 seconds for test and can later be set to longer time.
In domoticz the status is shown as an on/off device. Both On and Off positions are pushed to my phone by pushsafer.
As a matter of facts every (domoticz receives regular updates from esp) 10 seconds the status is pushed by pushsafer to my phone even if the status has not been changed.
Question: How can I prevent from pushing every 10 seconds same status. I profer to receive only a pushmessage once the status has changed.
Hopefully my problem is described well to understand.
-Bart
ps: the notification settings of device show up most right 'recover'. Can't find meaning. Any idea?
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 602
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: how to use notifications
It's the updates that trigger.
You might write a small script to trigger the notifications.
It triggers on any change of state of mySwitch and inside the script it decides wheter it was switched from Off to On.
Code: Select all
return {
on = {
devices = { 'mySwitch' } -- Replace 'mySwitch' with the name of your switch
},
data = {
prevState = { initial = 'Off' } -- This stores the previous state of the switch
},
execute = function(domoticz, device)
-- Check if the state has changed from 'Off' to 'On'
if device.state == 'On' and domoticz.data.prevState == 'Off' then
-- Send a notification
domoticz.notify('Switch turned on', 'mySwitch has just been turned on', domoticz.PRIORITY_NORMAL)
end
-- Update the previous state
domoticz.data.prevState = device.state
end
}
Bugs bug me.
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
Thanks very much for your help. I am using dzVents for simple scripts where I never used the data{} strophe. So have to read the docu about this.
I didnot mention that in fact I have three of these monitors.
Can you tell me how to update your script for 3 devices?
Thanks!
Bart
I didnot mention that in fact I have three of these monitors.
Can you tell me how to update your script for 3 devices?
Thanks!
Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 602
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: how to use notifications
Code: Select all
return {
on = {
devices = { 'mySwitch1', 'mySwitch2', 'mySwitch3' } -- Add your switch names here
},
data = {
prevState = { initial = { mySwitch1 = 'Off', mySwitch2 = 'Off', mySwitch3 = 'Off' } } -- Initial states for all switches
},
execute = function(domoticz, device)
-- Check if the state has changed from 'Off' to 'On' for the specific device
if device.state == 'On' and domoticz.data.prevState[device.name] == 'Off' then
-- Send a notification for the specific switch
domoticz.notify('Switch turned on', device.name .. ' has just been turned on', domoticz.PRIORITY_NORMAL)
end
-- Update the previous state for the specific device
domoticz.data.prevState[device.name] = device.state
end
}
Bugs bug me.
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
Thanks again! This handles notifcation from 'off to on'.
Do I need two scripts once I also like notification for 'on to off'?
Do I need two scripts once I also like notification for 'on to off'?
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 602
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: how to use notifications
Try to understand the code and see how easy it is to change it to what you are asking.
You can have it with 6 different messages as well.
Tip:
Before changing code, save the running code as myScript - 1, copy the complete code and past it into a new script myScript - 2 and so on.
Whatever mess you make, you can always return to a running copy.
You can have it with 6 different messages as well.
Tip:
Before changing code, save the running code as myScript - 1, copy the complete code and past it into a new script myScript - 2 and so on.
Whatever mess you make, you can always return to a running copy.
Bugs bug me.
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
I'll dig in into it and will report back my findings.
Anyway, I m very happy with yr help so far.
-Bart
Anyway, I m very happy with yr help so far.
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 602
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: how to use notifications
This script doesn't use notifications. You can see the results in the log.
Above the output using the script below.
If you want to make your family and friends go crazy, then go ahead and send notifications for everything changing in your Domoticz setup.
Code: Select all
2025-03-13 22:11:04.712 Dummy: Light/Switch (mySwitch1)
2025-03-13 22:11:04.798 dzVents: Handling events for: "mySwitch1", value: "On"
2025-03-13 22:11:04.798 dzVents: ------ Start internal script: Script #1: Device: "mySwitch1 (Dummy)", Index: 599
2025-03-13 22:11:04.799 dzVents: Switch turned on. mySwitch1 has just been turned on
2025-03-13 22:11:04.801 dzVents: ------ Finished Script #1
2025-03-13 22:11:16.473 Status: User: admin (IP: 192.168.2.111) initiated a switch command (599/mySwitch1/Off)
2025-03-13 22:11:16.486 Dummy: Light/Switch (mySwitch1)
2025-03-13 22:11:16.636 dzVents: Handling events for: "mySwitch1", value: "Off"
2025-03-13 22:11:16.637 dzVents: ------ Start internal script: Script #1: Device: "mySwitch1 (Dummy)", Index: 599
2025-03-13 22:11:16.638 dzVents: Switch turned off. mySwitch1 has just been turned off
2025-03-13 22:11:16.640 dzVents: ------ Finished Script #1
Code: Select all
return {
on = {
devices = { 'mySwitch1', 'mySwitch2', 'mySwitch3' } -- Voeg hier je schakelaars toe
},
data = {
prevState = { initial = { mySwitch1 = 'Off', mySwitch2 = 'Off', mySwitch3 = 'Off' } } -- Beginstatussen van alle schakelaars
},
execute = function(domoticz, device)
-- Check of de status is veranderd van 'Off' naar 'On'
if device.state == 'On' and domoticz.data.prevState[device.name] == 'Off' then
-- Stuur een notificatie voor de specifieke schakelaar
domoticz.log('Switch turned on. '.. device.name .. ' has just been turned on', domoticz.LOG_INFO)
end
-- Check of de status is veranderd van 'On' naar 'Off'
if device.state == 'Off' and domoticz.data.prevState[device.name] == 'On' then
-- Stuur een notificatie voor de specifieke schakelaar
domoticz.log('Switch turned off. '.. device.name .. ' has just been turned off', domoticz.LOG_INFO)
end
-- Update de vorige status voor de specifieke schakelaar
domoticz.data.prevState[device.name] = device.state
end
}
Bugs bug me.
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
This is the updated script. I tested as far as possible but I think it does what is expected.
What is it used for? This domoticz application is installed in a scouting building.
Since the building has been used (newbuilt ) we face now and then a trip of 'groep 13'.
As there is not always anybody in the building it might take time to discover that failure.
If the failure happened then it's good to get an alert. Meanwhile, as I'm on distance, I'm happy to see someone fixed the power failure.
Another thing to monitor is the power supply towards an UPS which in turn supplies a local server for among others 'Salto locks'.
Very unlikely if nobody is aware of a coming power failure. (Once someone unplugged the UPS as he needed a socket outlet..... yes dumb, but it happened.
Then we once faced trip of a CB from feeding grid. That resulted in less pv-panel energy back into the grid so lost money... (there are 72 panels)
Hope this makes sense to you.
What is it used for? This domoticz application is installed in a scouting building.
Since the building has been used (newbuilt ) we face now and then a trip of 'groep 13'.
As there is not always anybody in the building it might take time to discover that failure.
If the failure happened then it's good to get an alert. Meanwhile, as I'm on distance, I'm happy to see someone fixed the power failure.
Another thing to monitor is the power supply towards an UPS which in turn supplies a local server for among others 'Salto locks'.
Very unlikely if nobody is aware of a coming power failure. (Once someone unplugged the UPS as he needed a socket outlet..... yes dumb, but it happened.
Then we once faced trip of a CB from feeding grid. That resulted in less pv-panel energy back into the grid so lost money... (there are 72 panels)
Hope this makes sense to you.
Code: Select all
return {
on = {
devices = { 'Groep13', 'UPS', 'L1', 'L2', 'L3' } -- Add your switch names here
},
data = {
prevState = { initial = { Groep13 = 'Off', UPS = 'Off', L1 = 'Off', L2 = 'Off', L3 = 'Off' } } -- Initial states for all switches
},
execute = function(domoticz, device)
-- Check if the state has changed from 'Off' to 'On' for the specific device
if device.state == 'On' and domoticz.data.prevState[device.name] == 'Off' then
-- Send a notification for the specific switch
domoticz.notify('Power Failure', device.name .. ' is getript', domoticz.PRIORITY_NORMAL)
elseif
device.state == 'Off' and domoticz.data.prevState[device.name] == 'On' then
-- Send a notification for the specific switch
domoticz.notify('Power failure solved', device.name .. ' is hersteld', domoticz.PRIORITY_NORMAL)
end
-- Update the previous state for the specific device
domoticz.data.prevState[device.name] = device.state
end
}
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
@ HvdW
So far the script does what's desired.
It's in use for almost two weeks now and then next Q rises:
On board vessels we had an alarmsystem with possibility to delay incoming alarms e.g. for tanklevels (due to vessels movements).
Is such a delay doable to get a more 'quit' system (preventing from false alarms) ?
-Bart
So far the script does what's desired.
It's in use for almost two weeks now and then next Q rises:
On board vessels we had an alarmsystem with possibility to delay incoming alarms e.g. for tanklevels (due to vessels movements).
Is such a delay doable to get a more 'quit' system (preventing from false alarms) ?
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waltervl
- Posts: 5785
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: how to use notifications
That should be in the not shown logic here that sets the state of the devices 'Groep13', 'UPS', 'L1', 'L2', 'L3'
How do you decide when eg L1 is OFF, if Current L1=0 A?
Then you could add in that script that current L1 should be 0 for X seconds or minutes.
You can store the value in persistent data.
See for an example this discussion: viewtopic.php?t=43024
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
-
- Posts: 602
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: how to use notifications
I am using the system alive check from the dzvents examples to get notifications.
Thank you dzVents developers for your great work.
I always fail to find the recent examples, here are some older ones.
Code: Select all
-- System-alive-check
-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval
local THRESHOLD = 10 -- minutes
local devicesToCheck =
{
'Power', 'Gas', -- 'Luftdaten',
}
return
{
on =
{
devices = devicesToCheck,
timer =
{
'every 6 minutes',
},
},
data =
{
notified = { initial = {} },
},
logging =
{
level = domoticz.LOG_ERROR, -- change from LOG_DEBUG to LOG_ERROR when script executes without problems
marker = 'notify',
},
execute = function(dz, item)
if item.isTimer then
for index, deviceName in ipairs(devicesToCheck) do
local device = dz.devices(deviceName)
dz.log('device name ' .. device.name, dz.LOG_DEBUG)
dz.log('device state ' .. device.state, dz.LOG_DEBUG)
dz.log('device lastUpdate ' .. device.lastUpdate.minutesAgo, dz.LOG_DEBUG)
dz.log('device notified ' .. tostring(dz.data.notified[deviceName]), dz.LOG_DEBUG)
if device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true then
-- verwijderd bij de if statement device.state == 'Off' and
dz.log('Idle device ' .. deviceName, dz.LOG_DEBUG)
dz.notify('notifyer', deviceName .. ' is not responding anymore.',dz.PRIORITY_HIGH)
dz.data.notified[deviceName] = true -- om deze regel, daar draait het om -> eenmalige notificatie
end
end
else
dz.data.notified[item.name] = false
end
end
}
--einde system alive check
I always fail to find the recent examples, here are some older ones.
Bugs bug me.
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
@Waltervl
There are relays supplied by power circuits to monitor.
The relay change-over contact controls input of esp which in turn controls the domoticz device via MQTT so no Amp value. Also using Amp value might be not always reliable in case of no consumers in use.
There are relays supplied by power circuits to monitor.
The relay change-over contact controls input of esp which in turn controls the domoticz device via MQTT so no Amp value. Also using Amp value might be not always reliable in case of no consumers in use.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waltervl
- Posts: 5785
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: how to use notifications
So how can these relay devices give a false result?
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
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
@waltervl
If relay has been energized power is there.
If power fails relay is deenergized
If relay has been energized power is there.
If power fails relay is deenergized
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
@HvdW
Thanks for the example. I had a quick view. Do I understand it notifies in case of a failure but not once the failure is solved?
Great link to all examples! I've never been aware of this treasure
Thanks for the example. I had a quick view. Do I understand it notifies in case of a failure but not once the failure is solved?
Great link to all examples! I've never been aware of this treasure

Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waltervl
- Posts: 5785
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: how to use notifications
So how can this create false alarms? If no false alarms no need to change the script.
And if the value is always true you do not even need a script but use the standard notifications functionality on the switch.
Edit: reading back the topic you should not have the esp send every x seconds an update to MQTT but only when the status has changed.....
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
-
- Posts: 395
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.7
- Location: Netherlands
- Contact:
Re: how to use notifications
Walter, all you say is true. But if the wifi is not that stable misinformation might be there once a single event would fire a notification. And yes, the wifi in the building is not reliable.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
- waltervl
- Posts: 5785
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: how to use notifications
If wifi is not reliable you also wont get the notification if there is a true situation.
You could also have the esp check if the MQTT message is received in mosquitto. If not (due to wifi issues) resend the message. Check the esp mqtt library how to do that as it should be a normal functionality.
You could also have the esp check if the MQTT message is received in mosquitto. If not (due to wifi issues) resend the message. Check the esp mqtt library how to do that as it should be a normal functionality.
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
Who is online
Users browsing this forum: No registered users and 1 guest