Lua Scenes — examples
Turn the device on, when an other devices turns on
Conditions:
1{ 2 operator = "any", 3 conditions = { 4 { 5 type = "device", 6 id = 25, 7 property = "value", 8 operator = "==", 9 value = true, 10 isTrigger = true 11 } 12 } 13}
Actions:
1fibaro.call(30, "turnOn")
Turning on the device with a 30-second delay and sending an email to user 2 with the text Test notification when another device is turned on between 9:00 and 10:00
Conditions:
1{ 2 operator = "all", 3 conditions = { 4 { 5 type = "device", 6 id = 25, 7 property = "value", 8 operator = "==", 9 value = true, 10 isTrigger = true 11 }, 12 { 13 operator = "all", 14 conditions = { 15 { 16 type = "date", 17 property = "cron", 18 operator = "match>=", 19 value = {"0", "9", "*", "*", "*","*"} 20 }, 21 { 22 type = "date", 23 property = "cron", 24 operator = "match<", 25 value = {"0", "10", "*", "*", "*","*"} 26 } 27 } 28 } 29 } 30}
Actions:
1fibaro.setTimeout(30000, function() 2 fibaro.call(30, "turnOn") 3end) 4fibaro.alert("email", {2}, "Test notification")
Invert device state
Conditions:
1{}
Actions:
1local deviceValue1 = fibaro.get(241, "value") 2if tonumber(deviceValue1) > 0 then 3 fibaro.call(241, "turnOff") 4else 5 fibaro.call(241, "turnOn") 6end
Turn on the light (devices 51, 52, 53) when the motion sensor (device 54) is breached but only at night
Conditions:
1{ 2 operator = "all", 3 conditions = { 4 { 5 type = "device", 6 id = 54, 7 property = "value", 8 operator = "==", 9 value = true, 10 isTrigger = true 11 }, 12 { 13 operator = "any", 14 conditions = { 15 { 16 type = "date", 17 property = "sunset", 18 operator = ">=", 19 value = 0 20 }, 21 { 22 type = "date", 23 property = "sunrise", 24 operator = "<=", 25 value = 0 26 } 27 } 28 } 29 } 30}
Actions:
1fibaro.call({51, 52, 53}, "turnOn")
At sunrise open the blinds at 50% and turn on the dimmers at 50%
1{ 2 operator = "all", 3 conditions = { 4 { 5 type = "date", 6 property = "sunrise", 7 operator = "==", 8 value = 0, 9 isTrigger = true 10 } 11 } 12}
Actions:
1local rollerShutterBody = { 2 args = { 50 }, 3 filters = { 4 { 5 filter = "type", 6 value = { "com.fibaro.rollerShutter" } 7 } 8 } 9} 10 11local dimmerBody = { 12 args = { 30 }, 13 filters = { 14 { 15 filter = "type", 16 value = { "com.fibaro.multilevelSwitch" } 17 } 18 } 19} 20 21fibaro.callGroupAction("setValue", rollerShutterBody) 22fibaro.callGroupAction("setValue", dimmerBody)
When user 36 leaves the location 2, close the blinds and arm the alarm
1{ 2 operator = "all", 3 conditions = { 4 { 5 type = "location", 6 id = 36, 7 property = 2, 8 operator = "==", 9 value = "enter", 10 isTrigger = true 11 } 12 } 13}
Actions:
1local rollerShutterBody = { 2 args = { }, 3 filters = { 4 { 5 filter = "type", 6 value = { "com.fibaro.rollerShutter" } 7 } 8 } 9} 10 11fibaro.callGroupAction("close", rollerShutterBody) 12fibaro.alarm("arm")
Get information about visible motion sensors and lights in the default room
1{ 2 operator = "all", 3 conditions = { 4 } 5}
Actions:
1local roomId = 219 2 3function tableLength(table) 4 local count = 0 5 for _ in pairs(table) do count = count + 1 end 6 return count 7end 8 9function getRoom() 10 local result = api.get('/rooms/' .. roomId) 11 roomID = result.id 12 return roomID 13end 14 15function getLights(roomID) 16 local IDs = {} 17 local result = api.get('/devices?roomID=' .. roomID .. '&isTypeOf=com.fibaro.binarySwitch&visible=true') 18 for k,v in pairs(result) do 19 table.insert(IDs, v.id) 20 end 21 return IDs 22end 23 24function getMotions(roomID) 25 local IDs = {} 26 local result = api.get('/devices?roomID=' .. roomID .. '&isTypeOf=com.fibaro.motionSensor&visible=true') 27 for k,v in pairs(result) do 28 table.insert(IDs, v.id) 29 end 30 return IDs 31end 32 33function headerLights(inputArray) 34 output = "" 35 for key,value in pairs(inputArray) do 36 output = output .. value .. ' value ' 37 end 38 return output 39end 40 41function headerMotions(inputArray) 42 output = "" 43 for key,value in pairs(inputArray) do 44 output = output .. value .. ' value ' 45 end 46 return output 47end 48 49function headerLights(inputArray) 50 output = "" 51 for key,value in pairs(inputArray) do 52 output = output .. value .. ' value ' 53 end 54 return output 55end 56 57function arrayMotions(inputArray) 58 output = "" 59 for key,value in pairs(inputArray) do 60 output = output .. value .. ', ' 61 end 62 text = output 63 text = text:sub(1, -3) 64 return text 65end 66 67function arrayLights(inputArray) 68 output = "" 69 for key,value in pairs(inputArray) do 70 output = output .. value .. ', ' 71 end 72 text = output 73 text = text:sub(1, -3) 74 return text 75end 76 77 78--print("Room ID: " .. getRoom()) 79 80print("ONLY VISIBLE Motion Sensors and Lights in default room!!! ") 81print("roomID = " .. roomId) 82print(" ") 83print("HEADERS: // put under %%properties") 84print("for lights: " .. headerLights(getLights(getRoom()))) 85print("for Motions: " .. headerMotions(getMotions(getRoom()))) 86print(" ") 87print("VARIABLES:") 88print("lightsIDs = " .. "{" .. arrayLights(getLights(getRoom())) .. "}") 89print("motionsIDs = " .. "{" .. arrayMotions(getMotions(getRoom())) .. "}") 90
Turn on watering after pushing the Button with ID 2066 or meeting one of the following conditions: on Monday, Wednesday or Friday at 6:00, temperature is above 3 degrees and is one of the following weather conditions: foggy, clear or cloudy
Conditions:
1{ 2 conditions = { { 3 id = 2066, 4 isTrigger = true, 5 operator = "==", 6 property = "centralSceneEvent", 7 type = "device", 8 value = { 9 keyAttribute = "Pressed", 10 keyId = 1 11 } 12 }, { 13 conditions = { { 14 isTrigger = false, 15 operator = "match", 16 property = "cron", 17 type = "date", 18 value = { "*", "*", "*", "*", "1,3,5", "*" } 19 }, { 20 isTrigger = true, 21 operator = "match", 22 property = "cron", 23 type = "date", 24 value = { "00", "06", "*", "*", "*", "*" } 25 }, { 26 isTrigger = true, 27 operator = "<", 28 property = "temperature", 29 type = "weather", 30 value = 3 31 }, { 32 conditions = { { 33 isTrigger = true, 34 operator = "==", 35 property = "weatherCondition", 36 type = "weather", 37 value = "fog" 38 }, { 39 isTrigger = true, 40 operator = "==", 41 property = "weatherCondition", 42 type = "weather", 43 value = "clear" 44 }, { 45 isTrigger = true, 46 operator = "==", 47 property = "weatherCondition", 48 type = "weather", 49 value = "cloudy" 50 } }, 51 operator = "any" 52 } }, 53 operator = "all" 54 } }, 55 operator = "any" 56}
Actions:
1local wateringTime = 20 2fibaro.call(2055, 'turnOn') 3fibaro.setTimeout(wateringTime * 60 * 1000, function() 4fibaro.call(2055, 'turnOff') 5end)
Turn on watering after pushing the Button with ID 2066 or meeting one of the following conditions: on Monday, Wednesday or Friday at 6:00, temperature is above 3 degrees, soil moisture sensor with ID 35 detects moisture below 20%, and is one of the following weather conditions: foggy, clear or cloudy
Conditions:
1{ 2 conditions = { { 3 id = 2066, 4 isTrigger = true, 5 operator = "==", 6 property = "centralSceneEvent", 7 type = "device", 8 value = { 9 keyAttribute = "Pressed", 10 keyId = 1 11 } 12 }, { 13 conditions = { { 14 id = 35, 15 isTrigger = false, 16 operator = "<", 17 property = "value", 18 type = "device", 19 value = 20 20 }, { 21 isTrigger = false, 22 operator = "match", 23 property = "cron", 24 type = "date", 25 value = { "*", "*", "*", "*", "1,3,5", "*" } 26 }, { 27 isTrigger = true, 28 operator = "match", 29 property = "cron", 30 type = "date", 31 value = { "00", "06", "*", "*", "*", "*" } 32 }, { 33 isTrigger = true, 34 operator = "<", 35 property = "temperature", 36 type = "weather", 37 value = 3 38 }, { 39 conditions = { { 40 isTrigger = true, 41 operator = "==", 42 property = "weatherCondition", 43 type = "weather", 44 value = "fog" 45 }, { 46 isTrigger = true, 47 operator = "==", 48 property = "weatherCondition", 49 type = "weather", 50 value = "clear" 51 }, { 52 isTrigger = true, 53 operator = "==", 54 property = "weatherCondition", 55 type = "weather", 56 value = "cloudy" 57 } }, 58 operator = "any" 59 } }, 60 operator = "all" 61 } }, 62 operator = "any" 63}
Actions:
1local wateringTime = 20 2fibaro.call(2055, 'turnOn') 3fibaro.setTimeout(wateringTime * 60 * 1000, function() 4fibaro.call(2055, 'turnOff') 5end)
Turn on watering after pushing the Button with ID 2066 or meeting one of the following conditions: on Monday, Wednesday or Friday at 6:00
Conditions:
1{ 2 conditions = { { 3 id = 2066, 4 isTrigger = true, 5 operator = "==", 6 property = "centralSceneEvent", 7 type = "device", 8 value = { 9 keyAttribute = "Pressed", 10 keyId = 1 11 } 12 }, { 13 conditions = { { 14 isTrigger = false, 15 operator = "match", 16 property = "cron", 17 type = "date", 18 value = { "*", "*", "*", "*", "1,3,5", "*" } 19 }, { 20 isTrigger = true, 21 operator = "match", 22 property = "cron", 23 type = "date", 24 value = { "00", "06", "*", "*", "*", "*" } 25 } }, 26 operator = "all" 27 } }, 28 operator = "any" 29}
Actions:
1local wateringTime = 20 2fibaro.call(2055, 'turnOn') 3fibaro.setTimeout(wateringTime * 60 * 1000, function() 4fibaro.call(2055, 'turnOff') 5end)
Close the valves and send an email with notification if one of the water sensors has been activated
Conditions:
1{ 2 conditions = { { 3 id = 2073, 4 isTrigger = true, 5 operator = "==", 6 property = "value", 7 type = "device", 8 value = true 9 }, { 10 id = 2074, 11 isTrigger = true, 12 operator = "==", 13 property = "value", 14 type = "device", 15 value = true 16 } }, 17 operator = "any" 18}
Actions:
1local users = {2,3,4} -- users ids 2local valvesIds = {204, 205}; -- IDs of all valves 3local usePushNotifications = true -- true if push notification should be send with push 4local valveNO = true; -- "true" if valve is normally open, "false" if NC 5 6function closeValves() 7 if valveNO == true then 8 fibaro.call(valvesIds, "turnOn") 9 else 10 fibaro.call(valvesIds, "turnOff") 11 end 12end 13 14closeValves(); -- closing valves 15fibaro.alert('email', users, "You're drowning") 16if usePushNotifications == true then 17 fibaro.alert('push', users, "You're drowning") 18end