Page 1 of 1
How to deal with a blinking input ?
Posted: Tuesday 19 March 2024 18:19
by Michel13
Domoticz 2024-4
RPI 3B
Hello,
I have an electric gate and I monitor its status in Domoticz from a contact on its control panel. This contact is closed when the gate is open and open when it is closed.
It blinks during the opening or closing process.
I would like to send notifications (SMS) to be informed of the status of the gate. This is where I have a problem because this blinking contact generates a notification at each blink.
I would like to know if it is possible to maintain the change of contact state for a specific time (say 10-20 sec) so that there is only one SMS sent each time the gate opens/closes. Or any other way to achieve that goal.
I can't do much in the gate control panel. It is therefore at the level of Domoticz that I wish to overcome this problem.
I am not at all familiar with the different scripts in Domoticz (LUA, dzvents, etc...). I tried with Blocky but it is limited and I couldn't find anything that allows me to maintain contact for a few seconds after its first state change.
I'm sure this problem has already been overcomed but I don't see how and I haven't found a similar case on the forum.
Is this feasible, and if so, how?
Thanks for your help.
Re: How to deal with a blinking input ?
Posted: Tuesday 19 March 2024 19:06
by habahabahaba
You can try to use <LastUpdate> property.
if <YourGateDeviceStatus>.lastUpdate.secondsAgo > 15 then
-- send SMS
end
Re: How to deal with a blinking input ?
Posted: Tuesday 19 March 2024 19:26
by Michel13
Thanks habahabahaba.
Interesting approach. That way, only the last status is triggering the SMS.The problem is I don't know how and where to apply this. Any exemple that could help me ?
Re: How to deal with a blinking input ?
Posted: Tuesday 19 March 2024 19:54
by habahabahaba
Example of your code?
And what is approximately time between blinkings?
Re: How to deal with a blinking input ?
Posted: Tuesday 19 March 2024 20:43
by Michel13
Well, I have no code at all. What I have tried to do unsuccessfully is through Blocky. As I said, althought I can understand them, I am not at ease with scripts.
Time betweeen blinking is less than 1 sec. So a lastupdate of 1 sec will do perfectly the job.
Re: How to deal with a blinking input ?
Posted: Wednesday 20 March 2024 6:52
by habahabahaba
Re: How to deal with a blinking input ?
Posted: Wednesday 20 March 2024 7:01
by habahabahaba
In my case:
Code: Select all
return {
on = {
devices = {60}, -- 'IDX of motion sensor
},
execute = function(domoticz, device)
local MotionSensor = domoticz.devices(60) -- veriable of the device
if (MotionSensor.state == 'On' ) then -- if motion is detected
if MotionSensor.lastUpdate.secondsAgo > 35 then -- checking last update in order to execute os.commanв not so often
-- some code you want
-- SEND SMS or to Telegram or smth else
end
end
end
}
Re: How to deal with a blinking input ?
Posted: Wednesday 20 March 2024 19:23
by Michel13
Thanks habahabahaba for this piece of script. It is good to start with.
From your exemple and the bit and pieces I have got in the links you gave me, I have create a script for my environment but it does not work as expected.
Code: Select all
return {
on = {
devices = {15}, -- 'IDX du status du portail
},
execute = function(domoticz, device)
local MotionSensor = domoticz.devices(15) -- variable of the device
if (MotionSensor.state == 'On' and MotionSensor.lastUpdate.secondsAgo > 2) then -- if motion is detected and 'On' for more than 2 sec
commandArray = {}
commandArray[1]={['OpenURL']='here is my URL and msg for the SMS' }
return commandArray
end
if (MotionSensor.state == 'Off' and MotionSensor.lastUpdate.secondsAgo > 2) then -- if motion is detected and 'Off' for more than 2 sec
commandArray = {}
commandArray[1]={['OpenURL']='here is my URL and msg for the SMS' }
return commandArray
end
end
}
device 15 is the ID of the blinking contact in Domoticz.
The URL for SMS is working like a charm when I send it in Firefox. It works also well for sending notifications of my NAS, so the problem is somewhere else.
It is most probably something wrong in my script
Re: How to deal with a blinking input ?
Posted: Wednesday 20 March 2024 19:47
by habahabahaba
if you are sending SMS via url try this
Code: Select all
return {
on = {
devices = {15}, -- 'IDX du status du portail
httpResponses = {
'Sending SMS' -- must match with Callback method
}
},
execute = function(domoticz, device)
local MotionSensor = domoticz.devices(15) -- variable of the device
if (MotionSensor.state == 'On' and MotionSensor.lastUpdate.secondsAgo > 2) then -- if motion is detected and 'On' for more than 2 sec
domoticz.openURL({
url = 'You_URL_here', --
method = 'GET',
callback = 'Sending SMS', -- see httpResponses above.
}).afterSec(0) -- here you can regulate the delay of opening URL in seconds
end
if (MotionSensor.state == 'Off' and MotionSensor.lastUpdate.secondsAgo > 2) then -- if motion is detected and 'Off' for more than 2 sec
domoticz.openURL({
url = 'You_URL_here', --
method = 'GET',
callback = 'Sending SMS', -- see httpResponses above.
}).afterSec(0) -- here you can regulate the delay of opening URL in seconds
end
end
}
Why do you use SMS ? Is it free service?
Re: How to deal with a blinking input ?
Posted: Wednesday 20 March 2024 19:55
by habahabahaba
And this code
Code: Select all
MotionSensor.lastUpdate.secondsAgo > 2
it does not mean that it has been ON for more than 2 seconds, but that its status (whether On or Off) changed more than 2 seconds ago.
Re: How to deal with a blinking input ?
Posted: Thursday 21 March 2024 13:03
by Michel13
habahabahaba wrote: ↑Wednesday 20 March 2024 19:47
Why do you use SMS ? Is it free service?
Yes, unlimited.
it does not mean that it has been ON for more than 2 seconds, but that its status (whether On or Off) changed more than 2 seconds ago.
It is the way I understand it.
I have tested your script : it works fine with the httpResponses, thanks !
However, I found strange errors in the log, not only on this script but for all the url attached to some devices. Althought SMS are received properly, each time I have a record saying :
Code: Select all
2024-03-21 12:46:26.633 Error: Error opening url: <My URL>
I don't know why. Any idea ? A missing parameter maybe ?
Re: How to deal with a blinking input ?
Posted: Thursday 21 March 2024 14:44
by habahabahaba
No. Sometimes have such errors too.
Random time. No idea what is it

Re: How to deal with a blinking input ?
Posted: Thursday 21 March 2024 15:13
by Michel13
Thank you for your feedback.
For me, it's all the time, regardless of device. If in the end the URL works, and unless there is a side effect that I don't know about, I won't dwell on it any further.
I have changed a little bit the script to make it lighter and clearer, also adjusted the delays to suit my need :
Code: Select all
return {
on = {
devices = {15}, -- 'IDX of the gate contact
httpResponses = {
'Sending SMS' -- must match with Callback method
}
},
execute = function(domoticz, device)
local MotionSensor = domoticz.devices(15) -- variable of the device
if (MotionSensor.lastUpdate.secondsAgo > 3) then
if (MotionSensor.state == 'On') then
domoticz.openURL({
url = 'sending SMS for gate open',
method = 'GET',
callback = 'Sending SMS',
}).afterSec(5)
else
domoticz.openURL({
url = 'sending SMS for gate closed',
method = 'GET',
callback = 'Sending SMS',
}).afterSec(5)
end
end
end
}
Thank you again for your help to solve this blinking transient state.