Page 1 of 2

Wake Up Light DzVents

Posted: Thursday 15 March 2018 23:22
by Mrrodz
Hi, im trying to make a wake up light with DzVents. I'm new to lua, but this is my best attempt. my problem is that the variable won't increase when the timer is done. Any help would be fantastic thank you.

Code: Select all

 return {
    on = {
        timer = {'every 5 seconds'}
        },
        data = {
            Bright = { initial = 0 }
        },
    execute = function(domoticz, item)
        if (domoticz.devices.state == 'On') then -- Wake Switch is on
            domoticz.log('Start Wake UP Light')  -- Write to Log
            if ((domoticz.devices('Bridge').level <= 100) and item.isTimer) then -- If Light is 100% stop increasing
                domoticz.data.Bright = domoticz.data.Bright + 5 -- Add 5 to Varible Bright
                domoticz.devices('Bridge').dimTo(domoticz.data.Bright)-- Set Brightness to Varible Bright
                domoticz.log('Increase Brightnes by Varible is '..domoticz.data.Bright) --Log Bright Value 
            end    
        else
            domoticz.log('Wake Up Off, reset Bright Varible')
            domoticz.data.initialize('Bright')-- Reset Bright Varible
            domoticz.devices('Bridge').dimTo(domoticz.data.Bright)
        end
end
}

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 0:30
by waaren
as far as I can see the line

Code: Select all

if (domoticz.devices.state == 'On') then -- Wake Switch is on
is not complete.

it should be something like

Code: Select all

if  domoticz.devices("your Wake Switch device name").state == 'On'  then -- Wake Switch is on

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 10:23
by poudenes
timer = {'every 5 seconds'}

Minimum is 1 minute. You can't do less then 1 minute

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 16:35
by Boredcat
I am using this script for my wake up light.

In 30 minutes it to goes from 1% to 100% brightness. Every 18 seconds the brightness is increased, using the for loop

What it creates is the following list

licht.dimTo(2).afterSec(36)
licht.dimTo(3).afterSec(54)
licht.dimTo(4).afterSec(72)
..
licht,DimTi(100).afterSec(1800)

So after 36 seconds level to 2%
After 54 seconds level to 3%

Hope this helps.







Code: Select all

return {
	active = true,
	on = {
		devices = {
			'WAKEUP LIGHT',
		}
	},
	execute = function(domoticz, device)
		local licht = domoticz.devices('Slaapkamer')
		local WK = domoticz.devices('WAKEUP LIGHT')
		if (device.state == 'On') then
		    
		    licht.switchOn()
		    -- Lightswitched on
		    licht.dimTo(1)
		    -- Dim light to 1%
		    
		
		    for i = 1,100 do
		        t = i * 18
				licht.dimTo(i).afterSec(t)
				
			end
		    
	        
	       
			domoticz.log("WAKE UP LIGHT ACTIVE")
		end
		if (device.state == 'Off') then
		    licht.switchOff()
	   	end
		
	end
}

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 18:44
by Mrrodz
thank you for the reply's

waaren - sorry yes that how i do i have it, missed that bit when re typing.

poudenes - ahh right, in the DzVents it had an example with 5 seconds in it. i will adjust and see what happens.

Boredcat - interesting way, i think ill try this. could you share the full script as i haven't been able to get 'for' loop to work.


many thanks

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 21:07
by Mrrodz
Ok so I've got it working. Poudenes i changed the timer to 1 min and it worked

Code: Select all

 return {
    on = {
        timer = {'every minute'}
        },
        data = {
            Bright = { initial = 0 }
        },
    execute = function(domoticz, item)
        if (domoticz.devices('Wake').state == 'On') then -- Wake Switch is on
            domoticz.log('Start Wake UP Light')  -- Write to Log
            if ((domoticz.devices('Bridge').level <= 100) and item.isTimer) then -- If Light is 100% stop increasing
                domoticz.data.Bright = domoticz.data.Bright + 20 -- Add 5 to Varible Bright
                domoticz.devices('Bridge').dimTo(domoticz.data.Bright)-- Set Brightness to Varible Bright
            end    
        else
            domoticz.log('Wake Up Off, reset Bright Varible')
            domoticz.data.initialize('Bright')-- Reset Bright Varible
            domoticz.devices('Bridge').dimTo(domoticz.data.Bright)
        end
end
}
ideally i would like to run this every 5 seconds for a gradual increase. is this possible ? otherwise i will try Boredcats method.

