Page 1 of 1

Trigger Events in specific order based on last update.

Posted: Sunday 28 January 2018 11:44
by DanM
Hi,

I'm trying to write some code that 'retriggers' some of my motion sensors after 1 minute. They are of the type that simply stay on if motion continues (rather than re-send an on signal) and so if they are still on I want to re-send the on command.

The problem is that Id like to resend the commands in the same order as they were triggered.. so in order based upon their lastUpdate.secondsAgo. Im figuring the best way to do this is to read them into some sort of array and then sort it.. but Im at a total loss. Any help would be appreciated. Skeleton code below.

Code: Select all


return {
	active = true,
	on = {
		['timer'] = {
			'every minute'
		},
	},
	execute = function(domoticz, dummy, info)



--loop through the motion sensor devices
    domoticz.devices().filter(function(device)
	return (string.match(device.name, 'Motion')~=nil)
	end).forEach(function(device)

        --set the current sensor as 'sensor' variable		
        local sensor = domoticz.devices(device.name)	
        
        if sensor.lastUpdate.minutesAgo == 1 then
            if sensor.state == 'On' then
         -- add the sensor  and the lastUpdate.secondsAgo value to an array
        
            end  
        end
        
        
        --Loop through the array and set them on - thus preserving the trigger order. 
        --sensor.setState('On')  

    end)
	
	end
	}