Pacific Blue Software Logo

Making sense of the structure of the Virtual Device file in Fibaro

Investigating the structure of the Virtual Device file used by HC2

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.


A sample of .vfib file

{
  "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
  }
}

Summary

This is a 3 row user interface with a block of main code and a block of code for a button :

Sample Code

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
    

Dissecting the structure of the .vfib file


Back to Articles for Developers
Back to Articles on Lua
Investigating the structure of the Quick Apps file used by HC3

If you found this useful, then please consider making a donation.

paypal
QR Code for donation Please donate if helpful