thanks

Re: Wake Up Light DzVents

Posted: Friday 16 March 2018 22:52
by dannybloe
It is not possible. Shortest event interval is one minute with domoticz. Boredcats solution is the way to go. And brilliant ;)

Re: Wake Up Light DzVents

Posted: Saturday 17 March 2018 11:23
by Boredcat
@DannyBloe : Thnx. Not mine own idea, Found the basic in a blocky script ;-). Just adapted it to a DzVents script

@Mrrodz :

here the exact script that I am using (with even the old test comments that I used), and this works.
It is running on v3.9049


Triggered with a dummy Switch name WAKEUP LIGHT
The slaapkamer is a Yeelight White light (not that the best wakeup light, 1% brightness is already to bright).

Let me know if I can help.

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'WAKEUP LIGHT',
		}
	},
	execute = function(domoticz, device)
		local licht = domoticz.devices('Slaapkamer')
		local WK = domoticz.devices('WAKEUP LIGHT')
		if (device.state == 'On') then
		    -- domoticz.devices('Lamp bank links').switchOn().forSec(2).repeatAfterSec(1, 3)
		    licht.switchOn()
		    licht.dimTo(1)
		    
		    for i = 1,100 do
		        t = i * 18
				licht.dimTo(i).afterSec(t)
				-- domoticz.log('WAKE UP LIGHT timer ' ..i)
			end
		    
	        
	        -- domoticz.devices('Lamp bank links').setNightMode()
			domoticz.log("WAKE UP LIGHT ACTIVE")
		end
		if (device.state == 'Off') then
		    licht.switchOff()
	   	end
		
	end
}

Re: Wake Up Light DzVents

Posted: Tuesday 01 January 2019 23:36
by hscholing
How can I change this to dim instead of turning up the lights? I want to dim a light from 50% to 0% in about 15 minutes. I cannot really understand the script right now or is there a more simple solution for my wishes?

Re: Wake Up Light DzVents

Posted: Wednesday 02 January 2019 0:57
by waaren
hscholing wrote: Tuesday 01 January 2019 23:36 How can I change this to dim instead of turning up the lights? I want to dim a light from 50% to 0% in about 15 minutes. I cannot really understand the script right now or is there a more simple solution for my wishes?
You can achieve that by changing the direction in the for loop. So no stepping up like it was (default stepsize = 1) but stepping down (stepsize -1)

Code: Select all

return {
	
	on = {
		devices = {
			'WAKEUP LIGHT',
		}
	},
	execute = function(domoticz, device)
		local licht = domoticz.devices('Slaapkamer')
		local WK = domoticz.devices('WAKEUP LIGHT')
		if (device.state == 'On') then
		    -- domoticz.devices('Lamp bank links').switchOn().forSec(2).repeatAfterSec(1, 3)
		    licht.switchOn()
		    licht.dimTo(50)            -- start at 50%
		    
		    for i = 50,0,-1 do          -- stepping down from 50 to 0
		        t = i * 18                   -- 50 steps of 18 seconds = 900 seconds = 15 minutes
				licht.dimTo(i).afterSec(900 - t)
				-- domoticz.log('WAKE UP LIGHT timer ' ..i)
			end
		    
	        
	        -- domoticz.devices('Lamp bank links').setNightMode()
			domoticz.log("WAKE UP LIGHT ACTIVE")
		end
		if (device.state == 'Off') then
		    licht.switchOff()
	   	end
		
	end
}

