Page 1 of 2
Stop sending notifications
Posted: Wednesday 03 November 2021 10:48
by piefje
Hi,
If have a script that checks the level in a pound, when the level is > 30 cm a switch will open.
In the switch i have a notification that the switch is activated. But it keeps sending notifications every 10 seconds.
How can i solve this, 1 notifaction that the switch is on en 1 that it close
return
{
on =
{
devices = {'Nivo'}
},
execute = function(domoticz, switch)
if (domoticz.devices('Nivo').distance < 30) then
domoticz.devices('schakelaar').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting filled',
domoticz.PRIORITY_HIGH)
elseif (domoticz.devices('Nivo').distance > 30) then
domoticz.devices('schakelaar').switchOff()
end
end
}
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 11:35
by erem
use the persistent data = { ... } section to record the state of the switch, and only send he message if the switch changes
look here
https://github.com/domoticz/domoticz/bl ... /README.md
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 12:02
by waltervl
Or use the notification button/function on the switch itself.
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 12:45
by piefje
waltervl wrote: ↑Wednesday 03 November 2021 12:02
Or use the notification button/function on the switch itself.
This wil also keeps sending msg on interval.
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 13:01
by kuifje
Piefje,
i dont know about these scripts but in blockly i was advised to use a user variable ( integer ) when i wanted to put my badkamer licht out after 60 minutes. Without it the counter kept counting.
When your pound level is <30 and the user variable is 0 turn on the valve and set the user variable to 1 and send an email.
When your pound level > 30 and the user variable is 1 turn of the valve and set the variable to 0 and send an email.
Maybe this will help
good luck
Kuifje
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 14:00
by waltervl
piefje wrote: ↑Wednesday 03 November 2021 12:45
waltervl wrote: ↑Wednesday 03 November 2021 12:02
Or use the notification button/function on the switch itself.
This wil also keeps sending msg on interval.
Not if you use the checkFirst().switchOn() option in DzVents when you switch the device. Then DzVents checks the state first and if in the same state it not switch and so not trigger a notification.
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 14:14
by piefje
Is there no option like this.
return
{
on =
{
devices = {'Nivo'}
},
IF (DOMOTICZ.DEVICES('schakelaar').state = (On) and
if (domoticz.devices('Nivo').distance < 30) then
end
return
execute = function(domoticz, switch)
if (domoticz.devices('Nivo').distance < 30) then
domoticz.devices('schakelaar').switchOn()
domoticz.notify('This rocks!',
'Turns out that it is getting filled',
domoticz.PRIORITY_HIGH)
elseif (domoticz.devices('Nivo').distance > 30) then
domoticz.devices('schakelaar').switchOff()
end
end
}
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 15:30
by waltervl
piefje wrote: ↑Wednesday 03 November 2021 14:14
Is there no option like this.
See
https://www.domoticz.com/wiki/DzVents:_ ... ng#Options
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 16:55
by piefje
I know the options but dont know how to put then in. I only want 1 notification when the pound get filles and 1 when it stops.
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 18:36
by waltervl
Yes
So instead of
domoticz.devices('schakelaar').switchOn()
use domoticz.devices('schakelaar').switchOn().checkfirst()
and instead of
domoticz.devices('schakelaar').switchOff()
Use
domoticz.devices('schakelaar').switchOff().checkFirst()
Delete the notification line in dzVents script.
On the widget of switch Schakelaar click on notification button and add a notification, see wiki page
https://www.domoticz.com/wiki/Managing_ ... ifications
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 19:07
by piefje
Well the problem stays, when sending notification direct, ik keep getting msg. until the switch is off
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 19:46
by piefje
Hm, i have now set the interval in esp to 300 sec, now it gives me every 5 min a msg, but thats not what i want.
If the pound level is >30 then switch must on en send a msg (one time)
If the pound level is <25 then switch must off end send a msg (one time)
Re: Stop sending notifications
Posted: Wednesday 03 November 2021 21:56
by waltervl
I do not understand why you get this notifications if you modified the dzVents script according my suggestions. Did you change that?
Re: Stop sending notifications
Posted: Thursday 04 November 2021 9:00
by piefje
Yes, the problem i think is that the sensor is sending information every 30 seconds to domoticz and that triggers the notification of the switch.
return
{
on =
{
devices = {'Nivo'}
},
execute = function(domoticz, switch)
if (domoticz.devices('Nivo').distance > 30) then
domoticz.devices('schakelaar').switchOn().checkfirst()
elseif (domoticz.devices('Nivo').distance < 25) then
domoticz.devices('schakelaar').switchOff().checkFirst()
end
end
Re: Stop sending notifications
Posted: Thursday 04 November 2021 11:27
by besix
Welcome
As the distance sensor reports every 30 seconds, it is better to use the timer, e.g. every 2 minutes. Then the script will not be triggered every 30 seconds. The whole thing might look like this
Code: Select all
return
{
on =
{
timer = {'every 2 minutes'},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = 'Nivo',
},
data =
{
notified =
{
initial = 0,
},
},
execute = function(dz, item)
local nivo = dz.devices('Nivo')
local switch = dz.devices('schakelaar')
if item.isTimer then
if nivo.distance < 30 then
dz.data.notified = dz.data.notified + 1
switch.switchOn().checkFirst()
if dz.data.notified == 1 and nivo.distance < 30 then
local DateTimePressed = os.date("%d/%m/%Y %X")
dz.notify('This rocks!','Turns out that it is getting filled' .. DateTimePressed .. ".", dz.PRIORITY_HIGH)
end
elseif nivo.distance > 30 and dz.data.notified > 0 then
switch.switchOff().checkFirst()
dz.data.notified = 0
local DateTimePressed = os.date("%d/%m/%Y %X")
dz.notify('This rocks!','Ok' .. DateTimePressed .. ".", dz.PRIORITY_HIGH)
end
end
end
}
Re: Stop sending notifications
Posted: Thursday 04 November 2021 12:45
by erem
what @besix just posted is EXACTLY what i meant in my first comment.
that WILL work.
Re: Stop sending notifications
Posted: Thursday 04 November 2021 13:43
by piefje
Thx, i only changed <30 to > 30
This works.
Re: Stop sending notifications
Posted: Thursday 04 November 2021 15:11
by waltervl
piefje wrote: ↑Thursday 04 November 2021 9:00
Yes, the problem i think is that the sensor is sending information every 30 seconds to domoticz and that triggers the notification of the switch.
It should not trigger the switch notifiy every 30 seconds or every 2 minutes as the switch is only switched on when it reaches your limit and it is not already switched on/off (due to the .checkFirst() function). Last update time should also not change unless really switched on/off.
Re: Stop sending notifications
Posted: Thursday 04 November 2021 16:32
by EddyG
Here is your answer. Takes some time to read and understand, but it works.
viewtopic.php?p=203641#p203641
Re: Stop sending notifications
Posted: Friday 12 November 2021 11:57
by rrozema
Why do we need all those fancy tricks for such a simple problem? Just a few ifs will do the work nicely. Plus, save your future self some time and put in error messages if one of the devices is not found.
Code: Select all
return
{
on =
{
devices = {'Nivo'}
},
execute = function(domoticz, switch)
local nivo = domoticz.devices('Nivo')
local schakelaar = domoticz.devices('schakelaar')
if nil == nivo then
domoticz.log( 'Device "Nivo" does not exist.', domoticz_LOG_ERROR)
elseif nil == schakelaar then
domoticz.log( 'Device "schakelaar" does not exist.', domoticz_LOG_ERROR)
elseif nivo.distance > 30 and not schakelaar.active then
local DateTimePressed = os.date("%d/%m/%Y %X")
domoticz.notify('This rocks!','Turns out that it is getting filled' .. DateTimePressed .. '.', domoticz.PRIORITY_HIGH)
schakelaar.switchOn()
elseif nivo.distance < 25 and schakelaar.active then
local DateTimePressed = os.date("%d/%m/%Y %X")
domoticz.notify('This rocks!','Ok' .. DateTimePressed .. '.', domoticz.PRIORITY_HIGH)
schakelaar.switchOff()
end
end
}