Lua Wake up light script

Moderator: leecollings

Post Reply
Amsterdam020
Posts: 55
Joined: Saturday 05 March 2016 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5629
Contact:

Lua Wake up light script

Post by Amsterdam020 »

With domoticz and a Philips Hue light i compiled this script to have a wakeuplight.
On this forum i saw a couple of other examples, but as fare as i know of, not with the following functions combined.
- the light turns on at 7h very dimm and the amount of light slowly increases
- the light only turns on monday till friday, saterday and sunday are excepted
- in the array holidays you can give a list of dates (like holidays, christmas etc) when the light should not wake you

Code: Select all

time    = os.date("*t")
weekday = (os.date("%w"))
datum   = (os.date("%d/%m/%Y"))
weekday=tonumber(weekday)
datum   = (os.date("%d-%m-%Y"))
holidays = {"25-12-2018", "26-12-2018","01-01-2019"}
x=0
--print(weekday)
commandArray = {}
if  (time.hour==07)  -- first if
then if -- second if
    (weekday==1)  or (weekday==7) 
   then print("07 uur en en weekend") 
   else print("07 uur en werkdag") 
                for key,value in ipairs(holidays) -- start loop
                do
                    if (value==datum)
                        then 
                             x=x+1
                        else 
                   end -- end loop
                end
  if  -- third if
  (x>0) then print"it is a holiday" else
        -- fourth if
        --print"het is geen feestdag" 
        if       (time.min ==01) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=1&iswhite=false" &')
        elseif   (time.min ==02) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=2&iswhite=false" &')
        elseif   (time.min ==03) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=3&iswhite=false" &')
        elseif   (time.min ==04) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=4&iswhite=false" &')
        elseif   (time.min ==05) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=5&iswhite=false" &')
        elseif   (time.min ==06) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=6&iswhite=false" &')
        elseif   (time.min ==07) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=7&iswhite=false" &')
        elseif   (time.min ==08) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=9&iswhite=false" &')
        elseif   (time.min ==09) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=10&iswhite=false" &')
        elseif   (time.min ==10) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=13&iswhite=false" &')
        elseif   (time.min ==11) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=16&iswhite=false" &')
        elseif   (time.min ==12) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=19&iswhite=false" &')
        elseif   (time.min ==13) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=22&iswhite=false" &')
        elseif   (time.min ==14) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=25&iswhite=false" &')
        elseif   (time.min ==15) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=27&iswhite=false" &')
        elseif   (time.min ==16) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=30&iswhite=false" &')
        elseif   (time.min ==17) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=35&iswhite=false" &')
        elseif   (time.min ==18) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=40&iswhite=false" &')
        elseif   (time.min ==19) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=45&iswhite=false" &')
        elseif   (time.min ==20) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=50&iswhite=false" &')
        elseif   (time.min ==21) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=55&iswhite=false" &')
        elseif   (time.min ==22) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=60&iswhite=false" &')
        elseif   (time.min ==23) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=65&iswhite=false" &')
        elseif   (time.min ==24) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=70&iswhite=false" &')
        elseif   (time.min ==25) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=75&iswhite=false" &')
        elseif   (time.min ==26) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=80&iswhite=false" &')
        elseif   (time.min ==27) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=85&iswhite=false" &')
        elseif   (time.min ==28) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=90&iswhite=false" &')
        elseif   (time.min ==29) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=95&iswhite=false" &')
        elseif   (time.min ==30) then   os.execute('curl -s "http://192.168.1.85:8080/json.htm?type=command&param=setcolbrightnessvalue&idx=2451&hue=454&brightness=100&iswhite=false" &')
        elseif   (time.min ==30) then   commandArray['Lamp_name'] ='Off'
        elseif   (time.min ==35) then   commandArray['Lamp_name'] ='Off'
        elseif   (time.min ==55) then   commandArray['Lamp_name'] ='Off'
        else  print("do not wakeuplight")
        end
      end -- close third if
   end -- close second if
else --print("het is geen 07 uur ") 
end -- close third if

return commandArray
If you have suggestions/improvements feel free.
Rp3, youlesss, rfxcom, philips hue, dsb1820
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest