Wake Up Light DzVents

Easy to use, 100% Lua-based event scripting framework.
Post Reply
Mrrodz
Posts: 17
Joined: Sunday 06 December 2015 22:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Wake Up Light DzVents

Post by Mrrodz » Friday 16 March 2018 0:22

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
}

User avatar
waaren
Posts: 501
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Wake Up Light DzVents

Post by waaren » Friday 16 March 2018 1:30

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
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

poudenes
Posts: 455
Joined: Wednesday 08 March 2017 10:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Wake Up Light DzVents

Post by poudenes » Friday 16 March 2018 11:23

timer = {'every 5 seconds'}

Minimum is 1 minute. You can't do less then 1 minute
RPi3 with OSMC - RPi3 with Domoticz - Dashticz - MiLight - Nanolead Aurora - KaKu - Logitech Hamony - Nest - RFLink

Boredcat
Posts: 28
Joined: Friday 17 March 2017 10:31
Target OS: Raspberry Pi
Domoticz version: V3.8747
Location: Netherlands
Contact:

Re: Wake Up Light DzVents

Post by Boredcat » Friday 16 March 2018 17:35

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
}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff

Mrrodz
Posts: 17
Joined: Sunday 06 December 2015 22:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Wake Up Light DzVents

Post by Mrrodz » Friday 16 March 2018 19:44

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

Mrrodz
Posts: 17
Joined: Sunday 06 December 2015 22:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Wake Up Light DzVents

Post by Mrrodz » Friday 16 March 2018 22:07

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

dannybloe
Posts: 1408
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Wake Up Light DzVents

Post by dannybloe » Friday 16 March 2018 23:52

It is not possible. Shortest event interval is one minute with domoticz. Boredcats solution is the way to go. And brilliant ;)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Boredcat
Posts: 28
Joined: Friday 17 March 2017 10:31
Target OS: Raspberry Pi
Domoticz version: V3.8747
Location: Netherlands
Contact:

Re: Wake Up Light DzVents

Post by Boredcat » Saturday 17 March 2018 12:23

@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
}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests