Luup plugin icons
The Luup plugin static JSON file describes the icon that appears in the dashboard of the UI4 web interface.
Contents |
Icon format
All of Vera's icons are 42x42 pixel PNGs with transparency. Icons of other sizes will be resized to 42x42.
Configuration
The top-level key flashicon contains a string. This string is the name of an image file. The filename is either a relative path or a URL starting with "http".
Relative paths
If the filename is a relative path, it is relative to the directory /www/cmh/skins/default on the Vera. If the filename ends in the string ".swf", this extension is changed to ".png". (This is presumably a holdover from UI3, which was flash-based. In UI4, there is no reason to maintain this ruse, so just use the ".png" extension.)
Files installed in the "icons" directory are:
- Binary_Light.png
- Binary_Light_0.png
- Binary_Light_100.png
- Dimmable_Light.png
- Dimmable_Light_0.png
- Dimmable_Light_100.png
- Dimmable_Light_25.png
- Dimmable_Light_50.png
- Dimmable_Light_75.png
- Door_Lock.png
- Door_Lock_0.png
- Door_Lock_100.png
- Generic_IO.png
- Humidity_Sensor.png
- IR_Transmitter.png
- Insteon.png
- Ip_Camera.png
- Light_Sensor.png
- Motion_Sensor.png
- Motion_Sensor_0.png
- Motion_Sensor_100.png
- Power_Meter.png
- Scenes.png
- Temperature_Sensor.png
- Thermostat.png
- USB_UIRT.png
- Window_Covering.png
- Zwave.png
- advanced.png
- default.png
- default_device.png
- default_panel.png
- default_plugins.png
- device.png
- devices.png
- energy.png
- findvera.png
- generic_icon.png
- generic_sensor.png
- intro.png
- location.png
- music_audio.png
- plugins.png
- users.png
URLs
If the filename is a URL, it refers to a remote file on a web server.
Constant icons
For an icon that remains the same all the time, the flashicon key is all you need to provide. Ensure that the static JSON file does not contain a DisplayStatus key, and you are done.
Variable icons
For an icon that varies based on the value of a variable, place a DisplayStatus key at the top level of the static JSON file. Its value is a JSON object (associative array) with four keys:
- Service
- The Service ID of the variable that controls the icon. This can be found in the matching device XML file, under the serviceId element.
- Variable
- The variable name of the variable that controls the icon.
- MinValue
- The value that this variable has when it is considered "off" or at "0%". This can even be a string, if the variable is a string that takes two values.
- MaxValue
- The value that this variable has when it is considered "on" or at "100%". This can even be a string, if the variable is a string that takes two values.
Example for a binary switch:
"DisplayStatus": { "Service": "urn:upnp-org:serviceId:SwitchPower1", "Variable": "Status", "MinValue": "0", "MaxValue": "1" }
Example for a variable which takes on a range of values.
"DisplayStatus": { "Service": "urn:upnp-org:serviceId:Dimming1", "Variable": "LoadLevelStatus", "MinValue": "0", "MaxValue": "100" }
The filename in flashicon undergoes a special transformation for variable icons. The extension ".png" is changed to "_0.png", "_25.png", "_50.png", "_75.png" or "_100.png" depending on the value of the service variable, linearly scaled from its range of 0:(MaxValue-MinValue) to 0:100. Values round up; 1-25 produces the "_25" image; 26-50 produces the "_50" image, and so on. For images which are not found (for instance, if the web server returns 404 Not Found) the default image is used.
Consequently, at least three images, and as many as six, should be present for variable-icon plugins. For example, if flashicon contains http://example.com/image.png, the web server must be able to serve:
- http://example.com/image.png (for when the plugin is loading in the Luup engine)
- http://example.com/image_0.png
- http://example.com/image_100.png
and it should be able to serve (if the variable is a sliding scale):
- http://example.com/image_25.png
- http://example.com/image_50.png
- http://example.com/image_75.png
state_icons
From firmware 1.5.401 onwards, you must also tell the Static JSON file which icon files exist, with the state_icons key at the top level. The corresponding value is a JSON array of strings, the file names which should be displayed in the UI. This key was added to prevent the plethora of 404 errors that would appear in the JavaScript console.
Currently each device can have a maximum of 5 icons. The formula for choosing the icon is this:
var status = Variable / (MaxValue - MinValue); var val = ceil( status * 4 ); var icon = baseIconName + "_" + (isNaN( val * 25 ) ? 0 : (val * 25)) + ".png";
e.g. For the dimmable light, the formula would look like this:
var status = LoadLevelStatus / (100 - 0); var val = ceil( status * 4 ); var icon = "Dimmable_Light" + "_" + (isNaN( val * 25 ) ? 0 : (val * 25)) + ".png";
The resulting intervals and icons are:
LoadLevelStatus | Icon |
---|---|
0 | Dimmable_Light_0.png |
1 - 25 | Dimmable_Light_25.png |
26 - 50 | Dimmable_Light_50.png |
51 - 75 | Dimmable_Light_75.png |
76 - 100 | Dimmable_Light_100.png |
Cheating to get finer-grained variable icons
The JavaScript code that inserts the strings "_0" to "_100" into the image filename does not check that the raw variable value is in the range MinValue to MaxValue. By deliberately choosing a MaxValue less than the highest value that a variable can take, you can make the JavaScript load images with "_125", "_150", etc., effectively providing any number of images. MinValue is similarly handled, though the results are odd with negative variables or MinValue not equal to zero: the string inserted into the filename is "_-25", "-50", etc.
That this trick works is probably accidental, and its behaviour probably should not be relied on.
UI7 Icons
To avoid adding extra code to treat plugin icons, all plugin developers should take into consideration the following:
- "default_icon"
"flashicon" - we don't use it any more, instead we will have "default_icon" as in the above example, which can be either the url from a image uploaded somewhere on the web or a image stored locally in skins/default/img/devices/device_sates/ . Please be sure if you choose the last method to not upload images with names identical to any of the existing device state icon files. Image resolution should be 50px x 50px.
- "state_icons"
If the device created by the plugin has states and we need to display them we will use this object. "img" is the state image, same as above, it's a url to a image uploaded on the web or the name of a image stored locally in skins/default/img/devices/device_sates/. "conditions" is an array of objects from which we build logical expressions and evaluate them to decide what icon to be used for what state. In the example above if in lu_status for a given binary light with "subcategory_num" = 0 ( this means indoor binary light , because we also have devices for outdoor use like the Jasco 45604) we find service : "urn:upnp-org:serviceId:SwitchPower1", variable : "Status" and the value from this pair is equal ("operator") to the "value" (0) in the conditions object then we show the "binary_light_off.png" in the UI (light is off). A good example of usage for "subcategory_num" can be seen in the json definition of the motion sensor D_MotionSensor1.json - which serves as template for a number of types of sensors but I am not sure if this will be the case for plugins("subcategory_num" is not mandatory). As I said "conditions" is an array of objects, this means that if we want to display a certain icon based on more than 1 condition we can do so by adding to it more objects defining different conditions.
Example:
{ "default_icon": "binary_light_default.png", "state_icons": [ { "img": "binary_light_off.png", "conditions": [ { "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "operator": "==", "value": 0, "subcategory_num": 0 } ] }, { "img": "binary_light_on.png", "conditions": [ { "service": "urn:upnp-org:serviceId:SwitchPower1", "variable": "Status", "operator": "==", "value": 1, "subcategory_num": 0 } ] } ], ... }