first commit
This commit is contained in:
50
templates/All.Lua
Normal file
50
templates/All.Lua
Normal file
@@ -0,0 +1,50 @@
|
||||
--
|
||||
-- Domoticz passes information to scripts through a number of global tables
|
||||
--
|
||||
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
|
||||
-- otherdevices['yourotherdevicename'] = "On"
|
||||
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
|
||||
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
|
||||
--
|
||||
-- uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
-- uservariables['yourvariablename'] = 'Test Value'
|
||||
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
--
|
||||
-- other useful details are contained in the timeofday table
|
||||
-- timeofday['Nighttime'] = true or false
|
||||
-- timeofday['SunriseInMinutes'] = number
|
||||
-- timeofday['Daytime'] = true or false
|
||||
-- timeofday['SunsetInMinutes'] = number
|
||||
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
|
||||
--
|
||||
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
|
||||
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
|
||||
--
|
||||
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
|
||||
--
|
||||
commandArray = {}
|
||||
|
||||
print ("All based event fired");
|
||||
-- loop through all the devices
|
||||
for deviceName,deviceValue in pairs(otherdevices) do
|
||||
-- if (deviceName=='myDevice') then
|
||||
-- if deviceValue == "On" then
|
||||
-- print("Device is On")
|
||||
-- elseif deviceValue == "Off" then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Scene:MyScene'] = "Off"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
-- loop through all the variables
|
||||
for variableName,variableValue in pairs(uservariables) do
|
||||
-- if (variableName=='myVariable') then
|
||||
-- if variableValue == 1 then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Group:My Group'] = "Off AFTER 30"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
return commandArray
|
||||
76
templates/All.Python
Normal file
76
templates/All.Python
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Domoticz passes information to python scripts through global variables and the
|
||||
domoticz python module
|
||||
|
||||
The global variables in the script are:
|
||||
* changed_device: the current device that changed (object of Device)
|
||||
* changed_device_name: name of current device (same as changed_device.name)
|
||||
* is_daytime: boolean, true when it is is daytime
|
||||
* is_nighttime: same for the night
|
||||
* sunrise_in_minutes: integer
|
||||
* sunset_in_minutes: integer
|
||||
* user_variables: dictionary from string to value
|
||||
|
||||
A Device has a number of attributes and methods
|
||||
The attributes are:
|
||||
* id
|
||||
* name
|
||||
* type
|
||||
* sub_type
|
||||
* switch_type
|
||||
* n_value
|
||||
* n_value_string
|
||||
* s_value
|
||||
* last_update_string
|
||||
* last_update: datetime object
|
||||
|
||||
The methods are:
|
||||
* def last_update_was_ago(self, **kwargs):
|
||||
Arguments can be: days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]
|
||||
* def is_on(self):
|
||||
returns True when device is on
|
||||
* def is_off(self):
|
||||
returns True when device is ooff
|
||||
|
||||
* def on(self, after=None, reflect=False):
|
||||
turns device on, after is optional and are the number of seconds after which
|
||||
to turn the device on.
|
||||
If reflect is True, a next call to is_on will return True, while normally
|
||||
domoticz will first have to go through possible script before turning it on
|
||||
def off(self, after=None, reflect=False):
|
||||
simular to on()
|
||||
|
||||
uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
uservariables['yourvariablename'] = 'Test Value'
|
||||
uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
|
||||
other useful details are contained in the following global variables:
|
||||
* is_daytime
|
||||
* is_nighttime
|
||||
* sunrise_in_minutes
|
||||
* sunset_in_minutes
|
||||
* (TODO) security
|
||||
|
||||
Compare to Lua, instead of filling a commandArray, you change the status of a
|
||||
device by calling device.on() or device.off()
|
||||
|
||||
TODO: setting variables
|
||||
|
||||
Calling Python's print function will not print to the domoticz console, see below
|
||||
"""
|
||||
import DomoticzEvents as DE
|
||||
|
||||
DE.Log("Python: Changed: " + DE.changed_device.Describe())
|
||||
|
||||
if DE.changed_device_name == "Test":
|
||||
if DE.Devices["Test_Target"].n_value_string == "On":
|
||||
DE.Command("Test_Target", "Off")
|
||||
|
||||
if DE.Devices["Test_Target"].n_value_string == "Off":
|
||||
DE.Command("Test_Target", "On")
|
||||
|
||||
DE.Log("Python: Number of user_variables: " + str(len(DE.user_variables)))
|
||||
|
||||
# All user_variables are treated as strings, convert as necessary
|
||||
for key, value in DE.user_variables.items():
|
||||
DE.Log("Python: User-variable '{0}' has value: {1}".format(key, value))
|
||||
124
templates/All.dzVents
Normal file
124
templates/All.dzVents
Normal file
@@ -0,0 +1,124 @@
|
||||
-- Check the wiki for dzVents
|
||||
-- remove what you don't need
|
||||
return {
|
||||
|
||||
-- optional active section,
|
||||
-- when left out the script is active
|
||||
-- note that you still have to check this script
|
||||
-- as active in the side panel
|
||||
active = {
|
||||
|
||||
true, -- either true or false, or you can specify a function
|
||||
|
||||
--function(domoticz)
|
||||
-- return true/false
|
||||
--end
|
||||
},
|
||||
-- trigger
|
||||
-- can be a combination:
|
||||
on = {
|
||||
|
||||
-- device triggers
|
||||
devices = {
|
||||
-- scripts is executed if the device that was updated matches with one of these triggers
|
||||
'device name', -- device name
|
||||
'abc*', -- triggers for all devices which name begins with abc
|
||||
258, -- id
|
||||
},
|
||||
|
||||
-- timer riggers
|
||||
timer = {
|
||||
-- timer triggers.. if one matches with the current time then the script is executed
|
||||
'at 13:45',
|
||||
'at 18:37',
|
||||
'every 3 minutes on mon,tue,fri at 16:00-15:00',
|
||||
function(domoticz)
|
||||
-- return true or false
|
||||
end
|
||||
},
|
||||
|
||||
-- user variable triggers
|
||||
variables = {
|
||||
'myUserVariable'
|
||||
},
|
||||
|
||||
-- security triggers
|
||||
security = {
|
||||
domoticz.SECURITY_ARMEDAWAY,
|
||||
domoticz.SECURITY_ARMEHOME,
|
||||
},
|
||||
|
||||
-- scene triggers
|
||||
scenes = {
|
||||
'myScene'
|
||||
},
|
||||
|
||||
-- group triggers
|
||||
groups = {
|
||||
'myGroup'
|
||||
},
|
||||
|
||||
-- http responses
|
||||
httpResponses = {
|
||||
'some callback string'
|
||||
},
|
||||
|
||||
-- shell commmand responses
|
||||
shellCommandResponses = {
|
||||
'another callback string'
|
||||
},
|
||||
|
||||
-- system events
|
||||
system = {
|
||||
'start',
|
||||
'stop',
|
||||
'manualBackupFinished',
|
||||
'dailyBackupFinished',
|
||||
'hourlyBackupFinished',
|
||||
'monthlyBackupFinished'
|
||||
},
|
||||
|
||||
customEvents = {
|
||||
'myCustomEvent'
|
||||
}
|
||||
},
|
||||
|
||||
-- persistent data
|
||||
-- see documentation about persistent variables
|
||||
data = {
|
||||
myVar = { initial = 5 },
|
||||
myHistoryVar = { maxItems = 10 },
|
||||
},
|
||||
|
||||
-- custom logging level for this script
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = "template"
|
||||
},
|
||||
|
||||
-- actual event code
|
||||
-- the second parameter is depending on the trigger
|
||||
-- when it is a device change, the second parameter is the device object
|
||||
-- similar for variables, scenes and groups and httpResponses
|
||||
-- inspect the type like: triggeredItem.isDevice
|
||||
execute = function(domoticz, triggeredItem, info)
|
||||
--[[
|
||||
|
||||
The domoticz object holds all information about your Domoticz system. E.g.:
|
||||
|
||||
local myDevice = domoticz.devices('myDevice')
|
||||
local myVariable = domoticz.variables('myUserVariable')
|
||||
local myGroup = domoticz.groups('myGroup')
|
||||
local myScene = domoticz.scenes('myScene')
|
||||
|
||||
The device object is the device that was triggered due to the device in the 'on' section above.
|
||||
]] --
|
||||
|
||||
-- example
|
||||
|
||||
if (triggerdItem.active) then -- state == 'On'
|
||||
triggerdItem.switchOff().afterMin(2) -- if it is a switch
|
||||
domoticz.notify('Light info', 'The light ' .. triggerdItem.name .. ' will be switched off soon')
|
||||
end
|
||||
end
|
||||
}
|
||||
19
templates/Bare.dzVents
Normal file
19
templates/Bare.dzVents
Normal file
@@ -0,0 +1,19 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {},
|
||||
timer = {},
|
||||
variables = {},
|
||||
scenes = {},
|
||||
groups = {},
|
||||
security = {},
|
||||
httpResponses = {},
|
||||
shellCommandResponses = {},
|
||||
customEvents = {},
|
||||
system = {},
|
||||
},
|
||||
data = {},
|
||||
logging = {},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
|
||||
end
|
||||
}
|
||||
20
templates/CustomEvents.dzVents
Normal file
20
templates/CustomEvents.dzVents
Normal file
@@ -0,0 +1,20 @@
|
||||
return {
|
||||
on = {
|
||||
timer = {
|
||||
'every 5 minutes' -- just an example to trigger the event
|
||||
},
|
||||
customEvents = {
|
||||
'MyEvent' -- event triggered by emitEvent
|
||||
}
|
||||
},
|
||||
data = {},
|
||||
logging = {},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
if (triggeredItem.isCustomEvent) then
|
||||
domoticz.log(triggeredItem.data)
|
||||
else
|
||||
-- second parameter can be anything, number, string, boolean or table
|
||||
domoticz.emitEvent('MyEvent', 'Some data')
|
||||
end
|
||||
end
|
||||
}
|
||||
46
templates/Device.Lua
Normal file
46
templates/Device.Lua
Normal file
@@ -0,0 +1,46 @@
|
||||
--
|
||||
-- Domoticz passes information to scripts through a number of global tables
|
||||
--
|
||||
-- device changed contains state and svalues for the device that changed.
|
||||
-- devicechanged['yourdevicename'] = state
|
||||
-- devicechanged['svalues'] = svalues string
|
||||
--
|
||||
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
|
||||
-- otherdevices['yourotherdevicename'] = "On"
|
||||
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
|
||||
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
|
||||
--
|
||||
-- uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
-- uservariables['yourvariablename'] = 'Test Value'
|
||||
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
--
|
||||
-- other useful details are contained in the timeofday table
|
||||
-- timeofday['Nighttime'] = true or false
|
||||
-- timeofday['SunriseInMinutes'] = number
|
||||
-- timeofday['Daytime'] = true or false
|
||||
-- timeofday['SunsetInMinutes'] = number
|
||||
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
|
||||
--
|
||||
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
|
||||
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
|
||||
--
|
||||
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
|
||||
--
|
||||
commandArray = {}
|
||||
|
||||
-- loop through all the changed devices
|
||||
for deviceName,deviceValue in pairs(devicechanged) do
|
||||
print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
|
||||
-- if (deviceName=='myDevice') then
|
||||
-- if deviceValue == "On" then
|
||||
-- print("Device is On")
|
||||
-- elseif deviceValue == "Off" then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['another device name'] = "Off AFTER 10"
|
||||
-- commandArray['Scene:MyScene'] = "Off"
|
||||
-- commandArray['Group:My Group'] = "Off AFTER 30"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
return commandArray
|
||||
14
templates/Device.dzVents
Normal file
14
templates/Device.dzVents
Normal file
@@ -0,0 +1,14 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {
|
||||
'myDevice'
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, device)
|
||||
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
45
templates/ExecuteShellCommand.dzVents
Normal file
45
templates/ExecuteShellCommand.dzVents
Normal file
@@ -0,0 +1,45 @@
|
||||
local myResponse
|
||||
|
||||
return {
|
||||
on = {
|
||||
devices = {
|
||||
'test'
|
||||
},
|
||||
shellCommandResponses = {
|
||||
'myResponse', -- must match with the callback passed to the executeShellCommand
|
||||
},
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, item)
|
||||
|
||||
if (item.isDevice) then
|
||||
domoticz.executeShellCommand({
|
||||
command = 'speedtest-cli --json', -- just an example
|
||||
callback = 'myResponse', -- see shellCommandResponses above.
|
||||
timeout = 50, -- Max runtime 50 seconds
|
||||
})
|
||||
end
|
||||
|
||||
if (item.isShellCommandResponse) then
|
||||
|
||||
if (item.statusCode==0) then
|
||||
if (item.isJSON) then
|
||||
|
||||
domoticz.log('Download speed is '.. item.json.download,domoticz.LOG_INFO) -- just an example
|
||||
|
||||
-- update some device in Domoticz
|
||||
domoticz.devices('myTextDevice').updateText(someValue)
|
||||
end
|
||||
else
|
||||
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
|
||||
domoticz.log(item, domoticz.LOG_ERROR)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
14
templates/Group.dzVents
Normal file
14
templates/Group.dzVents
Normal file
@@ -0,0 +1,14 @@
|
||||
return {
|
||||
on = {
|
||||
groups = {
|
||||
'myGroup'
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, group)
|
||||
domoticz.log('Group ' .. group.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
42
templates/HTTPRequest.dzVents
Normal file
42
templates/HTTPRequest.dzVents
Normal file
@@ -0,0 +1,42 @@
|
||||
return {
|
||||
on = {
|
||||
timer = {
|
||||
'every 5 minutes' -- just an example to trigger the request
|
||||
},
|
||||
httpResponses = {
|
||||
'trigger' -- must match with the callback passed to the openURL command
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, item)
|
||||
|
||||
if (item.isTimer) then
|
||||
domoticz.openURL({
|
||||
url = 'http://somedomain/someAPI?param=1',
|
||||
method = 'GET',
|
||||
callback = 'trigger', -- see httpResponses above.
|
||||
})
|
||||
end
|
||||
|
||||
if (item.isHTTPResponse) then
|
||||
|
||||
if (item.ok) then
|
||||
if (item.isJSON) then
|
||||
|
||||
local someValue = item.json.someValue -- just an example
|
||||
|
||||
-- update some device in Domoticz
|
||||
domoticz.devices('myTextDevice').updateText(someValue)
|
||||
end
|
||||
else
|
||||
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
|
||||
domoticz.log(item, domoticz.LOG_ERROR)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
14
templates/Scene.dzVents
Normal file
14
templates/Scene.dzVents
Normal file
@@ -0,0 +1,14 @@
|
||||
return {
|
||||
on = {
|
||||
scenes = {
|
||||
'myScene'
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, scene)
|
||||
domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
50
templates/Security.Lua
Normal file
50
templates/Security.Lua
Normal file
@@ -0,0 +1,50 @@
|
||||
--
|
||||
-- Domoticz passes information to scripts through a number of global tables
|
||||
--
|
||||
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
|
||||
-- otherdevices['yourotherdevicename'] = "On"
|
||||
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
|
||||
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
|
||||
--
|
||||
-- uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
-- uservariables['yourvariablename'] = 'Test Value'
|
||||
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
--
|
||||
-- other useful details are contained in the timeofday table
|
||||
-- timeofday['Nighttime'] = true or false
|
||||
-- timeofday['SunriseInMinutes'] = number
|
||||
-- timeofday['Daytime'] = true or false
|
||||
-- timeofday['SunsetInMinutes'] = number
|
||||
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
|
||||
--
|
||||
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
|
||||
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
|
||||
--
|
||||
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
|
||||
--
|
||||
commandArray = {}
|
||||
|
||||
print ("Security based event fired");
|
||||
-- loop through all the devices
|
||||
for deviceName,deviceValue in pairs(otherdevices) do
|
||||
-- if (deviceName=='myDevice') then
|
||||
-- if deviceValue == "On" then
|
||||
-- print("Device is On")
|
||||
-- elseif deviceValue == "Off" then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Scene:MyScene'] = "Off"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
-- loop through all the variables
|
||||
for variableName,variableValue in pairs(uservariables) do
|
||||
-- if (variableName=='myVariable') then
|
||||
-- if variableValue == 1 then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Group:My Group'] = "Off AFTER 30"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
return commandArray
|
||||
14
templates/Security.dzVents
Normal file
14
templates/Security.dzVents
Normal file
@@ -0,0 +1,14 @@
|
||||
return {
|
||||
on = {
|
||||
security = {
|
||||
domoticz.SECURITY_ARMEDAWAY,
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, security)
|
||||
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
13
templates/Seurity.dzVents
Normal file
13
templates/Seurity.dzVents
Normal file
@@ -0,0 +1,13 @@
|
||||
return {
|
||||
active = false,
|
||||
on = {
|
||||
security = {
|
||||
domoticz.SECURITY_ARMEDAWAY,
|
||||
}
|
||||
},
|
||||
data = {},
|
||||
execute = function(domoticz, dummy, info)
|
||||
domoticz.log('Security was triggered by ' .. info.trigger, domoticz.LOG_INFO)
|
||||
-- code
|
||||
end
|
||||
}
|
||||
19
templates/System.dzVents
Normal file
19
templates/System.dzVents
Normal file
@@ -0,0 +1,19 @@
|
||||
return {
|
||||
on = {
|
||||
system = {
|
||||
'start',
|
||||
'stop',
|
||||
'manualBackupFinished',
|
||||
'dailyBackupFinished',
|
||||
'hourlyBackupFinished',
|
||||
'monthlyBackupFinished',
|
||||
},
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
domoticz.log('Domoticz has started')
|
||||
end
|
||||
}
|
||||
51
templates/Time.Lua
Normal file
51
templates/Time.Lua
Normal file
@@ -0,0 +1,51 @@
|
||||
--
|
||||
-- Domoticz passes information to scripts through a number of global tables
|
||||
--
|
||||
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
|
||||
-- otherdevices['yourotherdevicename'] = "On"
|
||||
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
|
||||
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
|
||||
--
|
||||
-- uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
-- uservariables['yourvariablename'] = 'Test Value'
|
||||
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
--
|
||||
-- other useful details are contained in the timeofday table
|
||||
-- timeofday['Nighttime'] = true or false
|
||||
-- timeofday['SunriseInMinutes'] = number
|
||||
-- timeofday['Daytime'] = true or false
|
||||
-- timeofday['SunsetInMinutes'] = number
|
||||
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
|
||||
--
|
||||
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
|
||||
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
|
||||
--
|
||||
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
|
||||
--
|
||||
|
||||
commandArray = {}
|
||||
|
||||
print ("Time based event fired");
|
||||
-- loop through all the devices
|
||||
for deviceName,deviceValue in pairs(otherdevices) do
|
||||
-- if (deviceName=='myDevice') then
|
||||
-- if deviceValue == "On" then
|
||||
-- print("Device is On")
|
||||
-- elseif deviceValue == "Off" then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Scene:MyScene'] = "Off"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
-- loop through all the variables
|
||||
for variableName,variableValue in pairs(uservariables) do
|
||||
-- if (variableName=='myVariable') then
|
||||
-- if variableValue == 1 then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['Group:My Group'] = "Off AFTER 30"
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
return commandArray
|
||||
54
templates/Timer.dzVents
Normal file
54
templates/Timer.dzVents
Normal file
@@ -0,0 +1,54 @@
|
||||
return {
|
||||
on = {
|
||||
timer = {
|
||||
'every minute', -- causes the script to be called every minute
|
||||
'every other minute', -- minutes: xx:00, xx:02, xx:04, ..., xx:58
|
||||
'every <xx> minutes', -- starting from xx:00 triggers every xx minutes (0 > xx < 60)
|
||||
'every hour', -- 00:00, 01:00, ..., 23:00 (24x per 24hrs)
|
||||
'every other hour', -- 00:00, 02:00, ..., 22:00 (12x per 24hrs)
|
||||
'every <xx> hours', -- starting from 00:00, triggers every xx hours (0 > xx < 24)
|
||||
'at 13:45', -- specific time
|
||||
'at *:45', -- every 45th minute in the hour
|
||||
'at 15:*', -- every minute between 15:00 and 16:00
|
||||
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
|
||||
'at 19:30-08:20', -- between 19:30 and 8:20 then next day
|
||||
'at 13:45 on mon,tue', -- at 13:45 only on Monday en Tuesday (english)
|
||||
'every hour on sat', -- you guessed it correctly
|
||||
'at sunset', -- uses sunset/sunrise info from Domoticz
|
||||
'at sunrise',
|
||||
'at sunset on sat,sun',
|
||||
'xx minutes before sunset',
|
||||
'xx minutes after sunset',
|
||||
'xx minutes before sunrise',
|
||||
'xx minutes after sunrise', -- guess ;-)
|
||||
'between aa and bb', -- aa/bb can be a time stamp like 15:44
|
||||
-- aa/bb can be sunrise/sunset
|
||||
-- aa/bb can be 'xx minutes before/after
|
||||
-- sunrise/sunset'
|
||||
'at nighttime', -- between sunset and sunrise
|
||||
'at daytime', -- between sunrise and sunset
|
||||
'at civildaytime', -- between civil twilight start and civil twilight end
|
||||
'at civilnighttime', -- between civil twilight end and civil twilight start
|
||||
'at daytime on mon,tue', -- between sunrise and sunset only on monday and tuesday
|
||||
|
||||
-- or if you want to go really wild:
|
||||
'at nighttime at 21:32-05:44 every 5 minutes on sat, sun',
|
||||
'every 10 minutes between 20 minutes before sunset and 30 minutes after sunrise on mon,fri,tue',
|
||||
|
||||
-- or just do it yourself:
|
||||
function(domoticz)
|
||||
-- you can use domoticz.time to get the current time
|
||||
-- note that this function is called every minute!
|
||||
-- custom code that either returns true or false
|
||||
return true
|
||||
end,
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, timer)
|
||||
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
53
templates/Timer.dzvents
Normal file
53
templates/Timer.dzvents
Normal file
@@ -0,0 +1,53 @@
|
||||
return {
|
||||
on = {
|
||||
timer = {
|
||||
'every minute', -- causes the script to be called every minute
|
||||
'every other minute', -- minutes: xx:00, xx:02, xx:04, ..., xx:58
|
||||
'every <xx> minutes', -- starting from xx:00 triggers every xx minutes
|
||||
-- (0 > xx < 60)
|
||||
'every hour', -- 00:00, 01:00, ..., 23:00 (24x per 24hrs)
|
||||
'every other hour', -- 00:00, 02:00, ..., 22:00 (12x per 24hrs)
|
||||
'every <xx> hours', -- starting from 00:00, triggers every xx
|
||||
-- hours (0 > xx < 24)
|
||||
'at 13:45', -- specific time
|
||||
'at *:45', -- every 45th minute in the hour
|
||||
'at 15:*', -- every minute between 15:00 and 16:00
|
||||
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
|
||||
'at 19:30-08:20', -- between 19:30 and 8:20 then next day
|
||||
'at 13:45 on mon,tue', -- at 13:45 only on Monday en Tuesday (english)
|
||||
'every hour on sat', -- you guessed it correctly
|
||||
'at sunset', -- uses sunset/sunrise info from Domoticz
|
||||
'at sunrise',
|
||||
'at sunset on sat,sun',
|
||||
'xx minutes before sunset',
|
||||
'xx minutes after sunset',
|
||||
'xx minutes before sunrise',
|
||||
'xx minutes after sunrise' -- guess ;-)
|
||||
'between aa and bb' -- aa/bb can be a time stamp like 15:44
|
||||
-- aa/bb can be sunrise/sunset
|
||||
-- aa/bb can be 'xx minutes before/after
|
||||
-- sunrise/sunset'
|
||||
'at nighttime', -- between sunset and sunrise
|
||||
'at daytime', -- between sunrise and sunset
|
||||
'at civildaytime', -- between civil twilight start and civil twilight end
|
||||
'at civilnighttime', -- between civil twilight end and civil twilight start
|
||||
'at daytime on mon,tue', -- between sunrise and sunset
|
||||
-- only on monday and tuesday
|
||||
|
||||
-- or if you want to go really wild:
|
||||
'at nighttime at 21:32-05:44 every 5 minutes on sat, sun',
|
||||
'every 10 minutes between 20 minutes before sunset and 30 minutes after sunrise on mon,fri,tue'
|
||||
|
||||
-- or just do it yourself:
|
||||
function(domoticz)
|
||||
-- you can use domoticz.time to get the current time
|
||||
-- note that this function is called every minute!
|
||||
-- custom code that either returns true or false
|
||||
return true
|
||||
end
|
||||
},
|
||||
},
|
||||
execute = function(domoticz, timer)
|
||||
domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
42
templates/UserVariable.Lua
Normal file
42
templates/UserVariable.Lua
Normal file
@@ -0,0 +1,42 @@
|
||||
--
|
||||
-- Domoticz passes information to scripts through a number of global tables
|
||||
--
|
||||
-- variable changed contains state and svalues for the variable that changed.
|
||||
-- uservariablechanged['yourvariablename'] = value
|
||||
--
|
||||
-- otherdevices, otherdevices_lastupdate and otherdevices_svalues are arrays for all devices:
|
||||
-- otherdevices['yourotherdevicename'] = "On"
|
||||
-- otherdevices_lastupdate['yourotherdevicename'] = "2015-12-27 14:26:40"
|
||||
-- otherdevices_svalues['yourotherthermometer'] = string of svalues
|
||||
--
|
||||
-- uservariables and uservariables_lastupdate are arrays for all user variables:
|
||||
-- uservariables['yourvariablename'] = 'Test Value'
|
||||
-- uservariables_lastupdate['yourvariablename'] = '2015-12-27 11:19:22'
|
||||
--
|
||||
-- other useful details are contained in the timeofday table
|
||||
-- timeofday['Nighttime'] = true or false
|
||||
-- timeofday['SunriseInMinutes'] = number
|
||||
-- timeofday['Daytime'] = true or false
|
||||
-- timeofday['SunsetInMinutes'] = number
|
||||
-- globalvariables['Security'] = 'Disarmed', 'Armed Home' or 'Armed Away'
|
||||
--
|
||||
-- To see examples of commands see: http://www.domoticz.com/wiki/LUA_commands#General
|
||||
-- To get a list of available values see: http://www.domoticz.com/wiki/LUA_commands#Function_to_dump_all_variables_supplied_to_the_script
|
||||
--
|
||||
-- Based on your logic, fill the commandArray with device commands. Device name is case sensitive.
|
||||
--
|
||||
commandArray = {}
|
||||
|
||||
-- loop through all the changed variables
|
||||
for variableName,variableValue in pairs(uservariablechanged) do
|
||||
print ("Variable based event fired on '"..variableName.."', value '"..tostring(variableValue).."'");
|
||||
-- if (variableName=='myVariable') then
|
||||
-- if variableValue == 1 then
|
||||
-- commandArray['a device name'] = "On"
|
||||
-- commandArray['another device name'] = "Off AFTER 10"
|
||||
-- commandArray['Variable:myVariable'] = 'new value'
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
||||
return commandArray
|
||||
15
templates/UserVariable.dzVents
Normal file
15
templates/UserVariable.dzVents
Normal file
@@ -0,0 +1,15 @@
|
||||
return {
|
||||
on = {
|
||||
variables = {
|
||||
'myUserVariable',
|
||||
},
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_INFO,
|
||||
marker = 'template',
|
||||
},
|
||||
execute = function(domoticz, variable)
|
||||
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
|
||||
-- code
|
||||
end
|
||||
}
|
||||
18
templates/global_data.dzVents
Normal file
18
templates/global_data.dzVents
Normal file
@@ -0,0 +1,18 @@
|
||||
-- this scripts holds all the globally persistent variables and helper functions
|
||||
-- see the documentation in the wiki
|
||||
-- NOTE:
|
||||
-- THERE CAN BE ONLY ONE global_data SCRIPT in your Domoticz install.
|
||||
|
||||
return {
|
||||
-- global persistent data
|
||||
data = {
|
||||
myGlobalVar = { initial = 12 }
|
||||
},
|
||||
|
||||
-- global helper functions
|
||||
helpers = {
|
||||
myHelperFunction = function(domoticz)
|
||||
-- code
|
||||
end
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user