Trigger Events in specific order based on last update.

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

Moderator: leecollings

Post Reply
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Trigger Events in specific order based on last update.

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

Who is online

Users browsing this forum: No registered users and 1 guest