This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Run tunable white (HCL)
#1
I made a script that changes the tunable white based on time of day. Maybe someone else can need it in the future. The data for the tunable white parameters was lifted from Schneiders DALI gateway. 

First run this once to store values in storage object HCL (note theres a lot of data, so if you frequent storage a lot maybe store data somewhere else):

Code:
hclTable = { [0] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [1] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [2] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [3] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [4] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [5] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [6] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2200,     m2v = 2400,     m3v = 2500,     m4v = 2600 }, [7] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2700,     m2v = 3200,     m3v = 4000,     m4v = 5000 }, [8] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 6500,     m2v = 6390,     m3v = 6281,     m4v = 6062 }, [9] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 5840,     m2v = 5625,     m3v = 5513,     m4v = 5400 }, [10] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 5177,     m2v = 4963,     m3v = 4750,     m4v = 4312 }, [11] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 4093,     m2v = 3875,     m3v = 3656,     m4v = 3328 }, [12] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 3000,     m2v = 3437,     m3v = 3875,     m4v = 4750 }, [13] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 5187,     m2v = 5843,     m3v = 6500,     m4v = 6062 }, [14] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 5625,     m2v = 5187,     m3v = 4750,     m4v = 4312 }, [15] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 3875,     m2v = 3437,     m3v = 3000,     m4v = 3437 }, [16] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 3875,     m2v = 4312,     m3v = 4750,     m4v = 5625 }, [17] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 6500,     m2v = 5625,     m3v = 4750,     m4v = 3875 }, [18] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 3000,     m2v = 3000,     m3v = 2900,     m4v = 2900 }, [19] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2800,     m2v = 2700,     m3v = 2600,     m4v = 2500 }, [20] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [21] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [22] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, [23] = {     m1 = 0,     m2 = 10,     m3 = 30,     m4 = 40,     m1v = 2500,     m2v = 2500,     m3v = 2500,     m4v = 2500 }, } storage.set('HCL', hclTable)

I set the next script as a user library, user.HCL. The function get called by a scheduled script that runs every 3 minutes. It returns the value when called. Via other triggers i disable and enable this scheduled script on demand. Note there is a Philips HUE true or false setting. If you have pure Kelvin values on your tunable whites, please set this to false. Setting it to true will convert to Mired color temperature. Also, testMode set to true will only output to log and not return value. debugMode will output to log and value if set to true.

Code:
function HCL()     -- Fetches HCL table from storage -- data = storage.get('HCL', 0)     -- Time and minutes right now -- local date = os.date('*t') local hour = date.hour local min = date.min     -- Testmode, debugmode and Philips HUE states -- testMode = false debugMode = false philipsHue = false     -- Kelvin values from HCL table -- value1 = data[hour].m1v value2 = data[hour].m2v value3 = data[hour].m3v value4 = data[hour].m4v     -- Sets color values to Mired Color Temperature if Philips Hue is used -- if philipsHue == true then  value1 = math.floor(1000000 / data[hour].m1v)  value2 = math.floor(1000000 / data[hour].m2v)  value3 = math.floor(1000000 / data[hour].m3v)  value4 = math.floor(1000000 / data[hour].m4v) end     -- Time in minutes is between 40 and 59 -- if min <= 59 and data[hour].m4 <= min then  if testMode == true then    log('Testmode: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 40 to 59 mins. Value: '..value4)  else    value = value4      if debugMode == true then      log('Debug: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 40 to 59 mins. Value: '..value4)      end  end  -- Time in minutes is between 30 and 40 -- elseif min <= data[hour].m4 and data[hour].m3 <= min then  if testMode == true then    log('Testmode: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 30 to 40 mins. Value: '..value3)  else    value = value3    if debugMode == true then      log('Debug: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 30 to 40 mins. Value: '..value3)    end  end  -- Time in minutes is between 10 and 30 -- elseif min <= data[hour].m3 and data[hour].m2 <= min then  if testMode == true then    log('Testmode: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 10 to 30 mins. Value: '..value2)  else    value = value2    if debugMode == true then      log('Debug: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 10 to 30 mins. Value: '..value2)    end  end    -- Time in minutes is between 0 and 10 -- elseif min <= data[hour].m2 and data[hour].m1 <= min then  if testMode == true then    log('Testmode: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 0 to 10 mins. Value: '..value1)  else    value = value1    if debugMode == true then      log('Debug: The time is: '..hour..':'..min..'. Fetching Kelvin value for between 0 to 10 mins. Value: '..value1)    end  end    -- Error, time was not detected properly -- else  log('HCL: ERROR, time value was not detected.') if philipsHue == true then      value = math.floor(1000000 / 2700)    else        value = 2700    end end return value   end
Reply


Messages In This Thread
Run tunable white (HCL) - by FatMax - 11.08.2018, 14:21
RE: Run tunable white (HCL) - by admin - 12.08.2018, 10:15
RE: Run tunable white (HCL) - by admin - 13.08.2018, 11:24
RE: Run tunable white (HCL) - by tomnord - 09.10.2019, 19:40
RE: Run tunable white (HCL) - by FatMax - 14.08.2018, 09:44
RE: Run tunable white (HCL) - by admin - 10.10.2019, 07:03
RE: Run tunable white (HCL) - by tomnordstrom - 10.10.2019, 07:48
RE: Run tunable white (HCL) - by admin - 10.10.2019, 08:14
RE: Run tunable white (HCL) - by KoBra - 20.09.2023, 19:35
RE: Run tunable white (HCL) - by admin - 21.09.2023, 05:15
RE: Run tunable white (HCL) - by KoBra - 21.09.2023, 05:59
RE: Run tunable white (HCL) - by admin - 21.09.2023, 08:22
RE: Run tunable white (HCL) - by KoBra - 21.09.2023, 12:42
RE: Run tunable white (HCL) - by admin - 21.09.2023, 12:48
RE: Run tunable white (HCL) - by KoBra - 21.09.2023, 14:18
RE: Run tunable white (HCL) - by admin - 21.09.2023, 14:45
RE: Run tunable white (HCL) - by KoBra - 21.09.2023, 15:08

Forum Jump: