Page 1 of 1

Washing Machine Door Signal

Posted: Saturday 19 October 2019 18:23
by paul402
I have one of those 433 Mhz Kerui door switches connected up to a relay which indicates when volts are no longer going through the door switch heater. Everything is working ok except my code. Instead of getting a delayed message that the door is "unlocked" I get the message immediately.
If I remove the "and washmachinedoor.lastUpdate.minutesAgo >= 5" delay then it all works fine without a delay.
Can anyone tell me where I am going wrong...

Code: Select all

return {
	on = {
		devices = {
			'WashMachine-D3'
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was changed ' .. device.state, domoticz.LOG_INFO)
		local washmachinedoor = domoticz.devices('WashMachine-D3')		
		if (washmachinedoor.state == 'Alarm' and washmachinedoor.lastUpdate.minutesAgo >= 5) then       
            domoticz.log('washmachine door is unlocked')
            msg="Wash Machine Door Unlocked" 
           domoticz.openURL('https://api.telegram.org/256900994&text=' .. msg)
            end
	end
}

Re: Washing Machine Door Signal

Posted: Saturday 19 October 2019 22:25
by hoeby
When the script is running.
What is the lastupdate time when you look to your device?

I have a few devices where the lastupdate isn't updatet when the switch modifies it's state.
When that happens, this could be the reason why >=5 is true and it send the notification.

Re: Washing Machine Door Signal

Posted: Saturday 19 October 2019 22:39
by waaren
paul402 wrote: Saturday 19 October 2019 18:23 Everything is working ok except my code. Instead of getting a delayed message that the door is "unlocked" I get the message immediately.
Adding extra log statements does give you more information on what is happening..

Would this help ?

Code: Select all

return {
    on = {
        devices = {
            'WashMachine-D3'
        }
    },
    
    execute = function(domoticz, device)
        domoticz.log('Device ' .. device.name .. ' was changed to ' .. device.state, domoticz.LOG_INFO)
        domoticz.log('Device ' .. device.name .. ' lastUpdate was '  .. device.lastUpdate.secondsAgo .. ' seconds ago.' , domoticz.LOG_INFO)
        
        if device.state == 'Alarm' then       
            domoticz.log('washmachine door is unlocked', domoticz.LOG_INFO)
            local msg = "Wash Machine Door Unlocked" 
            domoticz.openURL('https://api.telegram.org/256900994&text=' .. msg).afterMin(5)
        end
    end
}

Re: Washing Machine Door Signal

Posted: Monday 18 November 2019 12:08
by paul402
I finally got round to looking at this again. It works great and I've learnt something.
A big "Thank You" for your help!