So far tests are great, so I hope it works for everyone else who wants to try it to.
TURN ON LIGHTS:
Code: Select all
-- ~/domoticz/scripts/lua/script_device_livingroomon.lua
-- When entering room, script reads current light level
-- and turns on the lights in the room based on given options.
-- If it's between 8AM and 8PM it chooses a scenery for day-lights,
-- and otherwise for evening/night-lights. It also measures the
-- lumen-values and decides if it is to bright in the room to
-- turn on the lights.
commandArray = {}
-- SETTINGS --
a = 'Lux sensor' -- name of the lux sensor
b = 'Motion Sensor' -- name of the motion sensor
c = 'Lamp 1' -- name of a lamp that this script should depend on
d = 500 -- maximum lumen value
-- END SETTINGS --
-- Define hours for day and evening lights
h = tonumber((os.date('%H')))
if (h >= 8 and h < 20)
then
x = 'Scene:Livingroom ON day'
else
x = 'Scene:Livingroom ON night'
end
-- Get values from Lux sensor
V = otherdevices_svalues[a]
-- Remove charachters from datastring
function stripchars(str, chrs)
local s = str:gsub("["..chrs.."]", '')
return s end
-- Remove " Lux" from V
w = stripchars( V, " Lux" )
-- Issue command "x" if lux is below 500 (d) and motion is detected and dimmer is off
if (tonumber(w) <= d and devicechanged[b] == 'On' and otherdevices[c] == 'Off') then
commandArray[x]='On'
print(x)
end
return commandArray
Code: Select all
-- ~/domoticz/scripts/lua/script_device_livingroomoff.lua
-- This script reads the current lumen-values from a lux sensor and
-- turns off the lights if the values is above a given number.
commandArray = {}
-- SETTINGS --
a = 'Lux sensor' -- name of the lux sensor
b = 'Lamp 1' -- name of a lamp that this script should depend on
c = 'Lamp 2' -- name of an eventual second lamp that this script should depend on
d = 500 -- maximum lumen value
e = 'Scene:Livingroom OFF' -- name of scenario to be initiated
p = 'Lights in the livingroom has been turned off due to high lumen-values' -- text to be printed in log
-- END SETTINGS --
-- Get values from the Lux sensor
V = otherdevices_svalues[a]
-- Function to strip charachters
function
stripchars(str, chrs)
local s = str:gsub("["..chrs.."]", '')
return s
end
-- Strip " Lux" from V
w = stripchars( V, " Lux" )
-- Turn off lights if dimmer is on and Lux is higher than 500 (d)
if (tonumber(w) > d and otherdevices[b] == 'On' or tonumber(w) > d and otherdevices[c] == 'On') then
commandArray[e]='Off'
print(p)
end
return commandArray