Table of contents
- Description
- Turn off the heating when the window is opened
- Turning the device on and off after 5 seconds
- Turn on the Wall Plug when The Button pressed twice
- Turn off the Wall Plug when The Button pressed 4 times
- Turn off the Wall Plug when you are leaving the point and it is a storm outside
- Set dimmer to a value:57
- Control the temperature with hysteresis
- Turning off the heater, when the window is opened
Description
Do you want to create scenes in Lua but you don’t know how? In this article you can find some examples that you can use.
Looking for something else? Need help? Check FIBARO Forum for more!
Remember to change deviceID in the code!
Turn off the heating when the window is opened
This scene will switch off the thermostat when the window is opened.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
--[[ %% properties %% events %% globals --]] local myVariable myVariable = fibaro:getValue(55, 'value') --55 - deviceID of the Door/Window Sensor 2 if (myVariable == '1') then fibaro:call (97, 'turnOff') --97 - deviceID of The Heat Controller end |
Change the device state to the opposite when the motion sensor is breached
This scene will turn on or turn off the device whenever Motion Sensor will be breached.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
--[[ %% properties 90 value %% events %% globals --]] local myVariable1 local myVariable2 myVariable1 = fibaro:getValue(90, 'value') -- 90 - deviceID of the Motion Sensor fibaro:debug('value = ' .. myVariable1) myVariable2 = fibaro:getValue(27, 'value') -- 27 - deviceID of the Wall Plug fibaro:debug('value = ' .. myVariable2) if (myVariable1 == '1') then if (myVariable2 == '0') then fibaro:call(27, 'turnOn') else fibaro:call(27, 'turnOff') end end |
Turning the device on and off after 5 seconds
This scene will turn on the device for the specified period of time. In these case 5 seconds (5000). The time 5000 is expressed in mili-seconds. 1s = 1000ms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
--[[ %% properties %% events %% globals --]] local myVariable fibaro:debug('I will turn on the device with deviceID=27') -- 27 - deviceID of the Wall Plug fibaro:call(27, 'turnOn') myVariable = fibaro:getValue(27, 'value') fibaro:debug('Value of my variable = ' .. myVariable) fibaro:debug('Now I will turn off the device') fibaro:debug('Now I will wait for a 5 seconds') fibaro:sleep(5000) fibaro:call(27, 'turnOff') myVariable = fibaro:getValue(27, 'value') fibaro:debug('Now value of my variable = ' .. myVariable) |
Turn on the Wall Plug when The Button pressed twice
This scene will turn on the device when The Button will be pressed two times.
1 2 3 4 5 6 7 8 9 10 11 |
--[[ %% properties %% events 122 CentralSceneEvent 1 Pressed2 -- 122 - deviceID of The Button %% globals --]] fibaro:call(27, 'turnOn') -- 27 - deviceID of the Wall Plug |
Turn off the Wall Plug when The Button pressed 4 times
This scene will turn off the device when The Button will be pressed 4 times.
1 2 3 4 5 6 7 8 9 10 11 |
--[[ %% properties %% events -- 122 - deviceID of The Button 122 CentralSceneEvent 1 Pressed4 %% globals --]] fibaro:call(27, 'turnOff') -- 27 - deviceId of the Wall Plug |
Turn off the Wall Plug when you are leaving the point and it is a storm outside
This scene will turn off the device when you won’t be home and it will be a storm outside.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
--[[ %% properties 2 Location -- 2 - Admin account %% weather WeatherCondition %% events %% globals --]] local startSource = fibaro:getSourceTrigger(); if ( ( (fibaro:calculateDistance(fibaro:getValue(2, "Location"), "52.463755179509526;16.905060528498552") > 30 and fibaro:calculateDistance(fibaro:getValue(2, "PreviousLocation"), "52.463755179509526;16.905060528498552") <= 30) and api.get('/weather')['WeatherCondition'] == "storm" ) or startSource["type"] == "other" ) then fibaro:call(27, "turnOff"); -- 27 - deviceID of the Wall Plug end |
Set dimmer to a value:57
This scene will set the value of the Dimmer for 57.
1 2 3 4 5 6 7 8 9 10 11 |
--[[ %% properties %% events %% globals --]] fibaro:call(72, "setValue", "57") -- 72 - deviceId of the Dimmer |
Control the temperature with hysteresis
This scene will turn on/off the heater depending on the difference between measured temperature and setpoint (saved in the global variable) with 0.5 hysteresis.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
--[[ %% properties 71 value %% events %% globals targetTemp --]] -- ID of the Motion Sensor (temperature node) local tempSensorID = 71 -- ID of Relay Switch local heaterID = 62 fibaro:debug( fibaro:getValue(tempSensorID, "value") ) -- hysteresis margin in Celcius local hysteresis = 0.5 -- if temperature is lower than target value by more than set margin if tonumber(fibaro:getValue(tempSensorID, "value")) < (fibaro:getGlobalValue("targetTemp") - hysteresis) then -- turn on the heating fibaro:call(heaterID, "turnOn") -- if temperature is higher than target value by more than set margin elseif tonumber(fibaro:getValue(tempSensorID, "value")) > (fibaro:getGlobalValue("targetTemp") + hysteresis) then -- turn off the heating fibaro:call(heaterID, "turnOff") end |
Turning off the heater, when the window is opened
This scene will turn off/on the heater when the window is opened/closed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
--[[ %% properties 79 value %% events %% globals --]] -- ID of Door/Windor Sensor local windowID = 79 -- ID of Relay Swich or Wall Plug local heaterID = 134 -- check if window was opened if tonumber(fibaro:getValue(windowID, "value")) > 0 -- and heater/radiator is turned on and tonumber(fibaro:getValue(heaterID, "value")) > 0 then -- turn off heating fibaro:call(heaterID, "turnOff"); -- set flag to remember that function was activated fibaro:setGlobal("UsedAutoOff", "Yes"); -- check if window was closed elseif tonumber(fibaro:getValue(windowID, "value")) == 0 -- and auto off function was activeted and fibaro:getGlobalValue("UsedAutoOff") == "Yes" then -- turn on heating fibaro:call(heaterID, "turnOn"); -- reset flag fibaro:setGlobal("UsedAutoOff", "No"); end |
November 13, 2018 40177 Tutorials
Total 22 Votes:
0
22