Lua Scenes — actions
Actions are executed one after the other (except for "fibaro.setTimeout" - described further). Following actions are available:
sourceTrigger
The variable stores the trigger object that started the scene. It results directly from the triggers defined in the previous section, but is extended by a manual start. Type of the trigger is identified by type property, which can be one of the following:
- manual
- alarm
- custom-event
- date
- device
- global-variable
- location
- panic
- profile
- se-start
- weather
- climate
Examples values of sourceTrigger variable.
Manual start
1{ 2 type = "manual", 3 property = "execute" 4}
Trigger based on device property change
Property centralSceneEvent for device with id 298 triggered the scene.
1{ 2 type = "device", 3 value = { 4 keyId = 1, 5 keyAttribute = "Pressed" 6 }, 7 property = "centralSceneEvent", 8 id = 298 9}
Time trigger
Specific time and date triggered the scene.
1{ 2 type = "date", 3 property = "cron", 4 value = { "47", "11", "19", "12", "4", "2019" } 5}
Trigger based on alarm state change
Arming zone with id 4 triggered the scene.
1{ 2 value = true, 3 id = 4, 4 type = "alarm", 5 property = "armed" 6}
api.delete
api.delete(uri)
Delete resource using gateway API. Parameters:
- uri - path to the resource without
/apiprefix.
Action returns: {response data, response HTTP code}.
Examples: Delete global variable with name "test".
1local data, status = api.delete('/globalVariables/test')
api.get
api.get(uri)
Get resource using gateway API. Parameters:
- uri - path to the resource without
/apiprefix.
Action returns: {response data, response HTTP code}.
Examples: Get value of global variable with name "test".
1local data, status = api.get('/globalVariables/test')
api.post
api.post(uri, dane)
Send POST method request to the gateway API. Parameters:
- uri - path to the resource without
/apiprefix, - dane - data to send with the request.
Action returns: {response data, response HTTP code}.
Examples: Create global variable with name "test" and value "sampleValue".
1local requestData = { 2 name = 'test', 3 isEnum = false, 4 readOnly = false, 5 value = 'sampleValue' 6} 7local responseData, status = api.post('/globalVariables', requestData)
api.put
api.put(uri, dane)
Send PUT method request to the gateway API. Parameters:
- uri - path to the resource without
/apiprefix, - dane - data to send with the request.
Action returns: {response data, response HTTP code}.
Examples: Change value of global variable with name "test" to value "sampleValue2".
1local requestData = { 2 value = 'sampleValue2' 3} 4local responseData, status = api.put('/globalVariables/test', requestData)
fibaro.call
fibaro.call(id, action_name, arguments)
Executes an action on the device. Parameters:
- id - identifier of the device on which we want to execute the action.
- action_name - the name of the action we want to execute.
- arguments - list of arguments that the action accepts.
Examples:
- Execute "turnOn" action on device with id 30.
1fibaro.call(30, "turnOn")
- Execute "setConfiguration" action on device with id 31 with arguments:
- parameter number - 11
- size of the parameter in bytes - 1
- value of the parameter to set - 128
1fibaro.call(31, "setConfiguration", 11, 1, 128)
fibaro.call(ids, action_name, arguments)
Executes an action on devices. Parameters:
- ids - list of device identifiers on which to execute the action.
- action_name - the name of the action we want to execute.
- arguments - list of arguments the action accepts.
Example: Execute "turnOn" action on devices with id 30 and 32.
1fibaro.call({30, 32}, "turnOn")
fibaro.callGroupAction
fibaro.callGroupAction(action_name, arguments)
Executes an action on the devices. Parameters:
- action_name - the name of the action we want to execute.
- arguments - list of arguments that the function accepts and device filter.
The action returns a list of devices on which it was performed.
Examples: Calling the turnOn action on com.fibaro.zwaveDevice devices that do not have the battery interface.
1local body = { 2 "args": [], 3 "filters": 4 [ 5 { 6 "filter": "type", 7 "value": ["com.fibaro.zwaveDevice"] 8 }, 9 { 10 "filter": "not", 11 "value": 12 { 13 "filter": "interface", 14 "value": ["battery"] 15 } 16 } 17 ] 18} 19 20fibaro.callGroupAction("turnOn", body)
fibaro.get
fibaro.get(id, property_name)
Gets value of device property and the date it was last modified. Parameters:
- id - device ID for which we want to retrieve the property value.
- property_name - name of the property which value we want to retrieve.
Action returns: {value, last modification time}.
Examples: Get the value and the date of the last modification for the value property for device 54
1local value, modificationTime = fibaro.get(54, "value")
fibaro.getValue
fibaro.getValue(id, property_name)
Gets the value of the given property. Parameters:
- id - device ID for which we want to retrieve the property value.
- property_name - name of the property which value we want to retrieve.
Action returns only value of the property.
Examples: Retrieving the value of the value property for device id 54
1local value = fibaro.getValue(54, "value")
fibaro.getType
fibaro.getType(id)
Gets the device type. Parameters:
- id - device ID for which we want to retrieve its type.
The action returns the device type.
Examples: Retrive type of device 54
1local type = fibaro.getType(54)
fibaro.getName
fibaro.getName(id)
Gets the device name. Parameters:
- id - device ID for which we want to retrieve its name.
The action returns the device name.
Examples: Retrive name of device 54
1local type = fibaro.getName(54)
fibaro.getRoomID
fibaro.getRoomID(id)
Gets the ID of the room to which the device is assigned. Parameters:
- id_urządzenia - device ID for which we want to retrieve its room ID.
The action returns the ID of the room to which the device is assigned.
Examples: Retrieve ID of the room for device 54
1local roomId = fibaro.getRoomID(54)
fibaro.getSectionID
fibaro.getSectionID(id)
Gets the ID of the section to which the device is assigned. Parameters:
- id_urządzenia - device ID for which we want to retrieve its section ID.
The action returns the ID of the section to which the device is assigned.
Examples: Retrieve ID of the section for device 54
1local sectionId = fibaro.getSectionID(54)
fibaro.getRoomName
fibaro.getRoomName(id)
Gets the room name. Parameters:
- id - room ID for which we want to retrieve name.
The action returns room name.
Examples: Retrive name for room 219
1local roomName = fibaro.getRoomName(219)
fibaro.getRoomNameByDeviceID
fibaro.getRoomNameByDeviceID(id)
Gets the name of the room to which the device is assigned. Parameters:
- id - device ID for which we want to retrieve its room name.
The action returns room name.
Examples: Retrieve name of the room for device 54
1local roomName = fibaro.getRoomNameByDeviceID(54)
fibaro.wakeUpDeadDevice
fibaro.wakeUpDeadDevice(id)
Wake up the device. Parameters:
- id - device ID to wake up.
Examples: Wake up device 54
1fibaro.wakeUpDeadDevice(54)
fibaro.getDevicesID
fibaro.getDevicesID(filter)
Returns a list of device IDs that match the given filters. Parameters:
- filter - the way we want to filter the devices.
fibaro.getAllDeviceIds
fibaro.getAllDeviceIds()
Returns a list of objects of all devices.
1local devices = fibaro.getAllDeviceIds()
fibaro.getIds
fibaro.getIds(devices)
Returns a list of device IDs for given devices.
- devices - accepts list of device objects.
1local devices = fibaro.getAllDeviceIds() 2local devicesId = fibaro.getIds(devices)
fibaro.homeCenter.systemService.reboot
fibaro.homeCenter.systemService.reboot()
Restart the gateway.
1fibaro.homeCenter.systemService.reboot()
fibaro.homeCenter.systemService.suspend
fibaro.homeCenter.systemService.suspend()
Put the gateway in Sleep Mode.
1fibaro.homeCenter.systemService.suspend()
fibaro.homeCenter.notificationService.publish
fibaro.homeCenter.notificationService.publish(request)
Publish notification. Parameters:
- request - object on the basis of which the notification will be created:
- type - notification type, one of the following:
"FirmwareUpdateNotification""GenericDeviceNotification""GenericSceneNotification""GenericSystemNotification""MobilePopupNotification""ZwaveReconfigurationNotification"
- priority - notification priority, one of the following:
"info"- lowest priority"warning"- medium priority"alert"- highest priority
- data - notification data, depending on type:
- FirmwareUpdateNotification
- deviceId - device ID
- progress - configuration progress (numerical value)
- info - information about update (text value)
- status - one of the following:
"Available""QueuedForUpdate""Downloading""WaitingForCommunication""Updating""UpdateOk""UpdateFail""UpToDate""QueuedForCheck"
- GenericDeviceNotification
- deviceId - device ID
- title - notification title (text value)
- text - notification description (text value)
- icon - notification icon (optional), object, accepting the following fields:
- path - path to the icon
- source - source of the icon
- GenericSceneNotification
- sceneId - scene ID.
- title - notification title (text value)
- text - notification description (text value)
- GenericSystemNotification
- subType - one of the following:
"Generic""EmailInvalid""DeviceNotConfigured""DeviceNoTemplate""NoFibaroPartitionInAlarm""ZwavePollingTime""UserNameDuplicated"
- name - notification title (text value)
- text - notification description (text value)
- url - text value
- urlText - text value
- subType - one of the following:
- MobilePopupNotification
- title - notification title (text value)
- text - notification description (text value)
- button - table of objects describing buttons and their operation. The object has the following fields:
- buttonId - button ID,
- type - button type, one of the following:
"STANDARD""CALL_112""CANCEL"
- caption - text value,
- onPressedAction - action performed when the button is pressed
- ZwaveReconfigurationNotification
- taskId - task ID (numerical value)
- deviceId - device ID
- status - one of the following:
"Pending""WaitingForWakeup""Reconfiguring""Failed""Canceled""Successful""Aborted"
- name - notification title (text value)
- FirmwareUpdateNotification
- type - notification type, one of the following:
Examples: Publish GenericDeviceNotification notification.
1local body = { 2 type = "GenericDeviceNotification", 3 priority = "info", 4 data = { 5 deviceId = 54, 6 title = "sampleTitle", 7 text = "sampleText", 8 icon = { 9 path = "fibaro/icons/com.fibaro.FGT001/com.fibaro.FGT001-off.png", 10 source = "HC" 11 } 12 } 13} 14local response, code = fibaro.homeCenter.notificationService.publish(body)
fibaro.homeCenter.notificationService.update
fibaro.homeCenter.notificationService.update(id, request)
Updates the notification. Parameters:
- id - ID of notification to update
- request - object on the basis of which the notification will be updated. A detailed description of the entire request can be found in point fibaro.homeCenter.notificationService.publish(request).
Examples: Update notification 10.
1local body = { 2 type = "GenericDeviceNotification", 3 priority = "info", 4 data = { 5 deviceId = 54, 6 title = "sampleTitle", 7 text = "sampleText", 8 icon = { 9 path = "fibaro/icons/com.fibaro.FGT001/com.fibaro.FGT001-off.png", 10 source = "HC" 11 } 12 } 13} 14local response, code = fibaro.homeCenter.notificationService.update(10, body)
fibaro.homeCenter.notificationService.remove
fibaro.homeCenter.notificationService.remove(id)
Deletes the notification. Parameters:
- id - ID of notification to delete
Examples: Delete notification 60.
1local response, code = fibaro.homeCenter.notificationService.remove(60)
fibaro.alert(alert_type, user_ids, notification_content)
Send custom notification.
- alert_type - one of the notification types: "email", "sms" or "push"
- user_ids - list of user identifiers to send the notification to
- notification_content - content of the notification to send
Examples: Send notification with "Test notification" content using email to users with id 2, 3 and 4.
1fibaro.alert("email", {2,3,4}, "Test notification")
fibaro.emitCustomEvent
fibaro.emitCustomEvent(event_name)
Emitting Custom Event with the specified name. Parameters:
- event_name - the name of the event we want to emit
Examples: Emitting the event with the name "TestEvent".
1fibaro.emitCustomEvent("TestEvent")
fibaro.debug
fibaro.debug(tag, message)
Displaying debug level text message in the debugging console. Parameters:
- tag - message tag, can be used to filter messages
- message - the content of the message which shows up in the debug window
Examples: Display "Test message" in a debug window with the tag "TestTag":
1fibaro.debug("TestTag", "Test message")
fibaro.trace
fibaro.trace(tag, message)
Displaying trace level text message in the debugging console. Parameters:
- tag - message tag, can be used to filter messages
- message - the content of the message which shows up in the debug window
Examples: Display "Test message" in a debug window with the tag "TestTag":
1fibaro.trace("TestTag", "Test message")
fibaro.warning
fibaro.warning(tag, message)
Displaying warning level text message in the debugging console. Parameters:
- tag - message tag, can be used to filter messages
- message - the content of the message which shows up in the debug window
Examples: Display "Test message" in a debug window with the tag "TestTag":
1fibaro.warning("TestTag", "Test message")
fibaro.error
fibaro.error(tag, message)
Displaying error level text message in the debugging console. Parameters:
- tag - message tag, can be used to filter messages
- message - the content of the message which shows up in the debug window
Examples: Display "Test message" in a debug window with the tag "TestTag":
1fibaro.error("TestTag", "Test message")
fibaro.alarm
fibaro.alarm(partition_id, action)
Executes specified action on one partition. Parameters:
- partition_id - partition on which we want to execute the action,
- action - the action we want to execute. Available actions: "arm", "disarm"
Examples: Arm partition no. 1:
1fibaro.alarm(1, "arm")
fibaro.alarm(action)
Executes specified action on all partitions. Parameters:
- action - action to be executed on all partitions. Available actions: "arm", "disarm"
Examples: Disarm all partitions:
1fibaro.alarm("disarm")
fibaro.scene
fibaro.scene(action, scenes_ids)
Executes given action on a scene. Parameters:
- action - the action we want to perform on scenes, one of the following:
"execute"- uruchomienie sceny"kill"- zatrzymanie sceny
- scenes_ids - list of scenes IDs to perform the action on
Examples: Execute scenes with IDs 1, 2, 3.
1fibaro.scene("execute", {1, 2, 3})
Stop scenes with IDs 1, 2, 3
1fibaro.scene("kill", {1, 2, 3})
fibaro.setSkin
fibaro.setSkin(user_ids, theme)
Sets the selected interface color theme for the user. Parameters:
- user_ids - list of user IDs for which the selected theme should be activated
- theme - color theme to be set, one of the following:
"light"- light theme"dark"- dark theme
Examples: Set dark color theme for users 2 and 3:
1fibaro.setSkin({2, 3}, "dark")
fibaro.setSkin(theme)
Sets the selected interface color theme for all users. Parameters:
- theme - color theme to be set, one of the following:
"light"- light theme"dark"- dark theme
Examples: Set dark color theme for all users:
1fibaro.setSkin("dark")
fibaro.profile
fibaro.profile(profile_id, action)
Executes specified action on the user profile. Parameters:
- profile_id - ID of the profile on which we want to perform the action
- action - the action we want to execute on the profile. Currently, only
"activateProfile"action is available (activating the profile)
Examples: Activate profile with ID 1.
1fibaro.profile(1, "activateProfile")
fibaro.getGlobalVariable
fibaro.getGlobalVariable(variable_name)
Get the value of the global variable. Parameters:
- variable_name - name of variable to get the value of
Examples: Get the value of variable testVariable.
1local value = fibaro.getGlobalVariable("testVariable")
fibaro.setGlobalVariable
fibaro.setGlobalVariable(variable_name, variable_value)
Set the value of the global variable. Parameters:
- variable_name - the name of the variable we want to update
- variable_value - the new value for the variable
Examples: Change the value of testVariable to testValue.
1fibaro.setGlobalVariable("testVariable", "testValue")
fibaro.getSceneVariable
fibaro.getSceneVariable(variable_name)
Get the value of the scene variable.
Scene variables are variables that are passed between instances of the same scene and are only deleted if set to null.
Parameters:
- variable_name - name of variable to get the value of
Examples: Get the value of variable testVariable.
1local value = fibaro.getSceneVariable("testVariable")
fibaro.setSceneVariable
fibaro.setSceneVariable(variable_name, variable_value)
Set the value of the scene variable. If the variable does not exist, it will be created.
Scene variables are variables that are passed between instances of the same scene and are only deleted if set to null.
Parameters:
- variable_name - the name of the variable we want to update
- variable_value - the new value for the variable
Examples: Change the value of testVariable to 1.
1fibaro.setSceneVariable("testVariable", 1)
fibaro.setTimeout
fibaro.setTimeout(delay, function)
Performs the function asynchronously with a delay. Parameters:
- delay - delay in milliseconds after which the specified function will be performed,
- function - function, which will be executed with the delay.
Examples: Execute function with 30s delay which turns on the device (ID 40) and sets profile 1 as active.
1fibaro.setTimeout(30000, function() 2 fibaro.call(40, "turnOn") 3 fibaro.profile("activateProfile", 1) 4end)
fibaro.sleep
fibaro.sleep(delay)
Pauses the script execution for the set time (in milliseconds).
Examples: After 30s delay turn the device on (ID 30) and set profile 1 as active.
1fibaro.sleep(30000) 2fibaro.call(30, "turnOn") 3fibaro.profile("activateProfile", 1)
json.encode
json.encode(table)
Convert Lua table to the text represented in JSON format. Parameters:
- table - Lua table
Examples: Display sourceTrigger in the debug console.
1fibaro.debug("", json.encode(sourceTrigger))
json.decode
json.decode(text)
Convert the text represented in JSON format to Lua table. Parameters:
- text - data in JSON format
Examples:
1local tmp = "{\"test\":11}" 2local array = json.decode(tmp)