Page 1 of 1
emitEvent cancel
Posted: Friday 11 December 2020 13:01
by Number8
Hello,
If there a way to cancel for instance dz.emitEvent.afterMin(30)? (I guess no if I refer to documentation). If no what will happen if a new dz.emitEvent.afterMin(30) is set before 30 minutes in this case. Will it be replaced by the last emitEvent?
Thank you
dzVents 3.0.14
Re: emitEvent cancel
Posted: Friday 11 December 2020 15:14
by Number8
So I made some experiments. emitEventS are stacked in other words at some point in time they will all trigger a customEvent; Question then: is it conceivable to have a cancel Event?
Re: emitEvent cancel
Posted: Friday 11 December 2020 15:31
by waaren
Number8 wrote: Friday 11 December 2020 15:14
So I made some experiments. emitEvent are stacked in other words at some point in time they will all trigger a customEvent; Question then: is it conceivable to have a cancel Event?
Not likely to be implemented in domoticz but work around doable in dzVents. Can you give me an idea of how the event flow of a delayed customEvent that needs cancellation before triggering an event would look like? (How would it be emitted, -what should it do without cancellation and what would be a reason to cancel)
Re: emitEvent cancel
Posted: Friday 11 December 2020 15:54
by Number8
A rain detector has to trigger an alarm as soon as a drop of rain is detected. On the other hand I do not want to receive multiple detections when the rain stops and restarts again within a certain period of time. Here is the code I ended with (which is part of a bigger module)
Code: Select all
elseif item.isCustomEvent then
local rainResetDelay = 15 -- wait xx minutes before confirming that rain condition has dispeared. In order to avoid
local Time = require('Time')
if item.trigger == "rain" then
_d.rainUpdateTime = Time()
if item.data == "true" then
-- dz.log ("rain raised", dz.LOG_INFO)
if dz.devices(467).nValue ~= dz.ALERTLEVEL_RED then
dz.devices(467).updateAlertSensor(dz.ALERTLEVEL_RED, "Présence de pluie")
dz.notify ( "" , "Attention il pleut", dz.PRIORITY_NORMAL, "", "", dz.NSS_TELEGRAM)
end
else
dz.emitEvent("rainReset").afterMin(rainResetDelay)
-- dz.log ("rainReset raised", dz.LOG_INFO)
end
elseif item.trigger == "rainReset" then
-- dz.log ("rain reset trigger", dz.LOG_INFO)
local timeDifference = (Time().compare(_d.rainUpdateTime).minutes)
-- dz.log ("time difference = " .. tostring(timeDifference), dz.LOG_INFO)
if timeDifference >= rainResetDelay then
-- dz.log ("no rain for xxx minutes", dz.LOG_INFO)
if dz.devices(467).nValue ~= dz.ALERTLEVEL_GREEN then
dz.devices(467).updateAlertSensor(dz.ALERTLEVEL_GREEN, "Absence de pluie depuis " .. rainResetDelay .. " minutes")
dz.notify ( "" , "Absence de pluie a cessé depuis " .. rainResetDelay .. " minutes", dz.PRIORITY_NORMAL, "", "", dz.NSS_TELEGRAM)
end
end
end
end
Re: emitEvent cancel
Posted: Friday 11 December 2020 17:14
by waaren
Number8 wrote: Friday 11 December 2020 15:54
A rain detector has to trigger an alarm as soon as a drop of rain is detected. On the other hand I do not want to receive multiple detections when the rain stops and restarts again within a certain period of time. Here is the code I ended with (which is part of a bigger module)
If -d is short for dz.data then it seems you already have a work around?
btw. You store a complete time object in persistent data. If you don''t need it in other parts of the script you could store only
os.time() -- Number of seconds since epoch
which is only one integer and compare that later in the script again with the new os.time().
The attribute for alert type sensors is color.
Code: Select all
if dz.devices(467).color ~= dz.ALERTLEVEL_GREEN then
Re: emitEvent cancel
Posted: Sunday 13 December 2020 14:17
by Number8
If -d is short for dz.data then it seems you already have a work around?
Indeed
Thank you for the two tips