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.
Infos
- Project website: http://www.iobroker.net
- ioBroker SD images: http://www.iobroker.net/docu/?page_id=2563&lang=de
- KNX ETS software: https://www.knx.org/knx-de/software/uebersicht/index.php
- Philips Hue developers website: https://developers.meethue.com/documentation/core-concepts
- Node-RED homepage: http://www.nodered.org
- ioBroker JavaScript: https://github.com/IO-Broker/IO-Broker.javascript/blob/master/doc/en/javascript.md
- ioBroker status: https://github.com/IO-Broker/IO-Broker/wiki/Adapter-Development-Documentation#commands-and-statuses
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.