LUA Scripting

From ago control wiki
Jump to: navigation, search

LUA Scripting

LUA scripting capabilities have been added to ago control. Users can now write specialized scripts to add even more functionality. For more information on LUA visit the homepage and find even more information on the wiki.

LUA scripts should be stored in /etc/opt/agocontrol/lua/ with a filename of 'your_script_name.lua'. Note that you can name your scripts anything you like with the exception of 'helper.lua' as that filename is reserved.

Here is an example of controlling a switch using LUA:

command.lua:

for key,value in pairs(content) do print(key,value) end
if content.subject == "event.environment.timechanged" then
	if content.hour == 0 and content.minute == 39 then
		sendMessage('command=on','uuid=1e68018f-e43b-4279-a314-0a2c0c615d5c')
	end
end

The script checks if time is now 00:39 and then sends a message to turn on the device at uuid=1e68018f-e43b-4279-a314-0a2c0c615d5c.

Here is another example of how this can be expanded to automate thermostat setpoints throughout the day:

for key,value in pairs(content) do print(key,value) end
thermostat = 'uuid=76697596-8e50-487f-9217-91b6db4ad171'

setcool = function (temp)
        settemp = 'temperature=' ..temp
        sendMessage ('command=settemperature', 'mode=cool', settemp, thermostat)
end

setheat = function (temp)
        settemp = 'temperature=' ..temp
        sendMessage ('command=settemperature', 'mode=heat', settemp, thermostat)
end

if content.subject == "event.environment.timechanged" then
        -- Weekday
        if content.weekday < 6 then
                if content.hour == 05 and content.minute == 30 then
                        -- set heat 67 cool 76
                        setheat('67')
                        setcool('76')
                end
                if content.hour == 07 and content.minute == 30 then
                        -- set heat 65 cool 77
                        setheat('65')
                        setcool('77')
                end
                if content.hour == 16 and content.minute == 00 then
                        -- set heat 68 cool 77
                        setheat('68')
                        setcool('77')
                end
                if content.hour == 22 and content.minute == 00 then
                        -- set heat 66 cool 74
                        setheat('66')
                        setcool('74')
                end
        end

        -- Weekend
        if content.weekday >= 6 then
                if content.hour == 07 and content.minute == 30 then
                        -- set heat 67 cool 74
                        setheat('67')
                        setcool('74')
                end
                if content.hour == 08 and content.minute == 45 then
                        -- set heat 65 cool 77
                        setheat('65')
                        setcool('77')
                end

                if content.hour == 16 and content.minute == 00 then
                        -- set heat 68 cool 77
                        setheat('68')
                        setcool('77')
                end
                if content.hour == 22 and content.minute == 00 then
                        -- set heat 66 cool 74
                        setheat('66')
                        setcool('74')
                end
        end

end


To execute a script, cd to /opt/agocontrol/bin and type ./agolua

Personal tools