first commit
This commit is contained in:
22
dzVents/examples/calc temp delta.lua
Normal file
22
dzVents/examples/calc temp delta.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
--[[
|
||||
Assume you have two temperature sensors and a third dummy sensor that should be the
|
||||
difference of these two sensors (e.g. you want to see the difference between water temperature
|
||||
going into a radiator and the temperature of the water going out of it
|
||||
]]--
|
||||
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {'every 5 minutes'}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
local inTemp = domoticz.devices('Temp in').temperature
|
||||
local outTemp = domoticz.devices('Temp out').temperature
|
||||
local delta = outTemp - inTemp -- how much did the temperature drop?
|
||||
|
||||
-- update the dummy sensor
|
||||
domoticz.devices('Delta temp').updateTemperature(delta)
|
||||
|
||||
end
|
||||
}
|
||||
37
dzVents/examples/check battery levels.lua
Normal file
37
dzVents/examples/check battery levels.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local BATTERY_THRESHOLD = 10
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every hour'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
|
||||
local message = ''
|
||||
|
||||
-- first filter on low battery level
|
||||
local lowOnBat = domoticz.devices().filter(function(device)
|
||||
|
||||
local level = device.batteryLevel -- level is 0-100
|
||||
return (level ~= nil and -- not all devices have this attribute
|
||||
level <= BATTERY_THRESHOLD)
|
||||
|
||||
end)
|
||||
|
||||
-- then loop over the results
|
||||
lowOnBat.forEach(function(lowDevice)
|
||||
|
||||
message = message .. 'Device ' ..
|
||||
lowDevice.name .. ' is low on batteries (' .. tostring(lowDevice.batteryLevel) .. '), '
|
||||
|
||||
end)
|
||||
|
||||
if (message ~= '') then
|
||||
domoticz.notify('Low battery warning', message, domoticz.PRIORITY_NORMAL)
|
||||
domoticz.log('Low battery warning: ' .. message, domoticz.LOG_ERROR)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
36
dzVents/examples/check dead devices by desc.lua
Normal file
36
dzVents/examples/check dead devices by desc.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
--Check dead device using their description
|
||||
--This allow to configure device to be checked directly in domoticz GUI by accessing to device details and add "CDA:<delayInMinute>"
|
||||
--You have to active http fetching !
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every 60 minutes'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
local message=""
|
||||
|
||||
domoticz.devices().forEach(function(device)
|
||||
if (device.description ~= nil) then
|
||||
_, _, threshold = string.find(device.description,"CDA:(%d+)")
|
||||
if (threshold ~= nil) then
|
||||
local name = device.name
|
||||
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
|
||||
if ( minutes > tonumber(threshold)) then
|
||||
message = message .. 'Device ' ..
|
||||
name .. ' seems to be dead. No heartbeat for at least ' ..
|
||||
minutes .. ' minutes.\r'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
if (message ~= "") then
|
||||
domoticz.notify('Dead devices', message, domoticz.PRIORITY_HIGH)
|
||||
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
37
dzVents/examples/check dead devices.lua
Normal file
37
dzVents/examples/check dead devices.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
local devicesToCheck = {
|
||||
{ ['name'] = 'Sensor1', ['threshold'] = 30 },
|
||||
{ ['name'] = 'Sensor2', ['threshold'] = 30 },
|
||||
{ ['name'] = 'Bathroom temperature', ['threshold'] = 20 }
|
||||
}
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every 5 minutes'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
|
||||
local message = ""
|
||||
|
||||
for i, deviceToCheck in pairs(devicesToCheck) do
|
||||
local name = deviceToCheck['name']
|
||||
local threshold = deviceToCheck['threshold']
|
||||
local minutes = domoticz.devices(name).lastUpdate.minutesAgo
|
||||
|
||||
if ( minutes > threshold) then
|
||||
message = message .. 'Device ' ..
|
||||
name .. ' seems to be dead. No heartbeat for at least ' ..
|
||||
minutes .. ' minutes.\r'
|
||||
end
|
||||
end
|
||||
|
||||
if (message ~= "") then
|
||||
domoticz.email('Dead devices', message, 'me@address.nl')
|
||||
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
22
dzVents/examples/external_light.lua
Normal file
22
dzVents/examples/external_light.lua
Normal file
@@ -0,0 +1,22 @@
|
||||
-- External light
|
||||
-- turn lights on at sunset and back off at sunrise
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
timer = {
|
||||
'at sunset',
|
||||
'at sunrise'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, timer)
|
||||
-- external light switch name
|
||||
local external_light = domoticz.devices('External light')
|
||||
|
||||
if (timer.trigger == 'at sunset') then
|
||||
external_light.switchOn()
|
||||
else
|
||||
external_light.switchOff()
|
||||
end
|
||||
end
|
||||
}
|
||||
23
dzVents/examples/fake presence.lua
Normal file
23
dzVents/examples/fake presence.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- example script to fake the presence of people being at home
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
timer = {
|
||||
'at sunset',
|
||||
'at 23:30'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, timer)
|
||||
|
||||
if (timer.trigger == 'at sunset') then
|
||||
domoticz.devices('mySwitch').switchOn()
|
||||
domoticz.devices('anotherSwitch').dimTo(40)
|
||||
-- add whatever you want
|
||||
else
|
||||
-- switch off at a random moment after 23:30
|
||||
domoticz.devices('mySwitch').switchOff().withinMin(60)
|
||||
domoticz.devices('anotherSwitch').switchOff().withinMin(60)
|
||||
end
|
||||
end
|
||||
}
|
||||
27
dzVents/examples/garage door.lua
Normal file
27
dzVents/examples/garage door.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
--[[
|
||||
|
||||
From the domoticz examples online:
|
||||
http://www.domoticz.com/wiki/Event_script_examples
|
||||
|
||||
Send a warning when the garage door has been open for more than 10 minutes
|
||||
|
||||
]]
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every minute',
|
||||
}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
|
||||
local door = domoticz.devices('Garage door')
|
||||
|
||||
if (door.state == 'Open' and door.lastUpdate.minutesAgo > 10) then
|
||||
domoticz.notify('Garage door alert',
|
||||
'The garage door has been open for more than 10 minutes!',
|
||||
domoticz.PRIORITY_HIGH)
|
||||
end
|
||||
end
|
||||
}
|
||||
23
dzVents/examples/generic.lua
Normal file
23
dzVents/examples/generic.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
-- See README.md for instructions
|
||||
|
||||
return {
|
||||
active = false, -- set to true to activate this script
|
||||
on = {
|
||||
'My switch', -- name of the device
|
||||
'My sensor_Temperature', -- better not use but check device.attributeIsChanged('temperature')
|
||||
'My sensor',
|
||||
258, -- index of the device
|
||||
['timer'] = 'every minute', -- see readme for more options and schedules
|
||||
'PIR_*', -- triggers for all devices which name begins with PIR_
|
||||
},
|
||||
|
||||
execute = function(domoticz, mySwitch) -- see readme for what you get
|
||||
-- see readme for the entire domoticz object tree
|
||||
-- mySwitch is a Device object with all the properties of the device that was updated
|
||||
-- unless this is a timer script, then there is not second parameter to this execute function
|
||||
|
||||
if (mySwitch.state == 'On') then
|
||||
domoticz.notify('Hey!', 'I am on!', domoticz.PRIORITY_NORMAL)
|
||||
end
|
||||
end
|
||||
}
|
||||
19
dzVents/examples/get sensor values.lua
Normal file
19
dzVents/examples/get sensor values.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
devices = {
|
||||
'My sensor'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, mySensor)
|
||||
|
||||
if (mySensor.temperature > 50) then
|
||||
domoticz.notify('Hey!', 'The house might be on fire!!',
|
||||
domoticz.PRIORITY_EMERGENCY,
|
||||
domoticz.SOUND_SIREN)
|
||||
domoticz.log('Fire alert', domoticz.LOG_ERROR)
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
|
||||
25
dzVents/examples/intruder alert.lua
Normal file
25
dzVents/examples/intruder alert.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
return {
|
||||
|
||||
active = true,
|
||||
|
||||
on = {
|
||||
devices = {
|
||||
'PIR_*' -- all my motion detectors' name start with PIR_
|
||||
}
|
||||
},
|
||||
|
||||
execute = function(domoticz, detector)
|
||||
|
||||
if (detector.state == 'Motion' and domoticz.security ~= domoticz.SECURITY_DISARMED) then
|
||||
-- o dear
|
||||
|
||||
domoticz.setScene('intruder alert', 'On')
|
||||
|
||||
-- send notification
|
||||
domoticz.notify('Security breach', '',
|
||||
domoticz.PRIORITY_EMERGENCY,
|
||||
domoticz.SOUND_SIREN)
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
72
dzVents/examples/leak_detection.lua
Normal file
72
dzVents/examples/leak_detection.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
-- Water leak detection
|
||||
--
|
||||
-- assumptions:
|
||||
-- need 2 devices :
|
||||
-- a Water Flow devices name "Water_Flow"
|
||||
-- a Dummy Device type percentage "Leakage_Percent"
|
||||
--
|
||||
-- 1 / leakage "open valve"
|
||||
-- Every minute if a non-zero water flow is present, it increments a counter (Leakage_Percent)
|
||||
-- If the water flow is zero is that it leaks more continuously.
|
||||
-- A notification can be put on "Leakage_Percent" if >80% (80% = 80 minutes of continuous flow)
|
||||
--
|
||||
-- 2 / "micro continuous flow" (drip)
|
||||
-- in 24 hours one must have at least 2 hours without flow (detection 0.5 liters / hour is 4.5m3 / year)
|
||||
-- if not, "Leakage_Percent" is forced at 100%.
|
||||
|
||||
local FLOW_DEVICE = 'Water_Flow' -- Flow device
|
||||
local LEAK_DEVICE = 'Leakage_Percent' -- percent dummy device
|
||||
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every minute'
|
||||
}
|
||||
},
|
||||
data = {
|
||||
time_0_flow = { initial = 0 },
|
||||
total_time = { initial = 0 },
|
||||
},
|
||||
execute = function(domoticz)
|
||||
-- Flow in liter/minute
|
||||
local flow = tonumber(domoticz.devices(FLOW_DEVICE).rawData[1])
|
||||
-- Dummy device in %
|
||||
local leakage = domoticz.devices(LEAK_DEVICE)
|
||||
local time_with_flow = tonumber(leakage.rawData[1])
|
||||
local new_time_with_flow = time_with_flow
|
||||
|
||||
-- 1 / leakage "open valve"
|
||||
if (flow > 0) then
|
||||
domoticz.data.time_0_flow = 0 -- there is a flow
|
||||
new_time_with_flow = new_time_with_flow + 1 -- time with flow
|
||||
if (new_time_with_flow > 100) then
|
||||
new_time_with_flow = 100
|
||||
end
|
||||
else
|
||||
new_time_with_flow = 0
|
||||
domoticz.data.time_0_flow = domoticz.data.time_0_flow + 1 -- time without flow
|
||||
end
|
||||
|
||||
-- 2 / flight type "micro continuous flow" (drip)
|
||||
domoticz.data.total_time = domoticz.data.total_time + 1 -- time without since last 2 hours with no flow
|
||||
|
||||
if (domoticz.data.time_0_flow > 120) then
|
||||
-- 2 hours with no flow
|
||||
domoticz.data.total_time = 0
|
||||
elseif (domoticz.data.total_time > (60*24)) then
|
||||
-- 24 heures since last 2 hours with no flow
|
||||
new_time_with_flow = 100
|
||||
end
|
||||
-- log
|
||||
domoticz.log(new_time_with_flow .. ' minutes with flow ')
|
||||
domoticz.log(domoticz.data.time_0_flow .. ' minutes without flow ')
|
||||
domoticz.log(domoticz.data.total_time .. ' minutes without 2hrs without flow ')
|
||||
|
||||
-- update dummy device %
|
||||
if (time_with_flow ~= new_time_with_flow) then
|
||||
leakage.update(0,new_time_with_flow)
|
||||
end
|
||||
end
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
-- this script can be used in conjunction with the System-alive checker plug-in.
|
||||
-- the plugin pings a list of devices and creates switches for these devices
|
||||
-- the reason for this script is to not treat devices as dead immediately after they
|
||||
-- do not respond. More often than not, the second ping atempt does work. So only
|
||||
-- if the device has been not responding for a while AFTER it is been presumed dead
|
||||
-- then this script will notify you
|
||||
|
||||
-- put the names of these switches in the devicesToCheck list
|
||||
-- you may have to tweak the THRESHOLD depending on the check interval
|
||||
|
||||
|
||||
|
||||
|
||||
local THRESHOLD = 5 -- minutes
|
||||
local devicesToCheck = {'ESP8266 CV', 'ESP8266 ManCave', 'ESP8266 Watermeter'}
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
devices = {
|
||||
devicesToCheck
|
||||
},
|
||||
timer = {
|
||||
'every 5 minutes'
|
||||
}
|
||||
},
|
||||
data = {
|
||||
notified = { initial = {} }
|
||||
},
|
||||
execute = function(domoticz, item, triggerInfo)
|
||||
|
||||
if (item.isTimer) then
|
||||
|
||||
-- check all devices that are off and have not been updated in the past 5 minutes and have not been notified for
|
||||
for index, deviceName in pairs(devicesToCheck) do
|
||||
|
||||
local device = domoticz.devices(deviceName)
|
||||
|
||||
if (device.state == 'Off' and
|
||||
device.lastUpdate.minutesAgo >= THRESHOLD and
|
||||
domoticz.data.notified[deviceName] == false) then
|
||||
|
||||
domoticz.notify(deviceName .. ' is not responding anymore.',' ',domoticz.PRIORITY_HIGH)
|
||||
|
||||
-- make sure we only notify once for this device in this case
|
||||
domoticz.data.notified[deviceName] = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
-- it is the device that was triggered
|
||||
domoticz.data.notified[item.name] = false
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
}
|
||||
23
dzVents/examples/only run script when button pressed.lua
Normal file
23
dzVents/examples/only run script when button pressed.lua
Normal file
@@ -0,0 +1,23 @@
|
||||
return {
|
||||
|
||||
-- create a function for the active key, when the switch in Domoticz
|
||||
-- called 'script_blabla' is active, then the script is executed.
|
||||
|
||||
-- Note: keep this function really light weight because it is ALWAYS
|
||||
-- executed in every cycle, even when 'My switch' hasn't changed!!
|
||||
|
||||
active = function(domoticz)
|
||||
return (domoticz.devices('script_blabla').state == 'On')
|
||||
end,
|
||||
|
||||
on = {
|
||||
devices = {
|
||||
'My switch'
|
||||
}
|
||||
},
|
||||
|
||||
execute = function(domoticz, mySwitch)
|
||||
-- do some weird complicated stuff
|
||||
-- that takes quite some processing time ;-)
|
||||
end
|
||||
}
|
||||
100
dzVents/examples/plant watering notification.lua
Normal file
100
dzVents/examples/plant watering notification.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--[[
|
||||
This script can be used to get notification message when plant sensor exceed specified tresholds.
|
||||
It is specifically build to be used with the Xiaomi Mi Flora (https://www.domoticz.com/wiki/Mi_Flora_Bluetooth_LE), but can also be used with similar sensors
|
||||
|
||||
For the script to work correctly it is recommended your device names have the following convention:
|
||||
|
||||
Mi Flora - #0 Moisture
|
||||
Mi Flora - #0 Conductivity
|
||||
Mi Flora - #1 Moisture
|
||||
etc. etc.
|
||||
|
||||
This is the default device naming when Mi Flora plugin creates devices.
|
||||
|
||||
If you have another naming you need to adjust settings below.
|
||||
]]--
|
||||
|
||||
local configuration = {
|
||||
-- Define the different sensorTypes you want to get notified of
|
||||
sensorTypes = {
|
||||
moisture = {
|
||||
name = 'Moisture', -- Specify substring of name to match ie. "Mi Flora - #1 Moisture"
|
||||
property = 'percentage' -- property of dzVents device object to use
|
||||
},
|
||||
fertility = {
|
||||
name = 'Conductivity',
|
||||
property = 'percentage'
|
||||
}
|
||||
},
|
||||
|
||||
-- Define the plant names and the tresholds (min, max) per sensor below
|
||||
sensor0 = {
|
||||
plant = "Calamondin",
|
||||
tresholds = {
|
||||
moisture = {30, 60},
|
||||
fertility = {350, 2000}
|
||||
}
|
||||
},
|
||||
sensor1 = {
|
||||
plant = "Red pepper",
|
||||
tresholds = {
|
||||
moisture = {15, 60},
|
||||
fertility = {350, 2000}
|
||||
}
|
||||
},
|
||||
sensor2 = {
|
||||
plant = "Strawberries",
|
||||
tresholds = {
|
||||
moisture = {15, 60},
|
||||
fertility = {350, 2000}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
devices = {
|
||||
'Mi Flora*'
|
||||
}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_DEBUG
|
||||
},
|
||||
execute = function(domoticz, device)
|
||||
|
||||
local sensorNumber = string.match(device.name, "#(%d+)")
|
||||
local configKey = 'sensor' .. sensorNumber
|
||||
|
||||
if (configuration[configKey] == nil) then
|
||||
domoticz.log('No configuration defined for sensor #' .. sensorNumber, domoticz.LOG_INFO)
|
||||
return
|
||||
end
|
||||
|
||||
local sensorConfig = configuration[configKey]
|
||||
local tresholds = sensorConfig.tresholds
|
||||
local plantName = sensorConfig.plant
|
||||
|
||||
local function checkSensorTresholds(sensorType, notification)
|
||||
local sensorTypeConfig = configuration.sensorTypes[sensorType]
|
||||
if (tresholds[sensorType] == nil or not string.match(device.name, sensorTypeConfig.name)) then
|
||||
domoticz.log(string.format('No tresholds configured for sensor #%d or name does not match' , sensorNumber), domoticz.LOG_DEBUG)
|
||||
return
|
||||
end
|
||||
|
||||
local value = device[sensorTypeConfig.property]
|
||||
if (value < tresholds[sensorType][1] or value > tresholds[sensorType][2]) then
|
||||
notification = string.format(notification, plantName)
|
||||
notification = notification .. ' | ' .. string.format('%s = %d', sensorType, value)
|
||||
domoticz.notify('Plants', notification)
|
||||
domoticz.log(string.format('#%d %s exceeded', sensorNumber, sensorType), domoticz.LOG_DEBUG)
|
||||
else
|
||||
domoticz.log(string.format('#%d %s ok', sensorNumber, sensorType), domoticz.LOG_DEBUG)
|
||||
end
|
||||
end
|
||||
|
||||
checkSensorTresholds('moisture', '%s needs watering')
|
||||
checkSensorTresholds('fertility', '%s needs fertilization')
|
||||
|
||||
end
|
||||
}
|
||||
24
dzVents/examples/random night light.lua
Normal file
24
dzVents/examples/random night light.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local RANDOM_DELAY_MINS = 30
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'at sunset',
|
||||
'at 01:00'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz)
|
||||
|
||||
if (domoticz.security ~= domoticz.SECURITY_DISARMED) then
|
||||
|
||||
local light = domoticz.devices('Window light')
|
||||
|
||||
if (not light.bState) then -- i.e. state == 'On'
|
||||
light.switchOn().withinMin(RANDOM_DELAY_MINS)
|
||||
else
|
||||
light.switchOff().withinMin(RANDOM_DELAY_MINS)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
}
|
||||
14
dzVents/examples/respond to switch.lua
Normal file
14
dzVents/examples/respond to switch.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
devices = {
|
||||
'My switch'
|
||||
}
|
||||
},
|
||||
|
||||
execute = function(domoticz, mySwitch)
|
||||
if (mySwitch.state == 'On') then
|
||||
domoticz.notify('Hey!', 'I am on!', domoticz.PRIORITY_NORMAL)
|
||||
end
|
||||
end
|
||||
}
|
||||
20
dzVents/examples/schedule fish pond pump.lua
Normal file
20
dzVents/examples/schedule fish pond pump.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
['timer'] = {
|
||||
'at 8:30 on mon,tue,wed,thu,fri',
|
||||
'at 17:30 on mon,tue,wed,thu,fri',
|
||||
|
||||
-- weeekends are different
|
||||
'at sunset on sat, sun',
|
||||
'at sunrise on sat, sun'
|
||||
}
|
||||
},
|
||||
|
||||
execute = function(domoticz)
|
||||
|
||||
local pump = domoticz.devices('Pond')
|
||||
pump.toggleSwitch()
|
||||
|
||||
end
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
-- assumptions:
|
||||
-- the setpoint is set by a selector dummy device where the values are numeric temperatures
|
||||
-- but you can easily change it to a setpoint device
|
||||
|
||||
local BOILER_DEVICE = 'Boiler' -- switch device
|
||||
local SETPOINT_DEVICE = 'Setpoint' -- selector dummy device
|
||||
local TEMPERATURE_SENSOR = 'Temperature'
|
||||
local HYSTERESIS = 0.5 -- temp has to drop this value below setpoint before boiler is on again
|
||||
local SMOOTH_FACTOR = 3
|
||||
local LOGGING = true
|
||||
|
||||
return {
|
||||
on = {
|
||||
['timer'] = {
|
||||
'every minute',
|
||||
},
|
||||
devices = {
|
||||
TEMPERATURE_SENSOR,
|
||||
SETPOINT_DEVICE
|
||||
}
|
||||
},
|
||||
data = {
|
||||
temperatureReadings = { history = true, maxItems = SMOOTH_FACTOR }
|
||||
},
|
||||
active = true,
|
||||
execute = function(domoticz, item)
|
||||
|
||||
local avgTemp
|
||||
local temperatureReadings = domoticz.data.temperatureReadings
|
||||
local sensor = domoticz.devices(TEMPERATURE_SENSOR)
|
||||
local current = sensor.temperature
|
||||
local boiler = domoticz.devices(BOILER_DEVICE)
|
||||
local setpoint = domoticz.devices(SETPOINT_DEVICE)
|
||||
|
||||
-- first check if the sensor got a new reading or the setpoint was changed:
|
||||
if (item.isDevice) then
|
||||
|
||||
if (sensor.changed) then
|
||||
-- sensor just reported a new reading
|
||||
-- add it to the readings table
|
||||
|
||||
if (current ~= 0 and current ~= nil) then
|
||||
temperatureReadings.add(current)
|
||||
else
|
||||
-- no need to be here, weird state detected
|
||||
domoticz.log('Strange sensor reading.. skiping', domoticz.LOG_ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
elseif (domoticz.devices(SETPOINT_DEVICE).changed) then
|
||||
-- a new setpoint was set
|
||||
if LOGGING then domoticz.log('Setpoint was set to ' .. item.state) end
|
||||
else
|
||||
-- no business here, bail out...
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- now determine what to do
|
||||
if (setpoint.state == nil or setpoint.state == 'Off') then
|
||||
boiler.switchOff()
|
||||
return -- we're done here
|
||||
end
|
||||
|
||||
local setpointValue = tonumber(setpoint.state)
|
||||
|
||||
-- determine at which temperature the boiler should be
|
||||
-- switched on
|
||||
local switchOnTemp = setpointValue - HYSTERESIS
|
||||
|
||||
-- don't use the current reading but average it out over
|
||||
-- the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc
|
||||
local avgTemp = temperatureReadings.avg(1, SMOOTH_FACTOR, current) -- fallback to current when history is empty
|
||||
|
||||
if LOGGING then
|
||||
domoticz.log('Average: ' .. avgTemp, domoticz.LOG_INFO)
|
||||
domoticz.log('Setpoint: ' .. setpointValue, domoticz.LOG_INFO)
|
||||
domoticz.log('Current boiler state: ' .. boiler.state, domoticz.LOG_INFO)
|
||||
domoticz.log('Switch-on temperature: ' .. switchOnTemp, domoticz.LOG_INFO)
|
||||
end
|
||||
|
||||
if (avgTemp >= setpointValue and boiler.state == 'On') then
|
||||
if LOGGING then domoticz.log('Target temperature reached, boiler off') end
|
||||
boiler.switchOff()
|
||||
end
|
||||
|
||||
if (avgTemp < setpointValue and boiler.state == 'Off') then
|
||||
if (avgTemp < switchOnTemp) then
|
||||
if LOGGING then domoticz.log('Heating is required, boiler switched on') end
|
||||
boiler.switchOn()
|
||||
else
|
||||
if LOGGING then domoticz.log('Average temperature below setpoint but within hysteresis range, waiting for temperature to drop to ' .. switchOnTemp) end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
132
dzVents/examples/sunscreen.lua
Normal file
132
dzVents/examples/sunscreen.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
-- Define all the sensors which needs to be considered for the sunscreen to close
|
||||
local sensors = {
|
||||
temperature = {
|
||||
active = true,
|
||||
device = 'Temperature',
|
||||
closeRule = function(device)
|
||||
return device.temperature <= 15
|
||||
end
|
||||
},
|
||||
wind = {
|
||||
active = true,
|
||||
device = 'Wind',
|
||||
closeRule = function(device)
|
||||
return device.speed >= 50 or device.gust >= 150
|
||||
end
|
||||
},
|
||||
rain = {
|
||||
active = true,
|
||||
device = 'Rain',
|
||||
closeRule = function(device)
|
||||
return device.rainRate > 0
|
||||
end
|
||||
},
|
||||
rainExpected = {
|
||||
active = false,
|
||||
device = 'Rain expected', -- This needs to be a virtual sensor of type 'percentage'
|
||||
closeRule = function(device)
|
||||
return device.percentage > 15
|
||||
end
|
||||
},
|
||||
uv = {
|
||||
active = true,
|
||||
device = 'UV',
|
||||
closeRule = function(device)
|
||||
return device.uv <= 3
|
||||
end
|
||||
},
|
||||
lux = {
|
||||
active = false,
|
||||
device = 'Lux',
|
||||
closeRule = function(device)
|
||||
return device.lux <= 500
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
-- Define the name of your sunscreen device
|
||||
local sunscreenDevice = 'Sunscreen'
|
||||
|
||||
-- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
|
||||
local dryRun = false
|
||||
|
||||
-- Define the name of a virtual switch which you can use to disable the sunscreen automation script
|
||||
-- Set to false to disable this feature
|
||||
local manualOverrideSwitch = false
|
||||
|
||||
-- Minutes to wait after a sunscreen close before opening it again.
|
||||
local timeBetweenOpens = 10
|
||||
|
||||
return {
|
||||
active = true,
|
||||
on = {
|
||||
timer = {'every minute'}
|
||||
},
|
||||
logging = {
|
||||
level = domoticz.LOG_DEBUG,
|
||||
marker = 'Sunscreen'
|
||||
},
|
||||
execute = function(domoticz)
|
||||
|
||||
local function switchOn(sunscreen, message)
|
||||
if (sunscreen.state == 'Closed') then
|
||||
if (not dryRun) then
|
||||
sunscreen.switchOn()
|
||||
domoticz.notify('Sunscreen', message)
|
||||
end
|
||||
domoticz.log(message, domoticz.LOG_INFO)
|
||||
end
|
||||
end
|
||||
|
||||
local function switchOff(sunscreen, message)
|
||||
if (sunscreen.state == 'Open') then
|
||||
if (not dryRun) then
|
||||
sunscreen.switchOff()
|
||||
domoticz.notify('Sunscreen', message)
|
||||
end
|
||||
domoticz.log(message, domoticz.LOG_INFO)
|
||||
end
|
||||
end
|
||||
|
||||
if (manualOverrideSwitch and domoticz.devices(manualOverrideSwitch).state == 'On') then
|
||||
domoticz.log('Automatic sunscreen script is manually disabled', domoticz.LOG_DEBUG)
|
||||
return
|
||||
end
|
||||
|
||||
local sunscreen = domoticz.devices(sunscreenDevice)
|
||||
|
||||
-- Sunscreen must always be up during nighttime
|
||||
if (domoticz.time.isNightTime) then
|
||||
switchOff(sunscreen, 'Closing sunscreen, It is night')
|
||||
return
|
||||
end
|
||||
|
||||
-- Check all sensor tresholds and if any exeeded close sunscreen
|
||||
for sensorType, sensor in pairs(sensors) do
|
||||
|
||||
if (sensor['active'] == true) then
|
||||
|
||||
local device = domoticz.devices(sensor['device'])
|
||||
local closeRule = sensor['closeRule']
|
||||
|
||||
domoticz.log('Checking sensor: ' .. sensorType, domoticz.LOG_DEBUG)
|
||||
|
||||
if (closeRule(device)) then
|
||||
|
||||
switchOff(sunscreen, sensorType .. ' treshold exceeded, Sunscreen up')
|
||||
|
||||
domoticz.log(sensorType .. ' treshold exceeded', domoticz.LOG_DEBUG)
|
||||
-- Return early when we exeed any tresholds
|
||||
return
|
||||
end
|
||||
else
|
||||
domoticz.log('Sensor not active skipping: ' .. sensorType, domoticz.LOG_DEBUG)
|
||||
end
|
||||
end
|
||||
|
||||
-- All tresholds OK, sunscreen may be lowered
|
||||
if (sunscreen.lastUpdate.minutesAgo > timeBetweenOpens) then
|
||||
switchOn(sunscreen, 'Sun is shining, all thresholds OK, lowering sunscreen')
|
||||
end
|
||||
end
|
||||
}
|
||||
119
dzVents/examples/templates/All.lua
Normal file
119
dzVents/examples/templates/All.lua
Normal file
@@ -0,0 +1,119 @@
|
||||
-- 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 http responses
|
||||
httpResponses = {
|
||||
'some 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_DEBUG,
|
||||
marker = "Cool script"
|
||||
},
|
||||
|
||||
-- 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
|
||||
}
|
||||
18
dzVents/examples/templates/Bare.lua
Normal file
18
dzVents/examples/templates/Bare.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {},
|
||||
timer = {},
|
||||
variables = {},
|
||||
scenes = {},
|
||||
groups = {},
|
||||
security = {},
|
||||
httpResponses = {},
|
||||
customEvents = {},
|
||||
system = {},
|
||||
},
|
||||
data = {},
|
||||
logging = {},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
|
||||
end
|
||||
}
|
||||
20
dzVents/examples/templates/CustomEvents.lua
Normal file
20
dzVents/examples/templates/CustomEvents.lua
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.utils._.print(triggeredItem.data)
|
||||
else
|
||||
-- second parameter can be anything, number, string, boolean or table
|
||||
domoticz.emitEvent('MyEvent', 'Some data')
|
||||
end
|
||||
end
|
||||
}
|
||||
10
dzVents/examples/templates/Device.lua
Normal file
10
dzVents/examples/templates/Device.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {
|
||||
'myDevice'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, device)
|
||||
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
10
dzVents/examples/templates/Group.lua
Normal file
10
dzVents/examples/templates/Group.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
groups = {
|
||||
'myGroup'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, group)
|
||||
domoticz.log('Group ' .. group.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
38
dzVents/examples/templates/HTTPRequest.lua
Normal file
38
dzVents/examples/templates/HTTPRequest.lua
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
},
|
||||
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
|
||||
}
|
||||
10
dzVents/examples/templates/Scene.lua
Normal file
10
dzVents/examples/templates/Scene.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
scenes = {
|
||||
'myScene'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, scene)
|
||||
domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
10
dzVents/examples/templates/Security.lua
Normal file
10
dzVents/examples/templates/Security.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
security = {
|
||||
domoticz.SECURITY_ARMEDAWAY,
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, security)
|
||||
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
17
dzVents/examples/templates/System.lua
Normal file
17
dzVents/examples/templates/System.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
return {
|
||||
on = {
|
||||
system = {
|
||||
'start',
|
||||
'stop',
|
||||
'manualBackupFinished',
|
||||
'dailyBackupFinished',
|
||||
'hourlyBackupFinished',
|
||||
'monthlyBackupFinished'
|
||||
}
|
||||
},
|
||||
data = {},
|
||||
logger = {},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
domoticz.log('Domoticz has started')
|
||||
end
|
||||
}
|
||||
50
dzVents/examples/templates/Timer.lua
Normal file
50
dzVents/examples/templates/Timer.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
||||
11
dzVents/examples/templates/UserVariable.lua
Normal file
11
dzVents/examples/templates/UserVariable.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
return {
|
||||
on = {
|
||||
variables = {
|
||||
'myUserVariable'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, variable)
|
||||
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
|
||||
-- code
|
||||
end
|
||||
}
|
||||
16
dzVents/examples/templates/bare.lua
Normal file
16
dzVents/examples/templates/bare.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {},
|
||||
timer = {},
|
||||
variables = {},
|
||||
scenes = {},
|
||||
groups = {},
|
||||
security = {},
|
||||
httpResponses = {}
|
||||
},
|
||||
data = {},
|
||||
logger = {},
|
||||
execute = function(domoticz, triggeredItem)
|
||||
|
||||
end
|
||||
}
|
||||
105
dzVents/examples/templates/complete.lua
Normal file
105
dzVents/examples/templates/complete.lua
Normal file
@@ -0,0 +1,105 @@
|
||||
-- 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 http responses
|
||||
httpResponses = {
|
||||
'some callback string'
|
||||
}
|
||||
},
|
||||
|
||||
-- persistent data
|
||||
-- see documentation about persistent variables
|
||||
data = {
|
||||
myVar = { initial = 5 },
|
||||
myHistoryVar = { maxItems = 10 },
|
||||
},
|
||||
|
||||
-- custom logging level for this script
|
||||
logging = {
|
||||
level = domoticz.LOG_DEBUG,
|
||||
marker = "Cool script"
|
||||
},
|
||||
|
||||
-- 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
|
||||
}
|
||||
10
dzVents/examples/templates/device.lua
Normal file
10
dzVents/examples/templates/device.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
devices = {
|
||||
'myDevice'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, device)
|
||||
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
18
dzVents/examples/templates/global_data.lua
Normal file
18
dzVents/examples/templates/global_data.lua
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
|
||||
}
|
||||
}
|
||||
10
dzVents/examples/templates/group.lua
Normal file
10
dzVents/examples/templates/group.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
groups = {
|
||||
'myGroup'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, group)
|
||||
domoticz.log('Group ' .. group.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
10
dzVents/examples/templates/scene.lua
Normal file
10
dzVents/examples/templates/scene.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
scenes = {
|
||||
'myScene'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, scene)
|
||||
domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
10
dzVents/examples/templates/security.lua
Normal file
10
dzVents/examples/templates/security.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
return {
|
||||
on = {
|
||||
security = {
|
||||
domoticz.SECURITY_ARMEDAWAY,
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, security, info)
|
||||
domoticz.log('Security was triggered by ' .. security.trigger, domoticz.LOG_INFO)
|
||||
end
|
||||
}
|
||||
53
dzVents/examples/templates/timer.lua
Normal file
53
dzVents/examples/templates/timer.lua
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
|
||||
}
|
||||
11
dzVents/examples/templates/variable.lua
Normal file
11
dzVents/examples/templates/variable.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
return {
|
||||
on = {
|
||||
variables = {
|
||||
'myUserVariable'
|
||||
}
|
||||
},
|
||||
execute = function(domoticz, variable)
|
||||
domoticz.log('Variable ' .. variable.name .. ' was changed', domoticz.LOG_INFO)
|
||||
-- code
|
||||
end
|
||||
}
|
||||
Reference in New Issue
Block a user