Re: Wake Up Light DzVents

Posted: Saturday 04 January 2020 14:51
by gerbenvanasselt
Hi Guys,

I am trying enhancing the script for my aquarium. Switching it on works great, but the part switching it off the other way from 80% to 0% does not work. It switches off immediatly. Not taking the wanted percentage steps. Any Idea what to do?

Very nice script by the way!!!

Code: Select all

return {
	active = true,
	on = {
		devices = {
			'Aquarium Trigger',
		}
	},
	
	execute = function(domoticz, device)
		local licht = domoticz.devices('AquaLicht')
				if (device.state == 'On') then
		    	    licht.switchOn()
		            licht.dimTo(20)
		    
		    for i = 20,80 do
		        t = i * 1
				licht.dimTo(i).afterSec(t)
				
			end
		    
	        
	       	domoticz.log("Aquarium light ACTIVE")
		end
		
		    if (device.state == 'Off') then
		    		    
		    licht.dimTo(80)
		    
			for i = 80,0,-1 do
		        t = i * 1
				licht.dimTo(i).afterSec(t)
			end
		    	        
	        domoticz.log("Aquarium light Off")
	   		
		end
		
	end
}

Re: Wake Up Light DzVents

Posted: Saturday 04 January 2020 15:40
by waaren
gerbenvanasselt wrote: Saturday 04 January 2020 14:51 I am trying enhancing the script for my aquarium. Switching it on works great, but the part switching it off the other way from 80% to 0% does not work. It switches off immediatly. Not taking the wanted percentage steps. Any Idea what to do?

Change line 31 from

Code: Select all

		        licht.dimTo(i).afterSec(t)
to

Code: Select all

		        licht.dimTo(i).afterSec(80 - t)

Re: Wake Up Light DzVents  [Solved]

Posted: Saturday 04 January 2020 22:51
by gerbenvanasselt
@Waaren, thanks that did the trick, very happy with it.

Re: Wake Up Light DzVents

Posted: Sunday 05 January 2020 21:33
by jake

waaren wrote:
hscholing wrote: Tuesday 01 January 2019 23:36 How can I change this to dim instead of turning up the lights? I want to dim a light from 50% to 0% in about 15 minutes. I cannot really understand the script right now or is there a more simple solution for my wishes?
You can achieve that by changing the direction in the for loop. So no stepping up like it was (default stepsize = 1) but stepping down (stepsize -1)

Code: Select all

		    
		    for i = 50,0,-1 do          -- stepping down from 50 to 0
		        t = i * 18                   -- 50 steps of 18 seconds = 900 seconds = 15 minutes
				licht.dimTo(i).afterSec(50 - t)
				-- domoticz.log('WAKE UP LIGHT timer ' ..i)
			end

}
Shouldn't this be changed into:

Code: Select all

licht.dimTo(i).afterSec(900 - t)
instead?

Re: Wake Up Light DzVents

Posted: Sunday 05 January 2020 22:20
by waaren
jake wrote: Sunday 05 January 2020 21:33 Shouldn't this be changed into:

Code: Select all

licht.dimTo(i).afterSec(900 - t)
instead?
Thx !
You are right and I modified it now.

Re: Wake Up Light DzVents

Posted: Friday 26 June 2020 14:59
by gerbenvanasselt
Hi guys,

The script was working for a while but not in the way I would like it to work. The proces with dimming from 0 to 100 goes well. The challenge is in te 100 to 0. When it reaches 0, after a few minutes my aquarium switches on again. This is unexpected behaviour.

Hope you can help me out?

This my script:

Code: Select all


