The main html file, index.html, uses the starter template of bootstrap.js library. This allows for responsive design support with navigation and a flexible grid.
On initial loading of the page, you will see a top navigation and grid of control cards. These cards are instances of modules that are loaded dynamically from the server.
A module is a template including html, javascript and css that is loaded from the server. A module can be instantiated multiple times with different settings. The instances are what get rendered as cards in the User Interface. The list of module instances to render on the page is retrieved from modules/instances.json.
To load the module instances as cards on the page, the Control Panel does the following from ModuleLoader.loadControlPanel:
index.html
(html template), script.js
(js), styles.css
(css)<div class="col-xs-18 col-sm-6 col-md-3"></div>
so that it adapts to smaller screen sizesNote: The UI code in ModuleLoader is designed to only show maximum 4 modules per row. So a new row is created for every 4 module instances.
Each module has a module id. The module's id is defined by its directory name (e.g. modules/thermostat
has module id "thermostat").
In order to be loaded, the module's directory must have the following files:
modules/{module-id}/index.html
- underscore.js template html file for the module's card UImodules/{module-id}/script.js
- javascript file used to manage the card's UI events and server communicationmodules/{module-id}/styles.css
- Custom CSS styles specific to the module's index.htmlTwo modules are available out-of-the-box:
modules/thermostat
modules/light-control
Control panel data updates are retrieved from data.json by the moduleDataManager
object every 15s (see js/home-automation.js for the source code). In order to receive these updates, a module must register a listener via moduleDataManager.addListener(...)
. Note that the data is refreshed from the server every 15 seconds and since the application currently has no server-side code it just retrieves the original values. So if you flip switches of a card then the values would automatically go back to their old values.
Modules must use HTTP POST $.ajax({url: url, method: "post"})
requests to post updates back to the server. These updates need to be sent to modules/{custom-module-id}/data/{module-instance-id}.json
.
To create your own custom control panel module, follow these steps:
registerEventListeners
and receiveData
functions