setKelvin(Kelvin): Function  [Solved]

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

Moderator: leecollings

Post Reply
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

setKelvin(Kelvin): Function  [Solved]

Post by deennoo »

First step using Dzevents.

My goal is to use the set kelvin fonction on a Yeelight Desktop lamp (as a test, finaly to all bulb and light from various brand all around the house)

I want to use ; setKelvin(Kelvin): Function for an adaptative Kelvin value depending on sun position

my basic LUA time script is :

Code: Select all

commandArray = {}
local mini = 100 --kelvin max range
local maxi = 0 --kelvin min range
local delta = maxi - mini
local wakeup = 60*timeofday['SunriseInMinutes']
local goodnight = 60*timeofday['SunsetInMinutes']
local periode = goodnight - wakeup
local offset = wakeup-periode/2
local color = mini
local time = os.date("*t")
local now = 60*(time.hour*60 + time.min)
if now >= wakeup and now < goodnight then
	color = math.floor((maxi-delta/2)+(delta/2)*math.cos((now-offset)*2*math.pi/periode)+0.5)
end

print('color:'..color)

if otherdevices['test']~='Off' then 

commandArray['OpenURL']='http://127.0.0.1:8080/json.htm?type=command&param=setkelvinlevel&idx=24&kelvin='..color..'' '


return commandArray 

Basic but working as a charme, next step is to retrive kelvin value, and update only if necesseary every 5 minutes

As DzEvent is the futur and i try to translate this with this :

Code: Select all

local mini = 100
local maxi = 0
local delta = maxi - mini
local wakeup = 60*timeofday['SunriseInMinutes']
local goodnight = 60*timeofday['SunsetInMinutes']
local periode = goodnight - wakeup
local offset = wakeup-periode/2
local color = mini
local time = os.date("*t")
local now = 60*(time.hour*60 + time.min)
if now >= wakeup and now < goodnight then
	color = math.floor((maxi-delta/2)+(delta/2)*math.cos((now-offset)*2*math.pi/periode)+0.5)
end



print('color:'..color)

return {
	on = {
		timer = {

			'every minute',		
			
		}
	},
	execute = function(domoticz, timer)
		
		domoticz.log('colordz events:'..color)
	
		domoticz.devices('test').setKelvin(color)

		
	end
}
Log answer is :

Code: Select all

2021-01-23 09:41:00.274 Error: dzVents: Error: (3.1.2) Method setKelvin is not available for device "test" (deviceType=Color Switch, deviceSubType=White). If you believe this is not correct, please report.
My device correctly answer to domoticz api

Code: Select all

http://127.0.0.1:8080/json.htm?type=command&param=setkelvinlevel&idx=24&kelvin=25
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: setKelvin(Kelvin): Function

Post by waaren »

deennoo wrote: Saturday 23 January 2021 9:44 Log answer is :

Code: Select all

2021-01-23 09:41:00.274 Error: dzVents: Error: (3.1.2) Method setKelvin is not available for device "test" (deviceType=Color Switch, deviceSubType=White). If you believe this is not correct, please report.
Thx for reporting.

I assume the subType 'White'was not in use yet when this dzVents function was created.

Can you please try again after changing line 36 of the file
<domoticz dir>/dzVents/runtime/device-adapters/rgbw_device.lua

from

Code: Select all

		if (device.deviceSubType == 'RGBWW') or (device.deviceSubType == 'WW')  then
to

Code: Select all

		if (device.deviceSubType == 'RGBWW') or (device.deviceSubType == 'WW') or (device.deviceSubType == 'White')  then
If that is successful I will patch it into dzVents and make it available in the next domoticz build.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: setKelvin(Kelvin): Function

Post by deennoo »

waaren wrote: Saturday 23 January 2021 10:52

Code: Select all

		if (device.deviceSubType == 'RGBWW') or (device.deviceSubType == 'WW') or (device.deviceSubType == 'White')  then
If that is successful I will patch it into dzVents and make it available in the next domoticz build.
The Job is done !

Maybe can be usefull to create setAutoKelvin function using "color" function of my script who come from : https://github.com/vil1driver/lua
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: setKelvin(Kelvin): Function

Post by waaren »

deennoo wrote: Saturday 23 January 2021 11:11 The Job is done !
Thx for testing !

Maybe can be usefull to create setAutoKelvin function using "color" function of my script who come from : https://github.com/vil1driver/lua
I am not sure I understand. Is this function different then what is already available in the dzVents rgbw device-adapter? as setColor or any of the other functions?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: setKelvin(Kelvin): Function

Post by deennoo »

On this fonction the name is color but must be named : whitetemp.

Idea is to automatise white temp on Sun position (surely this must be done on domoticz widget side).

Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: setKelvin(Kelvin): Function

Post by waaren »

deennoo wrote: Saturday 23 January 2021 12:57 On this fonction the name is color but must be named : whitetemp.
Probably a language thing but I do not understand.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: setKelvin(Kelvin): Function

Post by deennoo »

waaren wrote: Saturday 23 January 2021 15:12
deennoo wrote: Saturday 23 January 2021 12:57 On this fonction the name is color but must be named : whitetemp.
Probably a language thing but I do not understand.
My fault, i don't speak about setkelvin function

Spoking about :

Code: Select all

local mini = 100
local maxi = 0
local delta = maxi - mini
local wakeup = 60*timeofday['SunriseInMinutes']
local goodnight = 60*timeofday['SunsetInMinutes']
local periode = goodnight - wakeup
local offset = wakeup-periode/2
local color = mini
local time = os.date("*t")
local now = 60*(time.hour*60 + time.min)
if now >= wakeup and now < goodnight then
	color = math.floor((maxi-delta/2)+(delta/2)*math.cos((now-offset)*2*math.pi/periode)+0.5)
end
Who is a way to make kelvin value follow sun position and make de white temp to be automaticaly adapted to sun position like Philips Hue made, they call it adaptative light

https://www.imore.com/philips-hue-homek ... ing-update
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
Maikel76
Posts: 71
Joined: Friday 14 August 2020 6:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Bangkok
Contact:

Re: setKelvin(Kelvin): Function

Post by Maikel76 »

deennoo wrote:
waaren wrote: Saturday 23 January 2021 15:12
deennoo wrote: Saturday 23 January 2021 12:57 On this fonction the name is color but must be named : whitetemp.
Probably a language thing but I do not understand.
My fault, i don't speak about setkelvin function

Spoking about :

Code: Select all

local mini = 100
local maxi = 0
local delta = maxi - mini
local wakeup = 60*timeofday['SunriseInMinutes']
local goodnight = 60*timeofday['SunsetInMinutes']
local periode = goodnight - wakeup
local offset = wakeup-periode/2
local color = mini
local time = os.date("*t")
local now = 60*(time.hour*60 + time.min)
if now >= wakeup and now < goodnight then
	color = math.floor((maxi-delta/2)+(delta/2)*math.cos((now-offset)*2*math.pi/periode)+0.5)
end
Who is a way to make kelvin value follow sun position and make de white temp to be automaticaly adapted to sun position like Philips Hue made, they call it adaptative light

https://www.imore.com/philips-hue-homek ... ing-update
Goodafternoon,
I was looking for something that’s calculates this Kelvin value and stumbled upon your post. Thanks a lot for posting


Sent from my iPhone using Tapatalk
Scripting is my passion, dzVents, LUA, Bash
Dashticz v3.10.7 Beta --Raspbian Buster
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest