Bonjour à tous,
Comme évoqué dans un des topics du firmware avec @Lazer, j'initie un début de liste des différentes API-LUA et API-HTTP apparues suite aux évolutions de firmware.
Pour HC2 UNIQUEMENT
Cette liste est loin d'être exhaustive, je me suis basé sur les changelog des firmwares et le site https://developer.fibaro.com/.
Si vous en connaissez d'autres, n'hésitez pas (je pense à vous les MAITRES du LUA )
Les admins/modos, je vous laisse le soin de mettre le sujet où bon vous semble ;-), un sous-forum de HC2 peut-être.
These calls can be used to start increasing or decreasing Multilevel Switches (like Dimmer 2, RGBW or Roller Shutter 2 modules) value. 'x' and 'y' are optional parameters, used to set respectively time frame in which change should be applied and starting level. 'stopLevelChange' stops previously send action.
fibaro:call(ID, 'startLevelIncrease', x, y)
fibaro:call(ID, 'startLevelDecrease', x, y)
fibaro:call(ID, 'stopLevelChange')
Call used to get table with IDs of devices that meet requirement specified by 'x'.
fibaro:getDevicesId(x)
-- Examples:
print('All devices with parameter visible equal to "true" and enabled equal to "true":')
ids = fibaro:getDevicesId({visible = true, enabled = true})
print(json.encode(ids))
print('ALl devices with energy interface:')
ids = fibaro:getDevicesId({interfaces ={"energy"}})
print(json.encode(ids))
print('All devices with 'unit' property (no matter its value):')
ids = fibaro:getDevicesId({properties = {unit="nil"}})
print(json.encode(ids))
Which will set given scene respectively to Automatic, Manual and Disabled mode. Any other value will set scene triggering mode to Automatic.
fibaro:setSceneRunConfig(sceneID, runConfig)
where runConfig is string that takes one of these three values:
- TRIGGER_AND_MANUAL
- MANUAL_ONLY
- DISABLED
fibaro:getSceneRunConfig(sceneID)
returns currently set value.
Old functions will keep backward compatibility and continue to work without change.
- fibaro:setSceneEnabled(sceneID, enabled)
- fibaro:isSceneEnabled(sceneID)
Redémarrage Home Center et Arrêt Home Center
HomeCenter.SystemService.reboot() et HomeCenter.SystemService.shutdown()
Exemples :
-- Reboot system
HomeCenter.SystemService.reboot();
-- Shutdown system
HomeCenter.SystemService.shutdown();
Popup service
HomeCenter.PopupService.publish({title, subtitle, contentTitle, contentBody, img, type, buttons})
Parameters
title - string containing text to be displayed as a pop-up window title (parameter required)
subtitle - string containing text to be displayed as a pop-up window subtitle
contentTitle - string containing text to be displayed as a pop-up content title
contentBody - string containing text to be displayed as a pop-up content (parameter required)
img - string containing path of an image to be displayed in the pop-up window (supported extensions: .jpg, .bmp, .png, .gif)
type - notification type indicated with a colour, available types:
'Info' - blue (default)
'Success' - green
'Warning' - yellow
'Critical' - red
buttons - array containing definitions of buttons to be displayed in the pop-up, single button definition must be an array containing:
'caption' - text displayed on the button
'sceneId' - scene id triggered after pushing the button
Exemple 1
--[[
%% properties
%% globals
--]]
-- variable containing path of Motion Sensor’s icon
local imgUrl =
'http://www.fibaro.com/sites/all/themes/fibaro/images/motion-
sensor/en/motion_sensor_manual.png'
-- pop-up call
HomeCenter.PopupService.publish({
-- title (required)
title = 'No motion detected',
-- subtitle(optional), e.g. time and date of the pop-up call
subtitle = os.date("%I:%M:%S %p | %B %d, %Y"),
-- content header (optional)
contentTitle = 'No motion since last 15 minutes',
-- content (required)
contentBody = 'Should I run the scene "Night"?',
-- notification image (assigned from the variable)
img = imgUrl,
-- type of the pop-up
type = 'Success',
-- buttons definition
buttons = {
{ caption = 'Yes', sceneId = 0 },
{ caption = 'No', sceneId = 0 }
}
})
NOTE
Please note that the example scene must be triggered manually. It just illustrates the way of creating pop-ups. Execution of this scene will not affect any device status (sceneId = 0).
NOTE
Setting an action of the button to 'sceneId = 0' means that no action will be performed.
NOTE
Created pop-up is sent to each of users and mobile devices connected with the main controller.
NOTE
There is no maximum size of image displayed in the pop-up window. However, using too large file may result in long waiting times required for downloading the image.
NOTE
Pushing one of the buttons displayed in the pop-up window may only trigger another scene.
Exemple 2
--[[
%% properties
3814 value
%% globals
--]]
local startSource = fibaro:getSourceTrigger();
if (
( tonumber(fibaro:getValue(3814, "value")) > 60 )
or
startSource["type"] == "other"
)
then
HomeCenter.PopupService.publish({
title = 'Brightness level',
subtitle = 'is too high',
contentTitle = 'Dimmer',
contentBody = 'Would you like to turn it off?',
img = ' http://www.fibaro.com/images/eng/icon_osw.png',
type = 'Critical',
buttons = {
{ caption = 'Turn off', sceneId = 3228 },
{ caption = 'No', sceneId = 0 },
{ caption = 'Set to 100%', sceneId = 3229 }
}
})
end
1ère MAJ venant de @Steven concernant les fonctions fibaro :
Telecharger le tar.gz http://updatehc2.fibaro.com/4.083/
, puis dans opt/fibaro ouvrir fibaroSceneAPI.lua
Backups depuis une scène (Merci à @Nikko)
--[[
%% properties
%% events
%% globals
--]]
local portable = 385
local message = 'Backup du '..os.date("%d/%m/%y - %HH%M")
local url = 'http://127.0.0.1:11111/api/settings/backups'
local httpClient = net.HTTPClient()
httpClient:request(url , {
success = function(response)
if tonumber(response.status) == 201 then
print("Backup Created at " .. os.date())
fibaro:call(portable,'sendPush', message .. ' effectué')
else
print("Error " .. response.status)
fibaro:call(portable,'sendPush', 'Erreur lors de la création du Backup')
end
end,
error = function(err)
print('error = ' .. err)
end,
options = {
method = 'POST',
headers = {
["content-type"] = 'application/x-www-form-urlencoded;'
},
data = 'action=create&description='..message
}
});
- Attention, si planification avec GEA, dans la nuit, ca relance le zwave ;-)
GEA.add(true, 30, "", {{"Scenario", id}})
ASTUCES DIVERSES
Affichage persistent du LOG des VDs et couleurs possibles (merci @Steven et @Berale, je ne suis que le Scrib)
- Code à mettre dans le MAIN-LOOP
fibaro:log("Test")
fibaro:call(fibaro:getSelfId(), "setProperty", "logTemp", "TxtGray" )
- Couleurs possibles :
.TxtGreen
.TxtRed
.TxtYellow
.TxtBlue
.TxtGray
Exemple de @Nico
--1er bouton VD
local deviceId = fibaro:getSelfId();
fibaro:call(deviceId, "setProperty", "ui.Label1.value", "Repos")
-- Second bouton du VD
local deviceId = fibaro:getSelfId();
fibaro:call(deviceId, "setProperty", "ui.Label1.value", "Alarme")
fibaro:call(deviceId, "setProperty", "ui.Label2.value", os.date("%m %B %Y - %H:%M:%S"))
-- Mainloop pour affichage persistent du log
local deviceId = fibaro:getSelfId();
local value = fibaro:getValue(deviceId, "ui.Label2.value")
fibaro:log(value)
fibaro:call(fibaro:getSelfId(), "setProperty", "logTemp", "TxtGray" )
Affichage persistent HORS MAIN-LOOP
fibaro:call(fibaro:getSelfId(), "setProperty", "log", "blablabla" )
MISE à jour suite à la version stable 4.10 :
Merci à @Steven
fibaro:callGroupAction(action, filters)
{
"filter": "hasProperty",
"value": ["configured", "dead", "model"]
}
{
"filter": "interface",
"value": ["Z-Wave", "levelChange"]
}
{
"filter": "parentId",
"value": [664]
}
{
"filter": "type",
"value": ["com.fibaro.multilevelSwitch"]
}
{
"filter": "roomID",
"value": [2, 3]
}
{
"filter": "baseType",
"value": ["com.fibaro.binarySwitch"]
}
{
"filter": "isTypeOf",
"value": ["com.fibaro.binarySwitch"]
}
{
"filter": "isPlugin",
"value": [true]
}
{
"filter": "propertyEquals",
"value":
[
{
"propertyName": "configured",
"propertyValue": [true]
},
{
"propertyName": "dead",
"propertyValue": [false]
},
{
"propertyName": "deviceIcon",
"propertyValue": [15]
},
{
"propertyName": "deviceControlType",
"propertyValue": [15,20,25]
}
]
}
{
"filter": "deviceID",
"value": [55,120,902]
}
Parameters
action: action name
filters: filters object
Returned values
devices: array of device id's filtered by given rule.
Code example
--[[
%% properties
%% events
%% globals
--]]
local data =
{
args = { 1 },
filters =
{
{
filter = "roomID",
value = { 2 }
},
{
filter = "type",
value = { "com.fibaro.motionSensor" }
}
}
}
local devices = fibaro:callGroupAction("setArmed", data)
for k,v in ipairs(devices) do
print (v)
end
HomeCenter.NotificationService.publish(payload)
Name
Function name must be always the same: HomeCenter.NotificationService.publish
Application
Publishes notification.
Parameters
request: request object
Code example
HomeCenter.NotificationService.publish({
type = "GenericDeviceNotification",
priority = "warning",
data =
{
deviceId = 2643,
title = "foo",
text = "bar"
}
})
HomeCenter.NotificationService.update(id, payload)
Name
Function name must be always the same: HomeCenter.NotificationService.update
Application
Updates notification.
Parameters
id: notification id
request: request object
Code example
HomeCenter.NotificationService.update(7, {
canBeDeleted = true,
data =
{
title = "udapted foo",
text = "udapted bar"
}
})
HomeCenter.NotificationService.remove(id)
Name
Function name must be always the same: HomeCenter.NotificationService.remove
Application
Removes notification.
Parameters
id: notification id
Code example
HomeCenter.NotificationService.remove(7)
Info du jour concernant le centre de notification de la HC2, merci @tinman,
c'est ici :
- Pour utiliser le centre de notification avec des infos "perso" :
Tester et aprouvé en 4.10
function doNotify(text, devid)
api.post('/notificationCenter', {
type = 'GenericDeviceNotification',
canBeDeleted = true,
-- priority can be
-- alert -- red alert sign
-- warning -- yellow warning sign
-- info -- same as warning
priority = 'alert',
data = {
deviceId = devid,
text = text,
title = text
}
})
end
doNotify('Test notif HC2', 12 )