På Top 10 av de bästa sakerna i mitt smarta hem 2020 så hamnar några funktioner kring passering in och ut från yttedörren.
Dörren har både ett uppkopplat lås samt larm-sensor, dessa i samband med både en knapp på insidan dörren samt ljussensor och hallbelysningen skapar ett antal möjligheter.
I videon tar jag upp 4 (5) saker som gör att dörren i sig hamnar på plats nummer 8/10.
Scriptet som kopplar på automatisk låsning samma tid alla dagar i veckan:
function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); -- Weekday to trigger on along with hour and minute when we enable auto lock on door if ( ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "20:00") ) ) then fibaro:debug("We have a date triggered event execution to do...") -- Check if we have a the global variable enabled to do autolock programming if fibaro:getGlobalValue("UseAutoLocking") == "True" then -- Send auto lock parameter to ID Lock modifyParameter(281,1,1) --- Lock the door at this time as well fibaro:call(281, "secure") -- Wait it out to trigger only once this minute fibaro:sleep(1000*60) end end -- Run the script again in 1 minute setTimeout(tempFunc, 60*1000) end
function modifyParameter(id,parameterID,targetValue) device=api.get("/devices/" .. id) productInfo = "3,115,0,3,0,1,1,5" -- This is ID Lock 150 if device.properties.productInfo ~= productInfo then fibaro:debug( string.format( "Device %d property prodInfo %s differs from %s.\nNothing written to device.", id,device.properties.productInfo,productInfo)) return end local parameter for _,v in pairs(device.properties.parameters) do if v.id==parameterID then parameter=v break end end if not parameter then parameter={id=parameterID,size=1} table.insert(device.properties.parameters,parameter) end local settings = { id=device.id, properties={ parameters=device.properties.parameters } }
parameter.value=targetValue local ok, result=pcall(api.put,"/devices/" .. id,settings) if not ok then fibaro:debug("api call failed: "..result) return end end
if (sourceTrigger["type"] == "autostart") then tempFunc() else fibaro:debug("Running not autostarted script") local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if (startSource["type"] == "other") then fibaro:debug("Trigger other") modifyParameter(281,1,1) fibaro:call(281, "secure") fibaro:sleep(1000*60) end
end
Script för att stänga av auto-låsning, då vi vill ha två olika klockslag om det är vardag eller helg så triggas en scen för att få mindre duplicering av koden.
-- Script will run on different hours of the day on weekdays and weekends -- It will only TURN off autolock when triggered -- Script runs that will turn off autolock
if fibaro:countScenes() > 1 then fibaro:abort() end
local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc() local currentDate = os.date("*t"); local startSource = fibaro:getSourceTrigger(); if ( ( ((currentDate.wday == 1 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "11:00") ) ) then fibaro:debug("Weekends autlock disabled at 11:00") fibaro:startScene(105) -- Autolås av som scen för att spara på duplicering elseif ( ( ((currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "16:00") ) ) then fibaro:debug("Weekday autlock disabled at 6:30") fibaro:startScene(105) -- Autolås av som scen för att spara på duplicering end setTimeout(tempFunc, 60*1000) end
fibaro:debug(sourceTrigger["type"])
if (sourceTrigger["type"] == "autostart") then tempFunc() end
Ovanstånde triggar scen med ID 105, du känner igen vad som sker här från översta scriptet med skillnaden att detta sätter på auto-lås
-- Set parameters for this call to lock with ID 382, paramter and value id = 382 parameterID = 1 targetValue = 0
device=api.get("/devices/" .. id) productInfo = "3,115,0,3,0,1,1,5" -- This is ID Lock 150 if device.properties.productInfo ~= productInfo then fibaro:debug( string.format( "Device %d property prodInfo %s differs from %s.\nNothing written to device.", id,device.properties.productInfo,productInfo)) return end local parameter for _,v in pairs(device.properties.parameters) do if v.id==parameterID then parameter=v break end end if not parameter then parameter={id=parameterID,size=1} table.insert(device.properties.parameters,parameter) end local settings = { id=device.id, properties={ parameters=device.properties.parameters } }
parameter.value=targetValue local ok, result=pcall(api.put,"/devices/" .. id,settings) if not ok then fibaro:debug("api call failed: "..result) return else fibaro:debug("Command sent ok: ") end
Jag visade ej heller upp scriptet för att tända upp belysningen i hallen när man kommer hem. Detta är gjort som en block scene och ser ut som följer: