I have a problem with my script to turn on the lights in my living room. It looks like there is a problem with comparing two values and I can't figure out why it's not working properly. If anyone can help me out would be highly appreciated.
Logging (lights should go on, but are not going on):
2019-10-12 17:58:53.967 Status: dzVents: Info: ------ Start internal script: Lights livingroom: Device: "Woonkamer sensor - Burglar (zwave)", Index: 179
2019-10-12 17:58:53.972 Status: dzVents: Info:
2019-10-12 17:58:53.972 ++++++++++++++++++++
2019-10-12 17:58:53.972 SCRIPT LIGHTS LIVINGROOM:
2019-10-12 17:58:53.972 ....................
2019-10-12 17:58:53.972 Daytime active, lux value: 0 vs. minimum value 17
2019-10-12 17:58:53.972 No action needed
2019-10-12 17:58:53.972 ++++++++++++++++++++
2019-10-12 17:58:53.972 Status: dzVents: Info: ------ Finished Lights livingroom
Or
2019-10-12 17:43:10.872 ++++++++++++++++++++
2019-10-12 17:43:10.872 SCRIPT LIGHTS LIVINGROOM:
2019-10-12 17:43:10.872 ....................
2019-10-12 17:43:10.872 Daytime active, lux value: 10 vs. minimum value 17
2019-10-12 17:43:10.872 No action needed
2019-10-12 17:43:10.872 ++++++++++++++++++++
Logging (lights should stay on, but are going off):
2019-10-12 18:03:04.508 Status: dzVents: Info: ------ Start internal script: Lights livingroom: Device: "WK - Albast lamp (Philips Hue)", Index: 119
2019-10-12 18:03:04.512 Status: dzVents: Info:
2019-10-12 18:03:04.512 ++++++++++++++++++++
2019-10-12 18:03:04.512 SCRIPT LIGHTS LIVINGROOM:
2019-10-12 18:03:04.512 ....................
2019-10-12 18:03:04.512 Daytime active, lux value: 0 vs. minimum value 17
2019-10-12 18:03:04.512 0 is higher then 17
2019-10-12 18:03:04.512 there is enough light, turn off the lights
2019-10-12 18:03:04.512 ++++++++++++++++++++
2019-10-12 18:03:04.512 Status: dzVents: Info: ------ Finished Lights livingroom
Sometimes this is going well, but sometimes it's going wrong like this moment. My family is considering to throw away the sensor and Domoticz, so please help me saving my home automation

This is my script:
Code: Select all
--[[
SCRIPT DESCRIPTION:
This script turns on the lights in the livingroom at motion and depending on lux value.
If there is no motion anymore, the lights wil be turned off automtically.
DEVICES USED:
Idx 179 = Woonkamer sensor - Burglar
Idx 181 = Woonkamer sensor - Lux
Idx 118 = WK - Staande lamp
Idx 119 = WK - Albast lamp (primairy lamp for this script)
Idx 121 = WK - Plant spot lamp
]]--
--SET USER INPUT VARIABLES:
local IDLRM = 179
local IDLRL = 181
local IDLRS = 118
local IDLRA = 119 --primairy lamp for this script
local IDLRP = 121
local LOGGINGON = "Yes" -- turn logging on or off (values: On = "Yes", Off = "No")
local SECLLOFF = 1200 --turn off the lights switch after xx seconds.
local LUXVALUE = 17 --Lux value to turn on/off the lights (lux value is lower then this setting will turn on the lights)
return {
active = true,
on = {
devices = {
IDLRM,
IDLRL,
IDLRA,
},
},
execute = function(domoticz, triggeredItem, info)
--SET VARIABLES:
local MOTION = domoticz.devices(IDLRM)
local LUX = domoticz.devices(IDLRL).lux
local LIGHTALBAST = domoticz.devices(IDLRA)
local LIGHTSTANDING = domoticz.devices(IDLRS)
local LIGHTPLANT = domoticz.devices(IDLRP)
local LOGGING = "\n++++++++++++++++++++\n".."SCRIPT LIGHTS LIVINGROOM:".."\n...................."
--EXECUTE SCRIPT
if domoticz.time.matchesRule('at 06:30-22:00') or domoticz.time.matchesRule('at 06:30-23:59 on fri') or domoticz.time.matchesRule('at 06:30-23:59 on sat') then
LOGGING = LOGGING .."\n".."Daytime active, lux value: "..LUX.." vs. minimum value "..LUXVALUE
if (triggeredItem == IDLRM) then
LOGGING = LOGGING .."\n".."There has been motion detected"
if (LUX < LUXVALUE) and (LIGHTALBAST.state == "Off") then
LOGGING = LOGGING .."\n"..LUX .." is lower then "..LUXVALUE
LOGGING = LOGGING .."\n".."Its dark in here, turn on the lights"
LIGHTALBAST.switchOn()
LIGHTSTANDING.switchOn()
LIGHTPLANT.switchOn()
else
LOGGING = LOGGING .."\n".."No action needed"
end
elseif (LUX > LUXVALUE) and (LIGHTALBAST.state == "On") or (LIGHTALBAST.state == "Set Color") then
LOGGING = LOGGING .."\n"..LUX .." is higher then " ..LUXVALUE
LOGGING = LOGGING .."\n".."there is enough light, turn off the lights"
LIGHTALBAST.switchOff()
LIGHTSTANDING.switchOff()
LIGHTPLANT.switchOff()
elseif (LUX < LUXVALUE) and (LIGHTALBAST.state == "On") or (LIGHTALBAST.state == "Set Color") then
LOGGING = LOGGING .."\n".."Resetting timer, turn off the lights in "..SECLLOFF .." seconds"
LIGHTALBAST.cancelQueuedCommands()
LIGHTSTANDING.cancelQueuedCommands()
LIGHTPLANT.cancelQueuedCommands()
LIGHTALBAST.switchOff().afterSec(SECLLOFF)
LIGHTSTANDING.switchOff().afterSec(SECLLOFF)
LIGHTPLANT.switchOff().afterSec(SECLLOFF)
else
LOGGING = LOGGING .."\n".."No action needed"
end
else
LOGGING = LOGGING .."\n".."No action needed"
end
LOGGING = LOGGING .."\n++++++++++++++++++++"
--LOGGING:
if (LOGGINGON == "Yes") then
domoticz.log(LOGGING)
end
end
}