Jag har försökt att skriva lite förklaringar i koden så jag tror att ni kan lista ut hur ni ska konfigurera det hela för att det ska fungera, annars är det bara att fråga. Hoppas att någon kan få lite hjälp på traven precis som jag har fått.
LightSchedule
Code: Select all
--[[
%% properties
%% autostart
%% globals
Husstatus
TimeOfTheDay
DayOfTheWeek
--]]
-- Create the following global variables
-- Predefined variables
-- Husstatus
-- Hemma
-- Borta
-- TimeOfTheDay
-- Morning = 05:00
-- WakeUp = Workdays 06:15, Weekends and holidays 08:00 (Google Calendar)
-- WakeUpWeekend = 08:00
-- Day = 60 minutes after sunriseHour
-- Dark = <= xx Lux
-- Evening = 60 minutes before sunsetHour
-- BedtimeKids = 19:30
-- Bedtime = Workdays 23:00
-- BedtimeWeekend = 00:01
-- Night = 01:00-05:00
-- DayOfTheWeek
-- Monday
-- Tuesday
-- Wednesday
-- Thursday
-- Friday
-- Saturday
-- Sunday
-- Local time variables
-- time is given in minutes since midnight
local now = os.date("*t");
local sunriseOffset = 60;
local sunsetOffset = 60;
local morning = 300; --"05:00"
local wakeUp = 405; --"06:45"
local wakeUpWeekend = 480; --"08:00"
local day --60 minutes after sunriseHour
local dark --not implemented
local evening --60 minutes before sunsetHour
local bedtimeKids = 1170; --"19:30"
local bedtime = 1380; --"23:00";
local bedtimeWeekend = 1; -- "00:01"
local night = 60; --"01:00"
--Local variables
local bedroomLights
local bedroomLightsKids
local outdoorLights
local windowLights
if (fibaro:countScenes() > 1) then fibaro:abort() end
if (tonumber(fibaro:getValue(10 , "value")) == 0) then
bedroomLights = "Off" else bedroomLights = "On"
end
if (tonumber(fibaro:getValue(139 , "value")) == 0) then
bedroomLightsKids = "Off" else bedroomLightsKids = "On"
end
if (tonumber(fibaro:getValue(188 , "value")) == 0) then
outdoorLights = "Off" else outdoorLights = "On"
end
if (tonumber(fibaro:getValue(4 , "value")) == 0) then
windowLights = "Off" else windowLights = "On"
end
while true do
-- Get current time
now = os.date("*t");
-- Calculate current time in minutes since midnight
time = string.format("%02d", now.hour) * 60 + string.format("%02d", now.min);
-- Set day of the week
if (now.wday == 2)
then
fibaro:setGlobal("DayOfTheWeek", "Monday")
end
if (now.wday == 3)
then
fibaro:setGlobal("DayOfTheWeek", "Tuesday")
end
if (now.wday == 4)
then
fibaro:setGlobal("DayOfTheWeek", "Wednesday")
end
if (now.wday == 5)
then
fibaro:setGlobal("DayOfTheWeek", "Thursday")
end
if (now.wday == 6)
then
fibaro:setGlobal("DayOfTheWeek", "Friday")
end
if (now.wday == 7)
then
fibaro:setGlobal("DayOfTheWeek", "Saturday")
end
if (now.wday == 1)
then
fibaro:setGlobal("DayOfTheWeek", "Sunday")
end
-- Set time of the day
-- Day
-- Get time for sunrise
day = fibaro:getValue(1, "sunriseHour");
-- Calculate time for sunrise in minutes since midnight and add sunriseOffset
day = string.sub(day,1,2) * 60 + string.sub(day,4,5) + sunriseOffset
if (time == day)
then
fibaro:setGlobal("TimeOfTheDay", "Day")
end
-- Evening
-- Get time for sunset
evening = fibaro:getValue(1, "sunsetHour");
-- Calculate time for sunrise in minutes since midnight and add sunriseOffset
evening = string.sub(evening,1,2) * 60 + string.sub(evening,4,5) - sunsetOffset
if (time == evening)
then
fibaro:setGlobal("TimeOfTheDay", "Evening")
end
-- Morning
if ((time == morning) and (time < day))
then
fibaro:setGlobal("TimeOfTheDay", "Morning")
end
-- WakeUp
if ((time == wakeUp) and (time < day) and (fibaro:getGlobal("DayOfTheWeek") == "Monday" or fibaro:getGlobal("DayOfTheWeek") == "Tuesday" or fibaro:getGlobal("DayOfTheWeek") == "Wednesday" or fibaro:getGlobal("DayOfTheWeek") == "Thursday" or fibaro:getGlobal("DayOfTheWeek") == "Friday"))
then
fibaro:setGlobal("TimeOfTheDay", "WakeUp")
end
-- WakeUpWeekend
if ((time == wakeUpWeekend) and (time < day) and (fibaro:getGlobal("DayOfTheWeek") == "Saturday" or fibaro:getGlobal("DayOfTheWeek") == "Sunday"))
then
fibaro:setGlobal("TimeOfTheDay", "WakeUpWeekend")
end
-- BedtimeKids
if ((time == bedtimeKids) and (time >= evening))
then
fibaro:setGlobal("TimeOfTheDay", "BedtimeKids")
end
-- Bedtime
if ((time == bedtime) and (fibaro:getGlobal("DayOfTheWeek") == "Monday" or fibaro:getGlobal("DayOfTheWeek") == "Tuesday" or fibaro:getGlobal("DayOfTheWeek") == "Wednesday" or fibaro:getGlobal("DayOfTheWeek") == "Thursday" or fibaro:getGlobal("DayOfTheWeek") == "Sunday"))
then
fibaro:setGlobal("TimeOfTheDay", "Bedtime")
end
-- BedtimeWeekend
if ((time == bedtimeWeekend) and (fibaro:getGlobal("DayOfTheWeek") == "Friday" or fibaro:getGlobal("DayOfTheWeek") == "Saturday"))
then
fibaro:setGlobal("TimeOfTheDay", "BedtimeWeekend")
end
-- Night
if (time == night)
then
fibaro:setGlobal("TimeOfTheDay", "Night")
end
--fibaro:debug("time: " .. time);
--fibaro:debug("DayOfTheWeek: " .. fibaro:getGlobal("DayOfTheWeek"));
--fibaro:debug("TimeOfTheDay: " .. fibaro:getGlobal("TimeOfTheDay"));
--fibaro:debug("bedroomLights: " .. bedroomLights);
--fibaro:debug("bedroomLightsKids: " .. bedroomLightsKids);
--fibaro:debug("outdoorLights: " .. outdoorLights);
--fibaro:debug("windowLights: " .. windowLights);
--fibaro:debug("-----------------------------------------------------")
-- Sleep 55 seconds
fibaro:sleep(55*1000);
end
Code: Select all
--[[
%% properties
%% autostart
%% globals
TimeOfTheDay
Husstatus
--]]
--local bedroomLights = {10}
--local bedroomLightsKids = {34, 139}
--local outdoorLights = {166, 188, 190}
--local windowLights = {4, 5, 6, 32, 154, 158}
--local homeLights = {33, 119, 120, 186, 281}
-- Turn on window and outdoor lamps
if (fibaro:getGlobal("TimeOfTheDay") == "Morning" or fibaro:getGlobal("TimeOfTheDay") == "Evening")
then
fibaro:call(4, "turnOn"); --Fönsterlampa Gästrum/Kontor
fibaro:call(5, "turnOn"); --Fönsterlampa Vardagsrum
fibaro:call(6, "turnOn"); --Vaslampa Övre hall
fibaro:call(32, "turnOn"); --Fönsterlampa Hall
fibaro:call(154, "turnOn"); --Fönsteruttag Kök
fibaro:call(158, "turnOn"); --Fönsteruttag Matsalsrum
fibaro:call(166, "turnOn"); --Utebelysning Garage
fibaro:call(188, "turnOn"); --Utebelysning EntrÈ/Fasad
fibaro:call(190, "turnOn"); --Utebelysning Pooldäck
end
if (fibaro:getGlobal("TimeOfTheDay") == "Evening")
then
fibaro:call(10, "turnOn"); --Fönsterlampa Sovrum
fibaro:call(34, "turnOn"); --Fönsterlampa Frejas rum
fibaro:call(139, "turnOn"); --Fönsterlampa Sagas rum
end
if (fibaro:getGlobal("Husstatus") == "Hemma" and fibaro:getGlobal("TimeOfTheDay") == "WakeUp" or fibaro:getGlobal("TimeOfTheDay") == "WakeUpWeekend" or fibaro:getGlobal("TimeOfTheDay") == "Evening" or fibaro:getGlobal("TimeOfTheDay") == "bedtimeKids")
then
fibaro:call(33, "turnOn"); --Golvlampa Vardagsrum
fibaro:call(119, "turnOn"); --Golvlampa Övre hall
fibaro:call(120, "turnOn"); --Skåpsbelysning Övre hall
fibaro:call(186, "turnOn"); --Taklampa Hall
fibaro:call(281, "turnOn"); --Skåpslampa Hall
end
if (fibaro:getGlobal("TimeOfTheDay") == "WakeUp" or fibaro:getGlobal("TimeOfTheDay") == "WakeUpWeekend")
then
fibaro:call(10, "turnOn"); --Fönsterlampa Sovrum
fibaro:call(34, "turnOn"); --Fönsterlampa Frejas rum
fibaro:call(139, "turnOn"); --Fönsterlampa Sagas rum
end
if (fibaro:getGlobal("TimeOfTheDay") == "BedtimeKids")
then
fibaro:call(34, "turnOff"); --Fönsterlampa Frejas rum
fibaro:call(139, "turnOff"); --Fönsterlampa Sagas rum
end
if (fibaro:getGlobal("TimeOfTheDay") == "Bedtime" or fibaro:getGlobal("TimeOfTheDay") == "BedtimeWeekend")
then
fibaro:call(10, "turnOff"); --Fönsterlampa Sovrum
end
if (fibaro:getGlobal("TimeOfTheDay") == "Day" or fibaro:getGlobal("TimeOfTheDay") == "Night")
then
fibaro:call(4, "turnOff"); --Fönsterlampa Gästrum/Kontor
fibaro:call(5, "turnOff"); --Fönsterlampa Vardagsrum
fibaro:call(6, "turnOff"); --Vaslampa Övre hall
fibaro:call(10, "turnOff"); --Fönsterlampa Sovrum
fibaro:call(32, "turnOff"); --Fönsterlampa Hall
fibaro:call(34, "turnOff"); --Fönsterlampa Frejas rum
fibaro:call(139, "turnOff"); --Fönsterlampa Sagas rum
fibaro:call(154, "turnOff"); --Fönsteruttag Kök
fibaro:call(158, "turnOff"); --Fönsteruttag Matsalsrum
fibaro:call(166, "turnOff"); --Utebelysning Garage
fibaro:call(188, "turnOff"); --Utebelysning Entré/Fasad
fibaro:call(190, "turnOff"); --Utebelysning Pooldäck
end
if (fibaro:getGlobal("Husstatus") == "Borta" or fibaro:getGlobal("TimeOfTheDay") == "Day" or fibaro:getGlobal("TimeOfTheDay") == "Bedtime" or fibaro:getGlobal("TimeOfTheDay") == "BedtimeWeekend" or fibaro:getGlobal("TimeOfTheDay") == "Night")
then
fibaro:call(33, "turnOff"); --Golvlampa Vardagsrum
fibaro:call(119, "turnOff"); --Golvlampa Övre hall
fibaro:call(120, "turnOff"); --Skåpsbelysning Övre hall
fibaro:call(186, "turnOff"); --Taklampa Hall
fibaro:call(281, "turnOff"); --Skåpslampa Hall
end
if (fibaro:getGlobal("Husstatus") == "Borta")
then
fibaro:call(33, "turnOff"); --Golvlampa Vardagsrum
fibaro:call(119, "turnOff"); --Golvlampa Övre hall
fibaro:call(120, "turnOff"); --Skåpsbelysning Övre hall
fibaro:call(121, "turnOff"); --TV Övre hall
fibaro:call(122, "turnOff"); --PS3 Övre hall
fibaro:call(123, "turnOff"); --Uttag 5 Övre hall
fibaro:call(124, "turnOff"); --Uttag 6 Övre hall
fibaro:call(143, "turnOff"); --Taklampa Sovrum
fibaro:call(147, "turnOff"); --Spotar Matsalsrum
fibaro:call(151, "turnOff"); --Spotar Kök
fibaro:call(171, "turnOff"); --Taklampa Kök
fibaro:call(179, "turnOff"); --Taklampa Gästrum/Kontor
fibaro:call(183, "turnOff"); --Taklampa Matsalsrum
fibaro:call(186, "turnOff"); --Taklampa Hall
fibaro:call(192, "turnOff"); --Poollampa Pooldäck
fibaro:call(274, "turnOff"); --Taklampa Sagas rum
fibaro:call(278, "turnOff"); --Taklampa Frejas rum
fibaro:call(281, "turnOff"); --Skåpslampa Hall
end
Filen kan ni ladda ner här:https://www.dropbox.com/s/uuaynlu9qbjlw ... .xlsx?dl=0
Det tar ju en stund att skriva in alla enheter men sen kommer det att bli lättare
Tar gärna emot feedback och förslag till förbättringar eller tillägg
Edit: Har nu uppdaterat Excelfilen lite så att man kan välja kommandon i en rulllista.