Code: Select all
local WC = {Tak = 76, Spegel = 74, flakt_wc = 129, dorr = 342}
local KOK = {lilla_fonster = 85, fonster = 31, kaffebryggare = 158, floodsensor = 242, flowstop = 247, bankbelysning = 119, rorelse = 87, lux = 89}
local VRUM = {bokhyllan = 334, altan_dorr = 48, fonster_tv = 121, rorelse = 92, lux=94, RGBW = 184, fonster_altan = 338, ledlistkruka= 336}
local HALL = {taklampa = 297, ledlist_kruka = 14, trappen = 326}
local HALL_UPPE = {Motion = 249}
local SOVRUM = {lampa_jonny = 123, lampa_mona = 125, fonster = 113, rullgardin = 281}
local GASTRUM = {fonster = 153, rullgardin = 283}
local GARAGE = {port = 316, lampa = 5}
local KALLARE = {lyse_kallare = 23}
local UTE = {lyktstolpe = 115}
local ALTAN = {altan_krukor = 83}
local SENSORS = {dSensor_basement = 16, mSensor_basement = 18, dSensor_ytterdorr = 278, dSensor_altan = 223, mSensor1wc = 62, mSensor2wc = 67}
local VD = {SONOS_SAY_IT = 358, HC2_DIAGNOSTICS = 356, sunrise_sunset = 287, netatmo_rain = 290, netatmo_wind = 291, openweather = 289, calender = 6, ADMIN_WIFI = 80, VD_tempnu = 50, VD_energy = 127, TTS = 163, Sonos = 298, thingspeak = 263, freememory = 155, battTelegram = 272, VD_presence = 301, VD_huset= 140, mona = 303, jonny = 304}
local PORTALBLE = {iPhoneJonny = 284, iPhoneMona = 32}
local action_to_keypress_number = {["Pressed"] = 0, ["Pressed2"] = 3, ["HeldDown"] = 2, ["Released"] = 1}
local NodON = {koket = 258}
local LARM = {Garageporten = 316}
local GEA_ALARM = {jonny = 317, mona = 318}
local currenttime = os.date('*t');
local currentmonth = currenttime['month']
local TTS_Sonos = {"VirtualDevice", VD["SONOS_SAY_IT"], 1}
Code: Select all
------------------------ FUNCTIONS --------------------------------------
-- Calendar event
function isEventNow()
local day = os.date("%d/%m %H:%M")
for i = 1, 10 do
local event = fibaro:getGlobalValue("Event"..i)
if (string.find(event, day)) then
return true, event
end
end
return false
end
function checkSeason()
if ( currentmonth >= 3 and currentmonth <= 5) then
fibaro:setGlobal("SeasonState", "Spring");
elseif ( currentmonth >= 6 and currentmonth <= 8) then
fibaro:setGlobal("SeasonState", "Summer");
elseif ( currentmonth >= 9 and currentmonth <= 11) then
fibaro:setGlobal("SeasonState", "Autumn");
else fibaro:setGlobal("SeasonState", "Winter");
end
end
-- Check Presence
function checkPresence()
local jonnyHome=fibaro:getGlobalValue("Phone_JL_Present")
local geoJonnyHome=fibaro:getGlobalValue("Geo_Jonny_Home")
local monaHome=fibaro:getGlobalValue("Phone_ML_Present")
local geoMonaHome=fibaro:getGlobalValue("Geo_Mona_Home")
local sandraHome=fibaro:getGlobalValue("Phone_SW_Present")
local tijnHome=fibaro:getGlobalValue("Phone_MW_Present")
local sofiaHome=fibaro:getGlobalValue("Phone_SL_Present")
local driesHome=fibaro:getGlobalValue("Phone_DD_Present")
if tijnHome > "0" or sandraHome > "0" or sofiaHome > "0" or driesHome > "0" then
fibaro:setGlobal("GuestMode", "1")
else fibaro:setGlobal("GuestMode", "0")
end
local guests=fibaro:getGlobal("GuestMode")
local total=jonnyHome+geoJonnyHome+monaHome+geoMonaHome+guests
if (total == 0) then
fibaro:setGlobal("Status", "Borta")
--print("Borta")
else
fibaro:setGlobal("Status", "Hemma")
--print("Hemma")
end
end
-- Convert NodON Soft remote CentralSceneEvent command to sceneActivation ID by speedy @ forum.fibaro.com
function key_action_to_number()
local keypress_ID
if (startSource.type == "event" and startSource.event.type == "CentralSceneEvent") then
keypress_ID = tonumber(startSource.event.data.keyId .. action_to_keypress_number[tostring(startSource.event.data.keyAttribute)])
if keypress_ID == 10 then
elseif keypress_ID == 30 then
end
return keypress_ID
else
return false
end
end
---------------------------------------------------------------------------
-- ALARM --
-- GEA ALARM CLOCK - Om personen är hemma, kör GEA ALARM på utsatta tider som sätts med VD
GEA.add({"Alarm", GEA_ALARM["jonny"]}, 0, "", {{"If",{{"Global","Geo_Jonny_Home","1"}}},{"Global", "SleepState", "Vaken"}})
GEA.add({"Alarm", GEA_ALARM["mona"]}, 0, "", {{"If",{{"Global","Geo_Mona_Home","1"}}},{"Global", "SleepState", "Vaken"}})
-- SONOS - Sätt på play1 på P3 när GEA Alarm har utförts
GEA.add({"Alarm", GEA_ALARM["jonny"]}, 0, "", {{"If",{{"Global","Geo_Jonny_Home","1"}}},{"VirtualDevice", VD["Sonos"], "24"},{"Function", function() fibaro:sleep(4000) end}, {"VirtualDevice", VD["Sonos"], "7"}})
GEA.add({"Alarm", GEA_ALARM["mona"]}, 0, "", {{"If",{{"Global","Geo_Mona_Home","1"}}},{"VirtualDevice", VD["Sonos"], "24"},{"Function", function() fibaro:sleep(4000) end}, {"VirtualDevice", VD["Sonos"], "7"}})
-- SONOS - Sätt volymen till 8 när Sonos VD har status Stopped
GEA.add({"Label", VD["Sonos"], "lblState", "Stopped"}, -1, "", {{"Slider", VD["Sonos"], 15, 8}, {"Repeat"}})
-- TIMEOFDAY ACTIONS --
-- 15min efter soluppgång sätt TimeOfDay till Dag
GEA.add(true, 30,"",{{"Time", "Sunrise+15", "Sunrise+15"},{"Global", "TimeOfDay", "Dag"}})
-- 15min före solnedgång sätt TimeOfDay till Skymning
GEA.add(true, 30,"",{{"Time", "Sunset-15", "Sunset-15"},{"Global", "TimeOfDay", "Skymning"},{"Global", "LightState", "Auto"}})
-- När någon vaknar och TimeOfDay är lika med Natt, sätt TimeOfDay till Morgon
GEA.add({"Global", "SleepState", "Vaken"}, -1,"",{{"If",{{"Global", "TimeOfDay", "Natt"}}},{"Global", "TimeOfDay", "Morgon"}})
-- När huset sätts till Sova lägen, sätt TimeOfDay till Natt
GEA.add({"Global", "SleepState", "Sova"},-1,"",{{"Global", "TimeOfDay", "Natt"}})
-- Om huset är tomt sätt huset i Sova läge på fast tid
GEA.add(true, 30,"",{{"If",{{"Global", "Status", "Borta"}}},{"Time","23:15","23:15"},{"Global", "SleepState", "Sova"}})
-- KALENDER EVENT --
-- Vilken årstid är det?
GEA.add(true, 60, "Kollar vilken årstid det är", {{"Dates", "31/01", "31/01"},{"Dates", "28/02", "28/02"},{"Dates", "31/03", "31/03"},{"Dates", "30/04", "30/04"},{"Dates", "31/05", "31/05"},{"Dates", "30/06", "30/06"},{"Dates", "31/07", "31/07"},{"Dates", "31/08", "31/08"},{"Dates", "30/09", "30/09"},{"Dates", "31/10", "31/10"},{"Dates", "30/11", "30/11"},{"Dates", "31/12", "31/12"},{"Time", "00:00", "00:01"},{"Function", function() return checkSeason() end}})
-- Kolla Google kalender var 30:e minut
GEA.add(true , 30*60, "", {{"VirtualDevice", VD["calender"], "11"}, {"Repeat"}})
-- Skicka push när kalender event händer
GEA.add({"Function", function() return isEventNow() end}, 30, "#value#",{{"Portable", PORTALBLE["iPhoneJonny"]},{"Portable", PORTALBLE["iPhoneMona"]}})
-- VD --
-- Kolla om familjen är hemma
GEA.add(true, 30, "", {{"Repeat"},{"VirtualDevice", VD["VD_huset"], "13"}}) -- Check status
GEA.add(true, 60*60, "", {{"Repeat"},{"VirtualDevice", VD["sunrise_sunset"], "9"}}) -- Check sunrise/sunset time
GEA.add({"Global","Geo_Jonny_Home","1"}, -1, "",{{"Function", function() return checkPresence() end}})
GEA.add({"Global","Geo_Jonny_Home","0"}, -1, "",{{"Function", function() return checkPresence() end}})
GEA.add({"Global","Geo_Mona_Home","1"}, -1, "",{{"Function", function() return checkPresence() end}})
GEA.add({"Global","Geo_Mona_Home","0"}, -1, "",{{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_ML_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_ML_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_JL_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_JL_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_SW_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_SW_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_MW_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_MW_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_SL_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_SL_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_DD_Present","1"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Phone_DD_Present","0"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}},{"Function", function() return checkPresence() end}})
GEA.add({"Global","Status","Borta"}, -1, "",{{"Global", "Telegram", "Ingen hemma längre hos Larssons"}})
-- Set GEA_ALARM för helger
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekend"},{"Label", GEA_ALARM["jonny"], "lblAlarme", "08:00"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekend"},{"Label", GEA_ALARM["jonny"], "lblJours", "Lör Sön"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekend"},{"Label", GEA_ALARM["mona"], "lblAlarme", "08:00"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekend"},{"Label", GEA_ALARM["mona"], "lblJours", "Lör Sön"}})
-- Set GEA_ALARM för vardagar
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekday"},{"Label", GEA_ALARM["jonny"], "lblAlarme", "05:00"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekday"},{"Label", GEA_ALARM["jonny"], "lblJours", "Må Ti Ons Tor Fre"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekday"},{"Label", GEA_ALARM["mona"], "lblAlarme", "07:00"}})
GEA.add(true, 60, "",{{"Time", "00:00", "00:01"},{"Days", "Weekday"},{"Label", GEA_ALARM["mona"], "lblJours", "Må Ti Ons Tor Fre"}})
-- Thingspeak
GEA.add(true, 60, "", {{"Dates", "31/01", "31/01"},{"Dates", "28/02", "28/02"},{"Dates", "31/03", "31/03"},{"Dates", "30/04", "30/04"},{"Dates", "31/05", "31/05"},{"Dates", "30/06", "30/06"},{"Dates", "31/07", "31/07"},{"Dates", "31/08", "31/08"},{"Dates", "30/09", "30/09"},{"Dates", "31/10", "31/10"},{"Dates", "30/11", "30/11"},{"Dates", "31/12", "31/12"},{"Time", "23:59", "23:59"},{"VirtualDevice", VD["thingspeak"], "3"}})
GEA.add(true, 60, "", {{"Repeat"},{"VirtualDevice", VD["thingspeak"], "2"}})
-- FreeMemory
GEA.add({{"Global-", "RamFree", 25}}, 30, "RAM value less than #value# - will reboot tonight", {{"Time", "21:00", "21:01"}}) -- Push si Ram faible
GEA.add({{"Global-", "RamFree", 25}}, 30, "Reboot HC2 because less than 25% (#value#)", {{"Time", "02:45", "02:46"},{"VirtualDevice", VD["HC2_DIAGNOSTICS"], 15},{"Function", function() fibaro:sleep(1000) end},{"VirtualDevice", VD["HC2_DIAGNOSTICS"], 15}})
-- energiförbrukning
GEA.add(true, 1*60, "", {{"Repeat"},{"VirtualDevice", VD["VD_energy"], "6"}})
-- to EMONCMS
GEA.add(true, 30, "", {{"Repeat"},{"VirtualDevice", VD["VD_energy"], "7"}})
-- temperatur.nu
GEA.add(true, 2*60, "", {{"Repeat"},{"VirtualDevice", VD["VD_tempnu"], "1"}})
-- check batteries
GEA.add(true, 60, "", {{"Days","Saturday"},{"Time", "09:00", "09:01"},{"VirtualDevice", VD["battTelegram"], "1"}})
-- CopyGlobal
GEA.add(true, 30, "", {{"Time", "23:59", "23:59"},{"CopyGlobal", "todayKW", "yeasterdayKW"}})
-- Netatmo and OpenWeather
GEA.add(true, 5*60, "", {{"Repeat"},{"VirtualDevice", VD["netatmo_wind"], "6"}})
GEA.add(true, 5*60, "", {{"Repeat"},{"VirtualDevice", VD["netatmo_rain"], "6"}})
GEA.add(true, 5*60, "", {{"Repeat"},{"VirtualDevice", VD["openweather"], "9"}})
-- skicka Telegram om gårdagens och månadens elförbrukning
GEA.add({"Global!", "yeasterdayKW", ""}, 60, "", {{"Time", "07:00", "07:01"}, {"Global", "Telegram", "Gårdagens elförbrukning: #value# kWh"}})
GEA.add({"Global!", "monthKW", ""}, 30, "", {{"Dates", "31/01", "31/01"},{"Dates", "28/02", "28/02"},{"Dates", "31/03", "31/03"},{"Dates", "30/04", "30/04"},{"Dates", "31/05", "31/05"},{"Dates", "30/06", "30/06"},{"Dates", "31/07", "31/07"},{"Dates", "31/08", "31/08"},{"Dates", "30/09", "30/09"},{"Dates", "31/10", "31/10"},{"Dates", "30/11", "30/11"},{"Dates", "31/12", "31/12"},{"Time", "23:59", "23:59"},{"Global", "Telegram", "Månadens elförbrukning: #value# kWh"}})
-- TTS --
GEA.add(true, 30, "", {{"Time", "Sunrise+14", "Sunrise+14"}, {"Label", VD["SONOS_SAY_IT"], "Message", "Sätter variabel Status till Dag"},TTS_Sonos})
GEA.add(true, 30, "", {{"Time", "Sunset-16", "Sunset-16"}, {"Label", VD["SONOS_SAY_IT"], "Message", "Sätter variabel Status till Skymmning"},TTS_Sonos})
GEA.add(KOK["kaffebryggare"], -1, "",{{"Inverse"},{"Label", VD["SONOS_SAY_IT"], "Message", "Timer för kaffebryggaren har nu löpt ut, stänger av kaffebryggaren"},TTS_Sonos})
GEA.add({"Global", "SleepState", "Sova"}, -1, "", {{"Label", VD["SONOS_SAY_IT"], "Message", "Godnatt familjen Larsson."},TTS_Sonos})
GEA.add({"Global","Geo_Jonny_Home","1"}, -1, "",{{"Label", VD["SONOS_SAY_IT"], "Message", "Jonny kommer hem nu"},TTS_Sonos})
-- ACTIONS --
-- KÖKET
-- Tänd när TimeOfDay är Morgon
GEA.add({"Global", "TimeOfDay", "Morgon"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"}}} ,{"turnOn", KOK["lilla_fonster"]},{"turnOn", KOK["fonster"]}})
-- Tänk bänkbelysning vid rörelse
local turnoffRorelse = GEA.add(true, 30*60, "", {{"Inverse"}, {"turnOff", KOK["bankbelysning"]}, {"NotStarted"}})
GEA.add({KOK["rorelse"], {"Value-", KOK["lux"], 30}, {"Global", "SleepState", "Vaken"},{"Global", "LightState", "Auto"},{"Global", "Status", "Hemma"}}, -1, "", {{"turnOn", KOK["bankbelysning"]}, {"RestartTask", turnoffRorelse}})
-- Släck om LightStatus = Manual
GEA.add({"Global", "LightState", "Manual"}, -1, "", {{"turnOff", KOK["bankbelysning"]}})
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", KOK["lilla_fonster"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", KOK["fonster"]}})
-- NonON - Left button up/down
GEA.add({"SceneActivation", NodON["koket"], 10}, -1, "", {{"turnOn", KOK["flowstop"]}})
GEA.add({"SceneActivation", NodON["koket"], 30}, -1, "", {{"turnOff", KOK["flowstop"]}})
-- NonON - Right button up/down
GEA.add({"SceneActivation", NodON["koket"], 20}, -1, "", {{"turnOn", KOK["bankbelysning"]}})
GEA.add({"SceneActivation", NodON["koket"], 40}, -1, "", {{"turnOff", KOK["bankbelysning"]}})
-- Stänger av kaffebryggaren efter 120min och skickar push
GEA.add({"Sensor+", KOK["kaffebryggare"], 50}, 120*60, "Stänger av kaffebryggaren #time#", {{"turnOff", KOK["kaffebryggare"]}, {"VirtualDevice", VD["TTS"], "3"},{"Portable", PORTALBLE["iPhoneJonny"]},{"Portable", PORTALBLE["iPhoneMona"]}})
-- Fibaro floodsensor, flow stop protection
GEA.add(KOK["flowstop"], 200*60, "", {{"turnOff"}})
GEA.add(KOK["floodsensor"], -1, "VATTEN LÄCKAGE DISKMASKIN! (#date# #time#)", {{"Portable", PORTALBLE["iPhoneJonny"]},{"Portable", PORTALBLE["iPhoneMona"]}, {"turnOff", KOK["flowstop"]}})
-- HALLEN
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}},{"turnOn", HALL["ledlist_kruka"]}})
GEA.add(HALL["taklampa"], 10*60, "", {{"turnOff"}})
GEA.add(true, 30, "",{{"If",{{"Global", "TimeOfDay", "Morgon"},{"Global", "SleepState", "Vaken"}}} ,{"turnOn", HALL["ledlist_kruka"]}})
GEA.add({"SceneActivation", HALL["taklampa"], 24}, -1, "", {{"Global", "SleepState", "Sova"}})
-- TRAPPEN
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}}, {"turnOn", HALL["trappen"]}})
-- VARDAGSRUM
-- Tänk belysning vid rörelse
local turnoffVRUM = GEA.add(true, 20*60, "", {{"Inverse"}, {"turnOff", VRUM["bokhyllan"]}, {"NotStarted"}})
GEA.add({VRUM["rorelse"], {"Value-", VRUM["lux"], 17}, {"Global", "SleepState", "Vaken"},{"Global", "LightState", "Auto"},{"Global", "Status", "Hemma"},{"Global", "Filmmys", "ejAktiv"}}, -1, "", {{"turnOn", VRUM["bokhyllan"]}, {"RestartTask", turnoffVRUM}})
-- Släck om LUX är 18 eller mer
GEA.add({"Value+", VRUM["lux"], 18}, -1, "",{{"turnOff", VRUM["bokhyllan"]}})
-- Tänd när TimeOfDay är Morgon
GEA.add({"Global", "TimeOfDay", "Morgon"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"},{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["bokhyllan"]}})
GEA.add({"Global", "TimeOfDay", "Morgon"}, -1, "",{{"If",{{"Global", "SleepState", "Vaken"},{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["fonster_altan"]}})
-- Släck om LightStatus = Manual
GEA.add({"Global", "LightState", "Manual"}, -1, "", {{"turnOff", VRUM["bokhyllan"]}})
-- Släck om Filmmys = Aktiv
GEA.add({"Global", "Filmmys", "Aktiv"}, -1, "", {{"turnOff", VRUM["bokhyllan"]}})
GEA.add({"Global", "Filmmys", "Aktiv"}, -1, "", {{"turnOff", VRUM["fonster_altan"]}})
GEA.add({"Global", "Filmmys", "Aktiv"}, -1, "", {{"turnOff", VRUM["fonster_tv"]}})
GEA.add({"Global", "Filmmys", "Aktiv"}, -1, "", {{"turnOff", VRUM["ledlistkruka"]}})
-- Tänd om Filmmys = ejAktiv
GEA.add({"Global", "Filmmys", "ejAktiv"}, -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"},{"Global", "SleepState", "Vaken"}}},{"turnOn", VRUM["plug_kamin"]}})
GEA.add({"Global", "Filmmys", "ejAktiv"}, -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"},{"Global", "SleepState", "Vaken"}}},{"turnOn", VRUM["bokhyllan"]}})
GEA.add({"Global", "Filmmys", "ejAktiv"}, -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"},{"Global", "SleepState", "Vaken"}}},{"turnOn", VRUM["fonster_altan"]}})
GEA.add({"Global", "Filmmys", "ejAktiv"}, -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"},{"Global", "SleepState", "Vaken"}}},{"turnOn", VRUM["fonster_tv"]}})
GEA.add({"Global", "Filmmys", "ejAktiv"}, -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"},{"Global", "SleepState", "Vaken"}}},{"turnOn", VRUM["ledlistkruka"]}})
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["fonster_tv"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["RGBW"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["ledlistkruka"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["bokhyllan"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["fonster_tv"]}})
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}} ,{"turnOn", VRUM["fonster_altan"]}})
-- WC
-- Fläkt fuktighet
local humidity = {"If", {{"Value+",70,50}}}
GEA.add(true, 7*60, "", {{"Repeat"},{"turnOn", WC["flakt_wc"]}, humidity})
local flaktTask = GEA.add(WC["flakt_wc"], 7*60, "", {{"turnOff"}})
GEA.add(WC["dorr"], -1, "", {{"turnOn", WC["flakt_wc"]},{"RestartTask", flaktTask}})
-- Tänder vid rörelse
GEA.add(SENSORS["mSensor2wc"], -1, "", {{"Time", "07:00", "22:00"},{"turnOn", WC["Tak"]},{"turnOn", WC["Spegel"]}})
GEA.add(SENSORS["mSensor1wc"], -1, "", {{"Time", "07:00", "22:00"},{"turnOn", WC["Tak"]},{"turnOn", WC["Spegel"]}})
-- Släcker efter 12 minuter om ej rörelse registrerats
GEA.add(SENSORS["mSensor2wc"], 12*60, "", {{"Inverse"}, {"turnOff", WC["Tak"]},{"turnOff", WC["Spegel"]}})
GEA.add(SENSORS["mSensor1wc"], 12*60, "", {{"Inverse"}, {"turnOff", WC["Tak"]},{"turnOff", WC["Spegel"]}})
-- Om någon lampa släcks manuellt, släck den andra med automatik
GEA.add(WC["Tak"], -1, "", {{"Inverse"}, {"turnOff", WC["Spegel"]}})
GEA.add(WC["Spegel"], -1, "", {{"Inverse"}, {"turnOff", WC["Tak"]}})
-- ALTAN
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", ALTAN["altan_krukor"]}})
-- TRÄDGÅRD
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", UTE["lyktstolpe"]}})
-- Släck vid soluppgång
GEA.add(true, 30, "",{{"Time", "Sunrise", "Sunrise"} ,{"turnOff", UTE["lyktstolpe"]}})
-- GARAGE
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", GARAGE["lampa"]}})
-- Släck vid soluppgång
GEA.add(true, 30, "",{{"Time", "Sunrise", "Sunrise"} ,{"turnOff", GARAGE["lampa"]}})
-- SOVRUM
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"turnOn", SOVRUM["fonster"]}})
-- Tänd sänglampor när SleepState är Sova
GEA.add({"Global", "SleepState", "Sova"}, -1, "",{{"turnOn", SOVRUM["lampa_jonny"]}})
GEA.add({"Global", "SleepState", "Sova"}, -1, "",{{"turnOn", SOVRUM["lampa_mona"]}})
-- Släcker sänglampor efter 20min
GEA.add(SOVRUM["lampa_jonny"], 20*60, "", {{"turnOff"}})
GEA.add(SOVRUM["lampa_mona"], 20*60, "", {{"turnOff"}})
-- Rullgardinen går ner när SleepState är Sova
GEA.add({"Global", "SleepState", "Sova"}, -1, "",{{"Close", SOVRUM["rullgardin"], 100}})
--GEA.add( {"Value-", SOVRUM["rullgardin"], 31}, 10*60, "", {{"Close",SOVRUM["rullgardin"],100}})
-- GÄSTRUM
-- Tänd när TimeOfDay är Skymning
GEA.add({"Global", "TimeOfDay", "Skymning"}, -1, "",{{"If",{{"Global", "Status", "Hemma"}}},{"turnOn", GASTRUM["fonster"]}})
-- Släcker fönsterlampan när SleepState är Sova
GEA.add({"Global", "SleepState", "Sova"},-1,"",{{"turnOff", GASTRUM["fonster"]}})
-- KÄLLAREN
local basementTask = GEA.add(KALLARE["lyse_kallare"], 5*60, "", {{"turnOff"}})
local basementmotion = SENSORS["mSensor_basement"]
GEA.add(SENSORS["dSensor_basement"], -1, "", {{"turnOn", KALLARE["lyse_kallare"]}, {"RestartTask", basementTask}})
GEA.add(basementmotion, -1, "", {{"turnOn", KALLARE["lyse_kallare"]}, {"RestartTask", basementTask}})
-- GLOBALA ACTIONS
-- groupLights
local groupLights = {
ALTAN["altan_krukor"],
HALL["ledlist_kruka"],
HALL["trappen"],
VRUM["ledlistkruka"],
VRUM["bokhyllan"],
VRUM["fonster_altan"],
VRUM["fonster_tv"],
VRUM["altan_dorr"],
VRUM["RGBW"],
KOK["lilla_fonster"],
KOK["bankbelysning"],
KOK["fonster"],
SOVRUM["fonster"],
}
-- Släcker alla lampor när TimeOfDay är Dag
for _,v in ipairs(groupLights) do
GEA.add({"Global", "TimeOfDay", "Dag"}, -1, "", {{"turnOff", v}})
end
-- Släcker alla lampor när SleepState är Sova
for _,v in ipairs(groupLights) do
GEA.add({"Global", "SleepState", "Sova"}, -1, "", {{"turnOff", v}})
end
-- Sätter Filmmys till ejAktiv vid SleepState = Sova
GEA.add({"Global", "SleepState", "Sova"}, -1, "", {{"Global", "Filmmys", "ejAktiv"}})
-- Tänder upp huset när familjen kommer hem och det är skymning
GEA.add(SENSORS["dSensor_ytterdorr"], -1, "", {{"If",{{"Global", "TimeOfDay", "Skymning"}}},{"turnOn", HALL["taklampa_hall"]}})
GEA.add(SENSORS["dSensor_ytterdorr"], 2*60, "", {{"Inverse"}, {"turnOff", HALL["taklampa_hall"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}} ,{"turnOn", ALTAN["altan_krukor"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}} ,{"turnOn", VRUM["ledlistkruka"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}} ,{"turnOn", VRUM["bokhyllan"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}} ,{"turnOn", HALL["ledlist_kruka"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}}, {"turnOn", VRUM["RGBW"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}}, {"turnOn", VRUM["altan_dorr"]}})
GEA.add({"Global", "Status", "Hemma"}, -1, "",{{"If",{{"Global", "TimeOfDay", "Skymning"}}}, {"turnOn", HALL["trappen"]}})
-- ALARM --
-- Skalskydd
GEA.add({GARAGE["port"]}, -1, "Garageporten öppnades (#date# #time#)", {{"If",{{"Global", "Status", "Borta"}}},{"Portable", PORTALBLE["iPhoneJonny"]},{"VirtualDevice", VD["TTS"], "7"}})
local SensorGroup1 = {
SENSORS["dSensor_ytterdorr"],
GARAGE["port"],
}
GEA.add({{"Global", "SensorGroup1", "Safe"}}, 20*60, "All safe for #duration#, activate shell alarm", {{"Time", "22:00", "05:30"},{"Portable", PORTALBLE["iPhoneJonny"]}})
GEA.add({HALL_UPPE["Motion"]}, -1, "Movement on upperfloor Deactivate shell alarm", {{"Time", "23:00", "Sunrise"},{"Portable", PORTALBLE["iPhoneJonny"]}})
-- SCENES --
-- Netatmo scene
GEA.add(true, 5*60, "",{{"Repeat"},{"Scenario", 186}})
-- TEST ZONE --
-- ANVÄNDS EJ --
--GEA.add(true, 120, "",{{"Days","Weekday"},{"Time", "05:20", "22:00"},{"Function", function() return checkPresence() end},{"Repeat"}})
--GEA.add(true, 120, "",{{"Days","Weekend"},{"Time", "08:00", "22:00"},{"Function", function() return checkPresence() end},{"Repeat"}})
--local condPresence = {{"Global","LastSeenJonny",""},{"Global","LastSeenMona",""},{"Global","LastSeenTijn",""},{"Global","LastSeenSandra",""}}
--GEA.add(condPresence, -1, "",{{"Inverse"},{"Function", function() return checkPresence() end}})
--local condGeo = {"If", {{"Global","Geo_Mona_Home",""},{"Global","Geo_Jonny_Home",""}}}
--GEA.add(condGeo, -1, "",{{"Inverse"},{"Function", function() return checkPresence() end}})
--local condWifi = {{"Global","wifiML",""},{"Global","wifiJL",""},{"Global","wifiMW",""},{"Global","wifiSW",""},{"Global","Phone_JL_Present",""},{"Global","Phone_ML_Present",""}}
--GEA.add(condWifi, -1, "",{{"Inverse"},{"Time", "08:00", "22:00"},{"Function", function() return checkPresence() end}})