Sonoff RF Bridge with door contacts  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Sonoff RF Bridge with door contacts

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sonoff RF Bridge with door contacts

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Sonoff RF Bridge with door contacts

Post 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
jvrietveld
Posts: 15
Joined: Wednesday 25 December 2019 16:23
Target OS: Raspberry Pi / ODroid
Domoticz version: V2020.2
Location: Limburg
Contact:

Re: Sonoff RF Bridge with door contacts  [Solved]

Post 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.
Attachments
WIN_20200304_19_18_10_Pro.jpg
WIN_20200304_19_18_10_Pro.jpg (296.47 KiB) Viewed 848 times
Post Reply

Who is online

Users browsing this forum: HvdW and 1 guest