ioBroker integrates different smart home protocols into a single easy interface

Automation with JavaScript

You can read and write ioBroker objects manually, but you can also automate the process. ioBroker has three strategies for automation: Scenes (please do not confuse these with KNX scenes), Flows in Node-RED [5], and JavaScript. I'll focus on the most powerful of the three alternatives: writing your own small JavaScript programs.

The Scripts tab takes you to the built-in JavaScript development environment in ioBroker. Pressing the New Script icon creates an empty text file named Script1 in the common directory. You can rename this file as desired. Before saving the empty file, check the Help output box. In the built-in editor, you can start automating. To familiarize yourself with the JavaScript's ioBroker-specific extension, take a look at the documentation on GitHub [6].

The implementation of the previous automation example (TV button on remote control triggers the KNX Television scene, which in turn switches an additional Hue light) is shown in Listing 1. Line 1 contains the most important component: The on() statement defines a callback function that is used whenever the state of the harmony.0.Harmony-Hub.activities.currentActivity object changes. The object's complete path specification results from the hierarchical arrangement in the object tree. The specified string can be obtained in the Object view using the clipboard symbol above an object name.

Listing 1

KNX Television Scene

 

The function then determines the value of the currentActivity object and displays it on the console together with its previous value for demonstration purposes. The switch() statement in Line 12 considers different values of the activity, and Line 16 finally triggers the KNX Television scene by writing to the corresponding ioBroker object using the setState() function. The value 0 represents the KNX scene with the number 1 (the value is the scene number minus one). For the adapter to actually set the value, you first need to set a third parameter to false. This sounds a bit illogical at first, but you'll find a detailed explanation on the ioBroker Wiki [7].

In the group monitor of the ETS software, you can see how the TV scene was triggered on the KNX side. The scene object with the KNX group address 15/4/8 receives the value 0, which means that the program retrieves scene 1.

The second on() statement in Line 21 also switches on the Hue pendant_lamp_front when someone activates the KNX Television scene. Of course, you could have packed the setState() function call from Line 28 directly under the first setState() call from the Harmony callback function. However, a separate callback function (as in Listing 1) has the advantage that the Hue lamp is switched on even if the KNX scene was not triggered via ioBroker.

Conclusions

With even a little knowledge of JavaScript, almost any smart home subsystem can be integrated into a larger whole via the ioBroker platform. This integration is possible because the ioBroker system provides a large number of available adapters and an ingenious object database. ioBroker is a top-ranking solution for cost-effective smart home networking within your own four walls.

The Author

Stefan Heinle is an electrical engineer and an enthusiastic practitioner of home automation. He is a certified KNX partner and author of the book Home Automation with KNX, DALI, 1-Wire and Co., published by Rheinwerk. He offers supplementary information for the book, as well as professional smart home planning services, on the website http://www.heimautomation-buch.de.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Charly's Column – Mosquitto Message Broker

    Sys admin Charly does not tend toward hostilities, but he has huge problems with mosquitoes. Despite this, he does make an exception for the Mosquitto message broker.

  • FHEM

    If you want to equip your home with smart technology, you will need to deal with a variety of providers and what are often incompatible standards. FHEM is a free integration platform that houses the building blocks under one roof and offers visually appealing interfaces.

  • WiFi Thermo-Hygrometer

    A WiFi sensor monitors indoor humidity and temperature and a Node-RED dashboard reports the results, helping you to maintain a pleasant environment.

  • AJAX Workshop

    Books were the original model for website design. Navigation was similar to flipping the pages. Thanks to AJAX, many state-of-the-art websites now behave like desktop applications.

  • Twisted

    The Twisted framework makes it so easy to create network-aware applications in Python. Twisted speaks all the major Internet protocols, from mail through chat, and it can handle encryption. We’ll show you how to set up a personal web server with Twisted.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News