[return {
	active = true,
	on = {
		devices = {
			'Aquarium Trigger',
		}
	},
	
	execute = function(domoticz, device)
		local licht = domoticz.devices('AquaLichtT')
				if (device.state == 'On') then
		    	    licht.switchOn()
		            licht.dimTo(20)
		    
		    for i = 20,100 do
		        t = i * 6
				licht.dimTo(i).afterSec(t)
				
			end
		    
	        
	       	domoticz.log("Aquarium light ACTIVE")
		end
		
		    if (device.state == 'Off') then
		    		    
		        licht.dimTo(100)
		    
			for i = 100,0,-1 do
		        t = i * 6
				licht.dimTo(i).afterSec (600-t)
				
			domoticz.log("Aquarium light Off")
			
		end
		    	        
	        
	   	
	end
		
	end
}

Re: Wake Up Light DzVents

Posted: Friday 26 June 2020 16:35
by waaren
gerbenvanasselt wrote: Friday 26 June 2020 14:59 The script was working for a while but not in the way I would like it to work. The proces with dimming from 0 to 100 goes well. The challenge is in te 100 to 0. When it reaches 0, after a few minutes my aquarium switches on again. This is unexpected behaviour.
I don't see any code in this script that does this. Can you specify 'a few minutes' more precise?
It could also help to find what is causing this to look at the log.

Re: Wake Up Light DzVents

Posted: Tuesday 30 June 2020 20:52
by gerbenvanasselt
Hi there,

Think i found the problem. I restored a backup on another pi with all the scripts on it. That one interfered with my main domoticz setup. So the scripts competed with each other. That's why it messed up my setup!

Re: Wake Up Light DzVents

Posted: Tuesday 03 November 2020 21:15
by IceBlackz
Sorry for reviving this old topic, but it has a nice solution in making a wake up light. However, when using the method mentioned underneath it will generate a couple of lines with the .afterSec option. I also want to be able to cancel them all, is there a command to do such a thing? Like, cancel all outstanding/upcoming orders to a device to stop the dimming process at the current values?

Code: Select all

return {
	on = {
		scenes = {
			'WakeUpLight'
		}
	},
	execute = function(domoticz, scene)
	    --WakeUpLight scene idx = 3, somehow it won't take text
	    --local WULschakelaar = domoticz.devices('Dummy_switch_for_wakeuplight')
	    --local WULscene = domoticz.scenes('WakeUpLight')
	    local WULschakelaar = scene
	    local licht = domoticz.devices('Bed Ledstrip')
		domoticz.log('Scene ' .. scene.name .. ' was changed', domoticz.LOG_INFO)
		if WULschakelaar.state == 'On' then
		    domoticz.log ('The state of the scene is detected as ON, starting')
		    --licht.dimTo(30)
		    --licht.setColor(0,0,0,2,255,0,4,0)
		    local i = 1
		    local j = 0
		    local br = 100
		    local cw = 0
		    local ww = 0
		    local timestep = 1
		    local donewithloop = 0
		    
		    while donewithloop == 0 do
		        if WULschakelaar.state == 'Off' then
		            donewithloop = 1
		        elseif cw <= 25 then
		            cw = cw + 1
		        elseif ww <= 50 then
		            ww = ww + 1
		        elseif ww <= 254 then
		            ww = ww + 1
		            if j == 4 then
		                cw = cw + 1
		                j = 0
		            end
		            j = j + 1
		        elseif cw <= 254 then
		            cw = cw + 1
		        else
		            donewithloop = 1
		        end
		        licht.setColor(0,0,0,br,cw,ww,4,0).afterSec(timestep*i)
		        i = i + 1
		    end
		        
		elseif WULschakelaar.state == 'Off' then
		    domoticz.log('The state of the scene is detected as OFF')
		    --licht.dimTo(50)
		    licht.switchOff()
		else
		    domoticz.log('The state of the scene is unknown!')
		end
		domoticz.log(licht.color)
	end
}
FYI; I'm controlling an H801 flashed with Tasmota, and also noticed the following jump from white=100 to white=77 at a certain hex value:

Code: Select all

21:27:03 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":96,"Color":"0000003BB9","HSBColor":"0,0,0","White":96,"CT":416,"Channel":[0,0,0,23,73]}
21:27:04 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":96,"Color":"0000003BBA","HSBColor":"0,0,0","White":96,"CT":416,"Channel":[0,0,0,23,73]}
21:27:05 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":96,"Color":"0000003BBB","HSBColor":"0,0,0","White":96,"CT":417,"Channel":[0,0,0,23,73]}
21:27:06 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":97,"Color":"0000003CBC","HSBColor":"0,0,0","White":97,"CT":416,"Channel":[0,0,0,24,74]}
21:27:07 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":98,"Color":"0000003CBD","HSBColor":"0,0,0","White":98,"CT":416,"Channel":[0,0,0,24,74]}
21:27:08 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":98,"Color":"0000003CBE","HSBColor":"0,0,0","White":98,"CT":417,"Channel":[0,0,0,24,75]}
21:27:09 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":98,"Color":"0000003CBF","HSBColor":"0,0,0","White":98,"CT":417,"Channel":[0,0,0,24,75]}
21:27:10 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":99,"Color":"0000003DC0","HSBColor":"0,0,0","White":99,"CT":416,"Channel":[0,0,0,24,75]}
21:27:11 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":100,"Color":"0000003DC1","HSBColor":"0,0,0","White":100,"CT":417,"Channel":[0,0,0,24,76]}
21:27:12 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":100,"Color":"0000003DC2","HSBColor":"0,0,0","White":100,"CT":417,"Channel":[0,0,0,24,76]}
21:27:13 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":100,"Color":"0000003DC2","HSBColor":"0,0,0","White":100,"CT":417,"Channel":[0,0,0,24,76]}
21:27:14 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":77,"Color":"0000003EC4","HSBColor":"0,0,0","White":77,"CT":417,"Channel":[0,0,0,24,77]}
21:27:15 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":77,"Color":"0000003EC5","HSBColor":"0,0,0","White":77,"CT":417,"Channel":[0,0,0,24,77]}
21:27:16 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":78,"Color":"0000003EC6","HSBColor":"0,0,0","White":78,"CT":417,"Channel":[0,0,0,24,78]}
21:27:17 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":78,"Color":"0000003EC7","HSBColor":"0,0,0","White":78,"CT":418,"Channel":[0,0,0,24,78]}
21:27:18 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":78,"Color":"0000003FC8","HSBColor":"0,0,0","White":78,"CT":417,"Channel":[0,0,0,25,78]}
21:27:19 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":79,"Color":"0000003FC9","HSBColor":"0,0,0","White":79,"CT":417,"Channel":[0,0,0,25,79]}
21:27:20 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":79,"Color":"0000003FCA","HSBColor":"0,0,0","White":79,"CT":418,"Channel":[0,0,0,25,79]}
21:27:21 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":80,"Color":"0000003FCB","HSBColor":"0,0,0","White":80,"CT":418,"Channel":[0,0,0,25,80]}
21:27:22 MQT: stat/tasmota_CF13F8/RESULT = {"POWER":"ON","Dimmer":80,"Color":"00000040CC","HSBColor":"0,0,0","White":80,"CT":417,"Channel":[0,0,0,25,80]}
This is sadly enough also visible with the eye, suddenly the warmth of the white changes.. Does anyone have any tip how to solve this? I guess it's a setting in Tasmota, but I don't know which :(


Edit: I tried licht.cancelQueuedCommands(), but that doesn't work. Is this a bug? Because that should be the function I'm looking for..

Re: Wake Up Light DzVents

Posted: Tuesday 03 November 2020 21:44
by waaren
IceBlackz wrote: Tuesday 03 November 2020 21:15 when using the method mentioned underneath it will generate a couple of lines with the .afterSec option. I also want to be able to cancel them all, is there a command to do such a thing?
The dzVents setColor method uses an openURL API call to do the job. Unfortunately there is no possibility for this method to cancel commands already sent to core domoticz like there is for native eventSystem commands as dimTo(), switchOn(), etc.. For these native type of commands you can use cancelQueuedCommansds() to empty the commands queue for a device.