setRGB & dimTo in one function?  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
rudder66
Posts: 12
Joined: Saturday 07 December 2019 20:21
Target OS: Linux
Domoticz version: 4.11553
Location: Minsk, Belarus
Contact:

setRGB & dimTo in one function?

Post by rudder66 »

Hi all!
I use Xiaomi Gateway 2 as a nightlight.
To do this, I use a simple dzvents script:
Spoiler: show

Code: Select all

return {
	on = {
		devices = { 51 }
        },
	execute = function(domoticz, MOTION)
	local RGB = domoticz.devices(1)
	local LUXMETER = domoticz.devices(50)
	
    if (MOTION.state == 'On' and domoticz.time.matchesRule('between 21:30 and 60 minutes after sunrise')) then
        if (LUXMETER.lux <= 8 and RGB.active == false) then
            RGB.setRGB(255, 54, 0)
            RGB.dimTo(5)

        elseif (LUXMETER.lux > 8 and RGB.active) then
            RGB.switchOff()
        end
    elseif (MOTION.state == 'Off' and domoticz.time.matchesRule('between 21:30 and 65 minutes after sunrise')) then
        if (RGB.active) then
            RGB.switchOff()
	    end
    end
end
}
All is well, but there is one problem:
when starting functions

Code: Select all

RGB.setRGB (255, 54, 0)
RGB.dimTo (5)
the nightlight is first turned on with 100% brightness, and after that the brightness decreases to the required 5%.
That is, I visually observe a flash.
How to make the nightlight turn on immediately with a given color and brightness?

Thank you!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: setRGB & dimTo in one function?

Post by waaren »

rudder66 wrote: Monday 06 January 2020 9:51 How to make the nightlight turn on immediately with a given color and brightness?
Can you try this ? ( using setColor method of RGBWWW deviceType)

Code: Select all

return {
	on = {
		devices = { 51 }
        },
	execute = function(domoticz, MOTION)
	local RGB = domoticz.devices(1)
	local LUXMETER = domoticz.devices(50)
	
    if (MOTION.state == 'On' and domoticz.time.matchesRule('between 21:30 and 60 minutes after sunrise')) then
        if (LUXMETER.lux <= 8 and RGB.active == false) then
            RGB.setColor(255, 54, 0, 5)

        elseif (LUXMETER.lux > 8 and RGB.active) then
            RGB.switchOff()
        end
    elseif (MOTION.state == 'Off' and domoticz.time.matchesRule('between 21:30 and 65 minutes after sunrise')) then
        if (RGB.active) then
            RGB.switchOff()
	    end
    end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
rudder66
Posts: 12
Joined: Saturday 07 December 2019 20:21
Target OS: Linux
Domoticz version: 4.11553
Location: Minsk, Belarus
Contact:

Re: setRGB & dimTo in one function?  [Solved]

Post by rudder66 »

@waaren, you are just power! Everything works as it should!
I also need to go to the wiki page more often to get acquainted with the updates.
My offline dzvents manual did not have such a function. :(
Solved
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest