This module provides a wrapper to the official API of a KLF-200 interface. You can find the links to the firmware and the documentation at https://www.velux.com/api/klf200.
ATTENTION: This version supports the officially documented API that was introduced with firmware version 2.0.0.71. It is not compatible with older firmware versions. It is recommended that you update your KLF-200 with the new firmware version.
npm install klf-200-api --save
The KLF-200 uses a self-signed certificate to secure the TLS protocol. This package contains the fingerprint and certificate that I have extracted from my KLF-200.
In case that your connection doesn't work due to a different certificate you have to extract the certificate from your box with the following command:
$ echo -n | openssl s_client -connect <ip adress of your KLF-200>:51200 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > velux-cert.pem
After extracting the certificate you have to generate the fingerprint with the following command:
$ openssl x509 -noout -fingerprint -sha1 -inform pem -in velux-cert.pem
This will print a fingerprint like 12:34:56:78:9a:bc:de:f0:12:34:56:78:9a:bc:de:f0:12:34:56:78
.
See below for a sample usage with user defined certificate data.
The KLF-200 interface provides a list of connected products and a list of scenarios. The interface is intended to be used with wired switches but there is an official interface that works on sockets to control the connected products.
To work with this module you have to complete the following tasks:
Note 1: You no longer need to setup a scene for each desired position. With the new firmware it is possible to control the products directly.
Note 2: If you don't want to use wired switches
you don't have to use the provided wires.
To use this module with the interface to run a product you have to do the following steps:
Connection
object and login with loginAsync
.Products
object with createProductsAsync
.
This will load the registered products from the KLF-200.Product.setTargetPositionAsync
to set your product to the desired value.logoutAsync
.The following sample code shows how to open the window named 'Window kitchen' to 50%.
import { Connection, Products, Product } from "klf-200-api";
/*
Use either the IP address or the name of *your* interface
'velux-klf-12ab' is just a placeholder in this example.
*/
const conn = new Connection('velux-klf-12ab');
/*
Login with *your* password.
The default password is the same as the WiFi password
that is written on back side of the KLF200.
For security reason you should change it.
In the following example we assume
that the password is `velux123`.
*/
await conn.loginAsync('velux123');
try {
// Read the product's data:
const myProducts = await Products.createProductsAsync(conn);
// Find the window by it's name:
const myKitchenWindow = myProducts.findByName("Window kitchen");
if (myKitchenWindow) {
await myKitchenWindow.setTargetPositionAsync(0.5);
} else {
throw(new Error("Could not find kitchen window."));
}
} finally {
await conn.logoutAsync();
}
If you have to provide your own certificate data use the following code for login:
import { Connection, Products, Product } from "klf-200-api";
import { readFileSync } from "fs";
const myFingerprint = "12:34:56:78:9a:bc:de:f0:12:34:56:78:9a:bc:de:f0:12:34:56:78";
const myCA = readFileSync("velux-cert.pem");
// Connect using your own certificate data:
const conn = new Connection('velux-klf-12ab', myCA, myFingerprint);
...
For some basic usage scenarios you can use the following classes:
Gateway
: Represents the KLF-200. E.g. you can enable the
house status monitor, change the password or
query the current state.Products
and Product
: Get a list of the products and control
a product, e.g. open a window.Groups
and Group
: Get a list of groups and control them,
e.g. open all windows of a group together.Scenes
and Scene
: Get a list of defined scenes and run a scene.
E.g. you can open different windows at different positions.For other scenarios you may want to send a command directly to the KLF-200.
You can do so by using the method Connection.sendFrameAsync
.
This method handles the command handshake for you already.
The Promise
that is returned will fulfill when the corresponding
confirmation frame is received.
Depending on the request, it can be finished when the confirmation frame is received. With other request, like opening a window, you will receive additional notifications, which will be provided by event handlers to you.
The following list shows the implemented messages that can be used:
For full details see CHANGELOG.md.
MIT License
Copyright (c) 2019-2024 Michael Schroeder
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.