If you have ever wondered what the format of the virtual device (vfib) is then here it is.
It is basically a squashed json file. JSON stands for JavaScript
Object Notation and has been adopted as a standard for data swapping across platforms.
{
"name": "RH Garage Door",
"type": "virtual_device",
"properties": {
"deviceIcon": 1022,
"categories": "[\"other\"]",
"currentIcon": "1025",
"log": "",
"logTemp": "",
"mainLoop": "local name = 'Grg Door Right';\n local id = fibaro:getSelfId ();\n
local sensor = fibaro:getValue ('540', 'value');\n\n if sensor ~= '0'\nthen\n
--fibaro:call (device, \"setProperty\", \"ui.LabelStatus.value\", \"OPEN\");\n
fibaro:call (id, 'setProperty', 'currentIcon', 1026);\n
fibaro:startScene (132,{{['add']=name..' Open'}});\nelse \n
--fibaro:call (device, \"setProperty\", \"ui.LabelStatus.value\", \"CLOSED\");\n
fibaro:call (id, 'setProperty', 'currentIcon', 1025);\n
fibaro:startScene (132,{{['add']=name..' Closed'}});\nend",
"visible": "true",
"rows": [
{
"type": "label",
"elements": [
{
"id": 1,
"lua": false,
"waitForResponse": false,
"caption": "Status",
"name": "LabelStatus",
"favourite": false,
"main": false
}
]
},
{
"type": "button",
"elements": [
{
"id": 2,
"lua": true,
"waitForResponse": false,
"caption": "Open",
"name": "ButtonOpen",
"empty": false,
"msg": "fibaro:call ('214', 'turnOn')",
"buttonIcon": 1027,
"favourite": false,
"main": false
},
{
"id": 3,
"lua": true,
"waitForResponse": false,
"caption": "Close",
"name": "ButtonClose",
"empty": false,
"msg": "fibaro:call ('214', 'turnOff')",
"buttonIcon": 1027,
"favourite": false,
"main": false
}
]
},
{
"type": "button",
"elements": [
{
"id": 4,
"lua": true,
"waitForResponse": false,
"caption": "Toggle",
"name": "ButtonToggle",
"empty": false,
"msg": "local sensor = fibaro:getValue ('540', 'value');\n\n
if sensor ~= '0'\n
then \n
fibaro:call ('214', 'turnOff')\nelse \n
fibaro:call ('214', 'turnOn')\nend",
"buttonIcon": 1027,
"favourite": false,
"main": true
}
]
}
]
},
"actions": {
"pressButton": 1,
"setSlider": 2,
"setProperty": 2
}
}
This is a 3 row user interface with a block of main code and a block of code for a button :
rows is an array of visual elements, in this case three of them.
msg is the actual Lua code for that element. Lines are separated with `\n`.mainLoop is the main loop's Lua code.deviceicon is the normal icon assigned to the device.currenticon is the icon at present. Note, you are able to change the icon at run time.Here is the Lua code expanded for the button action.
local sensor = fibaro:getValue ('540', 'value');
if sensor ~= '0'
then
fibaro:call ('214', 'turnOff')
else
fibaro:call ('214', 'turnOn')
end
Please donate if helpful