LUA Scripting

From ago control wiki
Revision as of 21:35, 16 November 2013 by Dinki (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 scripting is still in it's early stages so things may change in the future. For now, you must name your LUA script 'command.lua' and it must reside in the same directory as the agolua binary in /opt/agocontrol/bin. 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