How to deal with a blinking input ?

Moderator: leecollings

Post Reply
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

How to deal with a blinking input ?

Post 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.
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post by habahabahaba »

You can try to use <LastUpdate> property.

if <YourGateDeviceStatus>.lastUpdate.secondsAgo > 15 then

-- send SMS

end
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to deal with a blinking input ?

Post 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 ?
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post by habahabahaba »

Example of your code?

And what is approximately time between blinkings?
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to deal with a blinking input ?

Post 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.
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post by habahabahaba »

Then I think you should start to learn scripts at first.
DzVents is prefered fo Domoticz, imho.
https://www.domoticz.com/wiki/Events
https://www.domoticz.com/wiki/Scripts#dzVents_Scripts
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post 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
}
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to deal with a blinking input ?

Post 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
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post 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?
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post 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.
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to deal with a blinking input ?

Post 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 ?
User avatar
habahabahaba
Posts: 215
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: How to deal with a blinking input ?

Post by habahabahaba »

No. Sometimes have such errors too.
Random time. No idea what is it :)
Michel13
Posts: 53
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to deal with a blinking input ?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests