Page 1 of 1

Sonoff RF Bridge with door contacts

Posted: Tuesday 03 March 2020 21:33
by jvrietveld
I have a DzVents script for handeling the data from my door contacts. The sends a notification in the weekends if one of the doors opens and closes.
The problem is the data recieved from the door contacts on the Sonoff RF Bridge is retained to the last value.
When this script is activated during the given time periode it will send a notification every minute when triggered.
The data from RFBridgesensor.rawData[1] keeps its value. Is there an option to clear this of reset it?

Code: Select all

return {
	on = {
	    timer = { 'at 23:20-06:30 on fri,sat,sun,mon },
		devices = {'Sonoff RF Bridge'}
	},
	   logging = { 
        level = domoticz.LOG_INFO
    },
	execute = function(domoticz, device)
	    local RFBridgesensor = domoticz.devices(16)    --Sonoff RF Bridge
	    local blnContact = 0
		
	    if RFBridgesensor.rawData[1] == '11818094' then         	
		   dw1message = "Voordeur is geopend  \r"
                   blnContact = 1
	    elseif RFBridgesensor.rawData[1] == '11818087' then        
	         dw1message = "Voordeur is nu gesloten \r" 
                 blnContact = 1
            elseif RFBridgesensor.rawData[1] == '1515630' then            
	         dw1message = "Achterdeur is geopend \r"
                 blnContact = 1
             elseif RFBridgesensor.rawData[1] == '1515623' then         
                dw1message = "Achterdeur is nu gesloten \r"
                 blnContact = 1
            elseif RFBridgesensor.rawData[1] == '6108270' then           	
                 dw1message = "Garage inloopdeur is geopend  \r" 
                 blnContact = 1  
            end
	
        if blnContact == 1 then
           domoticz.notify(dw1Onderwerp, dw1message, domoticz.PRIORITY_HIGH, nil, nil, domoticz.NSS_PUSHOVER  )     --Verstuur een Pushover
	   blnContact = 0 --- reset value
	end
}
Best regards,
Johan

Re: Sonoff RF Bridge with door contacts

Posted: Tuesday 03 March 2020 22:39
by waaren
jvrietveld wrote: Tuesday 03 March 2020 21:33 I have a DzVents script for handeling the data from my door contacts. The sends a notification in the weekends if one of the doors opens and closes.
The problem is the data recieved from the door contacts on the Sonoff RF Bridge is retained to the last value.
Can you try below script ?
It only executes when the device is updated within the time set in the rule.

Code: Select all

return 
{
    on = 
    { 
        devices = 
        { 
             ['Sonoff RF Bridge'] = { 'at 23:20-06:30 on fri, sat, sun, mon' }, 
        }, 
    }, 

    logging = 
    { 
        level = domoticz.LOG_DEBUG,
        marker = 'Sonoff', 
    },

    execute = function(dz, item)

        local sonoffStates = 
        {    
            ['11818094'] =  'Voordeur is geopend',
            ['11818087'] =  'Voordeur is gesloten',
            ['1515630'] =  'Achterdeur is geopend',
            ['1515623'] =  'Achterdeur is gesloten',
            ['6108270'] =  'Garage inloopdeur is geopend',
        }

        local event = sonoffStates[item.rawData[1]] 
        
        if event ~= nil then
           dz.notify('sonoff', event, dz.PRIORITY_HIGH, nil, nil, dz.NSS_PUSHOVER  )     --Verstuur een Pushover
        else
            dz.log(item.rawData[1], dz.LOG_DEBUG)
        end
    end
}

Re: Sonoff RF Bridge with door contacts

Posted: Wednesday 04 March 2020 8:45
by jvrietveld
Hi Waaren,

Thank you for the script and the quick response. I have updated my script with your content and so far so good no more a load of notifications every minute. I will try it for a few days and keep you posted.

Best regards,
Johan

Re: Sonoff RF Bridge with door contacts  [Solved]

Posted: Wednesday 04 March 2020 19:30
by jvrietveld
The scripts is working very well as you can see (attached image). The array value sonoffStates makes it a lot easier to maintain. Thanks for this solution.