The code looks good to medakipro wrote:Thanks about the LUX, it works as raw data. How to access temperature, also like raw?
I tried briefly and didn't find it, althought I do not need it at the moment
Here is the latest "night lights" version, might be useful for someone as a start script
Now I go to scripts folder with a smile, vs before when I was going there... without a smileCode: Select all
return { active = true, -- set to true to activate this script on = { 39, -- index of the device - 39 book PIR ['timer'] = 'every 2 minutes', -- minutes: xx:00, xx:02, xx:04, ..., xx:58 }, execute = function(domoticz, motionSensor) --initialize variables if (motionSensor==nil) then -- timer was triggered, get my switch motionSensor = domoticz.devices[39] --book PIR end luxLightValue = domoticz.devices[40].rawData[1] tvLED = domoticz.devices[35] livingRoomLights = domoticz.devices[36] --settings dimToPercentages = 20 waitingMinutes = 1 minimumAmbientLight = 50 -- motion triggered if (tonumber(luxLightValue) < minimumAmbientLight and motionSensor.state == 'On') then print('motion detected, tun ON the light') tvLED.dimTo(dimToPercentages) livingRoomLights.switchOn() end -- time passed since last movement detected if(tvLED.state == "On" and motionSensor.lastUpdate.minutesAgo>waitingMinutes) then print('NO motion for long enought, tun OFF the light') tvLED.switchOff() livingRoomLights.switchOff() end end }
It is good practice in Lua to define your variables as locals. That way you never accidentally influence other scripts:
Code: Select all
local myVar = 123
Code: Select all
local DIMTO_PERCENTAGES = = 20
local WAITING_MINUTES = 1
local MINIMUM_AMBIENT_LIGHT = 50
return {
...
execute = function(domoticz, motionSensor)
...
if (tonumber(luxLightValue) <MINIMUM_AMBIENT_LIGHT and motionSensor.state == 'On') then
...
end
}