Domoticz and Velux KLF-200
Last article in this series: let's integrate our Velux KLF-200 with Domoticz!
If you've followed my last article explaining how to add your roller shutters in a Velux KLF-200 io-homecontrol gateway, you've seen that it comes with an API, meaning we can control it from an home automation system - Domoticz in my case.
Initial thoughts
I first wanted to implement basic API calls to open/close my roller shutters, but when I looked at the Velux API, I realised that I'd better find existing implementations (e.g. on GitHub), since Velux provides you with the ability to interact with the KLF-200, but you have to implement a lot of things by yourself - basically, it's pretty low level, see below:
Finding alternatives
A quick search on GitHub on the keyword "KLF-200" gave me a few results:
Both seemed interesting, so I started playing a bit with them, but in parallel I looked at the Domoticz forums to see whether some folks had the same requirements as me, and indeed that was the case!
So what do we use?
The post in question is from French user "ProfBoc75" and available on the French Domoticz forum, but he also made a post in English on the Domoticz Forum.
What do we want to achieve?
We want to be able to fully control our roller shutters, i.e.:
- use Domoticz to close and open them,
- but also get their status displayed if we use the physical remote controller to open/close them.
Approach and Components
The idea is to use a component in between Domoticz and the Velux KLF-200 to get status from one side and send it to the other side, e.g.:
- we close one roller shutter with its remote controller:
- this is read from the KLF-200 API,
- then the roller shutter's status is updated in Domoticz,
- or we use Domoticz to open a roller shutter:
- this is read from Domoticz,
- then the command is sent to the KLF-200 API, which closes it.
We will need three components:
- a MQTT Broker: this is a lightweight messaging protocol with a subscribe/publish model, ideal for IoT and to make devices communicate with each other (in our case Domoticz and the KLF-200).
- Node-RED: a browser-based editor to wire together hardware devices and APIs.
- node-red-contrib-velux: specific Node-RED module for Velux KLF-200
Setting that up!
ProfBoc75's post is super well detailed, so I'm just listing the main steps below:
Prerequisites
- Install and setup a MQTT broker
- Install Node-RED
- Install node-red-contrib-velux using the CLI
- You must install version 0.0.4 with the below command, as using the node-red CLI installs version 0.0.3, which doesn't work
sudo node-red-stop
cd ~/.node-red/
npm install node-red-contrib-velux@0.0.4
sudo node-red-start
- Of course the KLF-200 must be setup
- Please refer to my previous article for more details
Domoticz part
- Create a "dummy hardware" in Setup > Hardware
- Then create as many "virtual sensors" as roller shutters you have in your
KLF-200
- Sensor type is "Switch"
- Then edit it the newly creates devices in "Switches" and set the Switch Type
to "Blinds Percentage":
Node-RED: KLF-200 to Domoticz
We are creating a Node-RED flow to read status from the KLF-200, and update the switches (roller shutters) in Domoticz.
- In Node-RED UI (http://YOUR IP:1880), import
this code
- using the "burger menu" from top right, then Import:
- Paste the code in the pink part, and:
- Put your KLF-200 IP address in the line "host": "192.168.xx.xx",
- and the KLF-200 WiFi password (which you can find on the KLF-200 itself) in the line "password": "YourWifiPassword",
- You can check the MQTT configuration in the purple "domoticz/in" icon, then
click on the pencil button on the "Server : MQTTBroker" line:
- And the KLF-200 settings can be checked in the "Velux Nodes" blue icon, then pencil next to "Datasource"
- Then click on the red "Deploy" icon at the top right
- The "domoticz/in" purple icon should show a green "connected" dot
- using the "burger menu" from top right, then Import:
- Edit the "UpdatePosition" and update the index numbers (IDX) with the ones from Domoticz (which you get from the Switches properties).
- Deploy the flow again (with the red "Deploy" button top right of the screen).
- You can now check that it works by closing a roller shutter with your remote,
and this should be updated in Domoticz:
=>
All done, now Domoticz knows the status of our roller shutters and displays them.
Let's do the other way around, i.e. having Domoticz control those shutters!
Node-RED: Domoticz to KLF-200
- Still from the Node-RED UI, import
this code
into the current flow.- Select "import copy" when a pop-up appears, since few nodes already exist
- Check the "MQTTBroker" and "VeluxAPI" - same as in previous step
- Edit the "VeluxMsg" green-ish icon:
- /!\ The name must match the name that you defined in your KLF-200
configuration /!\
- If you have more devices to add, just use the Node-RED UI:
- Add an item in "VeluxMsg" pointing to the next number (e.g. 5 if the last one was 4)
- Add a "Change" and fill in the correct Velux nodeID, and connect it to "VeluxMsg" on one side, and to "BougePosition" on the other side
- /!\ The name must match the name that you defined in your KLF-200
configuration /!\
- Deploy the flow
- You should now be able to control your shutters from Domoticz
Troubleshooting
- The Node-RED logs are super useful, and can be seen in the UI by clicking on
the "bug" icon:
- Be sure to use the Name of your Velux node when updating the "VeluxMsg" part.
- The Domoticz index number needs of course to be correct for the reading shutters state from Domoticz part.
Wrap-up
Many thanks to ProfBoc75 for his work, this post is just a more detailed walk-through.
I hope you found it useful, and as usual, hit me up on Twitter for any question/feedback!
Tags: Automation