Happy holidays to everyone!
I have created a small HABPanel widget to simulate a scheduling interface for Virtual Thermostats and On Off appliances. Most of the parameters can be changed from the widget settings.
A word of caution! When I started working on this I had almost zero knowledge about: JavaScript, AngularJS, Xtend/Xbase. Now I am pretty much at the same level, hence it should not be used on your daily system without proper testing.
I have tested it only on Chrome (desktop), Firefox (desktop) and Chrome (Android), having OH 2.2 running on a Raspberry Pi 2B. It might not be rendered/work correctly on all browsers/devices.
TL;DR
The schedule data is stored in a JSON object, which is passed to an openHAB item. The JSON is structured using the next model (an example for a virtual thermostat):
{“Target_Temp_1”: {“D1”: {“T0500”: 24,“T0800”: 20},“D2”: {…},…“D7”: {…}},“Target_Temp_2”: {“D1”: {…},…}}
- Target_Temp_1 - the item which will receive the target temperature
- D1-D7 - week days
- Thhmm - time of the day
- value - target temperature to be set
Requirements:
- OH 2.2 (should work with all 2.x releases)
- Eclipse SmartHome Transformation Service (JsonPath)
Persistence binding (I am using jdbc + MySQL DB); some small changes are required on the rules files if persistence is not used.
Widget customizable parameters:
- Scheduler Type: Thermostat or On/Off Appliance
- Temperature min, max, step, unit and default target temperature
- Time (hour and minute) step
- Item that stores the schedule
- Item that contains the operating mode (manual, automatic …)
- The running modes list can be configured (an array of values should be passed); if not (correctly) defined, then the built-in modes will be used
- Disable target temperature change from the Status view/tab (will not apply if operating mode is MANUAL).
- Options to hide the Status tab and the Running Mode selector (basically only the scheduling part will be displayed/used)
There is only one parameter that needs more attention: the Items parameter. This parameter contains an array of objects defined as follows:
[{“setItem”: “TargetItem”, “label”: “Item Label”, “readItem”: “ReadItem”}, {…}]
Items object properties:
- setItem: this is the item that will be changed on execution (e.g. the item that stores the target temperature or the appliance switch state)
- label: the object/item label that will be displayed on the widget
- readItem: used only for virtual thermostat; current temperature item
Few words regarding the rules:
- The rule that parses the JSON containing the schedule is executed using a cron set to fire each minute. Additionally the rule will be fired if the item that stores the JSON is updated or if the operating mode item changes
(for those I used the persistence binding as currently there is no way to see what triggered the rule). - To avoid unnecessary CPU cycles the schedule processing will be put to sleep using timers. Here is a small difference between the thermostat (HVAC) rules and the OnOff ones.
- Changes are sent on a “queue” item (HVAC_Queue / OnOff_Queue)
For HVAC: the code parses the JSON schedule and sets the current target temperature, if none set. Then it determines the next change in schedule. If multiple items share the same day-time pair then those are added in the queue item, along with the new target temperature and then it sleeps until next change should occur. Once the timer expires the new values are set and the queue is populated with the next change.
OnOff: is built on the same model. The difference is the OnOff schedule model contains only the time when the switch item should be turned ON and the ON duration. The queue is used again, but this time it will trigger the OFF state.
Widget resources:
Sample Items, should be stored in <openhab_config>/items/:
- OHScheduler.items - sample items for both virtual thermostat and off appliances (it contains also the array of objects that should be used in the widget configuration with those items)
Please note that the lines 11,13 and 15 end with “{}”. There you should put your binding config for the temperature items. If no such binding available, and you want to set the item value manually (e.g. from rules for testing purposes) then you should remove those curly braces.
Rules, should be stored in <openhab_config>/rules/:
- OHSchedulerHVAC.rules - rules file for virtual thermostat
- OHSchedulerOnOff.rules - rules file for OnOff appliances
Widget JSON to be imported in HABPanel:
- OHScheduler.widget.json - the widget that should be imported in HABPanel
Widget resources (js, css, svg and html) should be stored in <openhab_config>/html/habpanel/scheduler/:
- ohscheduler.js - the JavaScript that does the heavy lifting for the above widget (used lots of factories as initially I wanted to split it in multiple files/controllers).
- ohscheduler.tpl.html - the widget html template used by the widgetScheduler directive
- ohscheduler.css , ohscheduler.svg - resources used by the widget
- vis.min.js - VisJS visualization library
- angular-vis.js - AngularJS directive module for VisJS components
What is missing/nice to have:
[Fixed in Beta v0.2] Widget refresh if the value changes for any of the used items (e.g. room temperature change).[Fixed in Beta v0.2] A nice theme/page arrangement.[Fixed in Beta v0.2] Use “controller as” in widget and JavaScript code.[Fixed in Beta v0.3] Schedule view: responsive design and display all events if there are more than one scheduled for the same hour (currently it will display only the last for each item).- Add/Edit view: items list responsive design.
- Mode: handle other operating modes (like holidays/hold the current target temperature).
- OnOff scheduling validation: no other event scheduled between (schedule start time) and (schedule start time + duration). Please note that this shouldn’t affect the rules.
- Code optimization (this is placed on the nice to have list due to my lack of knowledge/experience).
Hope I managed to stir your interest. Take it for a spin and share your thoughts. In case of issues please share also the entire log from the browser console (-F12-), preferably after you have ticket the box “Enable Debug” from the widget config.
PS: I know this does not match the openHAB design pattern, but since there is no way to manage a virtual thermostat from a simple web interface this is the best solution I could think of. I have chosen to use this model because it doesn’t need too many additional OH items and it allows a dynamic number of intervals. Moreover it is scalable and items can be easily added or removed without changing the underlying code.
Versions / Changelog:
ohscheduler@GitHub: https://github.com/nepotu/ohscheduler
Use the above repository in order to get the latest version. All the previous releases are no longer available for download (the GDrive links were disabled)!
v0.1 Beta GDrive link for OHScheduler-Beta_v0.1.zip
- Initial release
v0.2 Beta GDrive link for OHScheduler-Beta_v0.2.zip
- “Controller as” in widget and JavaScript code
- JavaScript code to remove missing items from schedule (e.g. item removed from widget configuration)
- A light theme and proper bootstrap layout (responsive design)
- Widget model refresh if the value changes for any of the used items (e.g. room temperature change)
- Fixed initial state for switch items from OnOff status view
- Other small fixes
v0.3 Beta GDrive link for OHScheduler-Beta_v0.3.zip
- The schedule is now displayed using VisJS.
v0.3.1 Beta GDrive link for OHScheduler-Beta_v0.3.1.zip
- Round the temperature values to 1 decimal place.
- Persistence is no longer required for rules
[LATEST] v1.0 RC GDrive link for OHScheduler-v1.0RC.zip
- Options to hide the status tab and the running mode selector
- Always select the first (Status/Schedule) tab when the widget is loaded
- Reset to default values on Add/Edit tab selection
- Target Temperature not parsed correctly
- Temperature value decimal points now linked to Temperature Step: one decimal no decimals (if step=1)
- Timeline schedule fix for items with empty schedule
- Add an AngularJS directive in order to expose the html template
- Converted factories to constructor functions
- Removed global variables (now they are integrated in the corresponding constructors)
- Subscribe to ‘openhab-update’ event in order to refresh the widget, instead of EventSource
- Code rearrangement, plus variables changed to camelCase for unity (instead of underscores)
- Converted widget file names to lowercase
- Reworked the controller (used Prototype methods for readability)
- Other bug fixes
- New packing
- Rules error management and JSONPATH transform checks update for nonexistent items/days
Few snaps.
Widget Settings:
Thermostat Status:
Thermostat Status small screen:
Thermostat View Schedule:
Thermostat Add/Edit:
OnOff Status:
OnOff Add/Edit: