Adaptive light script

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
leanderdl
Posts: 2
Joined: Tuesday 08 August 2017 19:14
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Adaptive light script

Post by leanderdl »

I made this simpel script in dzVents2.0. I could not find anything like this for Domoticz, so i thought sharing it would be nice.

I use it with a light resistor on a ESP8266 with ESP Easy on it. The sensor added as analog input, value recalculated with formula "100-%value%/10" too make it appear as 0-100.

In domoticz i use this script:

Code: Select all

local DIMMABLE_LAMP = 'ding1'   -- The light that must be dimmed 
local SWITCH_ADAPTIVE = 'Adaptive light'    -- The switch to turn on or off the adaptive option for this light
local LUX_VALUE = 'Lux anders'  -- The input "Lux" sensor
local SMOOTH_FACTOR = 3 -- smooth factor, to prevent the light from adapting too much. 
local MINIMUM = 20 -- minimum percentage the light can be, too prevent the light goes off
local MAXIMUM = 100 --maximum percentage the light can be, only change when you don't want it to go too 100%
-- Do not change anything below this, unless you know what you're doing...
return {
	active = true,
    on = {
		    devices = {
	            		SWITCH_ADAPTIVE,
			            LUX_VALUE
		            },
	    },
    data = {
		    averageLux = { history = true, maxItems = SMOOTH_FACTOR }
		},
	execute = function(domoticz, device, triggerInfo)
      if (triggerInfo.type == domoticz.EVENT_TYPE_DEVICE) then
               domoticz.data.averageLux.add(domoticz.devices(LUX_VALUE).lux)
        end
	   if (domoticz.devices(SWITCH_ADAPTIVE).state == 'On') then
	         domoticz.devices(DIMMABLE_LAMP).dimTo(
	             (((MAXIMUM - MINIMUM) / 100) * (domoticz.data.averageLux.avg())) + MINIMUM
	            )
		end
	end
}
This works for me. If you have any questions or suggestions they're more than welcome.

Leander
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest