I need a bit of help to modify this script which i've found here : https://domoticaboard.nl/index.php?topic=44.0
The script is running, but i like to trigger more devices then the one now
How can i add a list of devices that will be switch by the script
So far i know you can do it with the funcrion "pairs"
Code: Select all
-- Define all the sensors which needs to be considered for the sunscreen to close
local sensors = {
rain = {
active = true,
device = 'RegenData',
closeRule = function(device)
return device.rainRate > 0
end
}
}
local sunscreenDevice = 'TestSwitch' -- Define the name of your sunscreen device
local dryRun = false -- Enable dry run mode to test the sunscreen script without actually activating the sunscreen
return {
active = true,
on = {
--timer = {'every minute'},
devices = {290},
},
logging = {
level = domoticz.LOG_DEBUG,
marker = 'Sunscreen'
},
execute = function(domoticz)
local function switchOn(sunscreen)
if (sunscreen.state == 'Off') then
if (not dryRun) then
sunscreen.switchOn()
--domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
local function switchOff(sunscreen)
if (sunscreen.state == 'On') then
if (not dryRun) then
sunscreen.switchOff()
--domoticz.notify('Sunscreen', message)
end
domoticz.log(message, domoticz.LOG_INFO)
end
end
local sunscreen = domoticz.devices(sunscreenDevice)
-- 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
switchOn(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
end
}