Connecting Velux Active KIX 300

I have extracted the client_id and client_secret from the VELUX active 1.5.0.7 APK using JADX. Those two information are returned by some methods, located all in the same class file.

# client_id: 5931426da127d981e76bdd3f
# client_secret: 6ae2d89d15e767ae5c56b456b452d319
# mgtkey: f3748d873c62f30ef6f7b61b7e725ac6

How to get your oauth2 token?

$ curl --location --request POST 'https://app.velux-active.com/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'client_id=5931426da127d981e76bdd3f' \
--data-urlencode 'client_secret=6ae2d89d15e767ae5c56b456b452d319' \
--data-urlencode 'username=my@email.com' \
--data-urlencode 'password=mypassw' \
--data-urlencode 'app_version=1108002' \
--data-urlencode 'user_prefix=velux'

Hi Hubert,

Thanks for extracting and sharing that. Now working for me. :slight_smile: To get token:

curl -d “grant_type=password&client_id=5931426da127d981e76bdd3f&client_secret=6ae2d89d15e767ae5c56b456b452d319&username=my@email.com&password=mypassw&user_prefix=velux” https://app.velux-active.com/oauth2/token

As documented here:

Did anyone succeed in setting state for Departure Switch (NXD)?

Tried:

curl -s -H “Content-Type: application/json; charset=utf-8” -H “Authorization: Bearer mytoken” -X POST -d “${JSON}” “https://app.velux-active.com/syncapi/v1/setstate

with $JSON set to:

{
“home”: {
“id”: “myhomeid”,
“modules”: [
{
“id”: “xx:xx:xx:xx:xx:xx”,
“locked”: true
}
]
}
}

But get this response:

{“error”:{“code”:21,“message”:“cannot set property locked for module xx:xx:xx:xx:xx:xx”}}

Best regards,
Jacob Laursen

@nougad - I may have somehow missed it, but how do you create a request for locking or unlocking your home?

/Jacob

Hi. Thank you very much for all info present in this thread.

I was able to install and run as openhabian the Homekit python version suggested by Bernhard and to define Things/Items as suggested by Rafael.

When I run the command as openhab I get below error:

/usr/bin/python3: Error while finding module specification for ‘homekit.get_characteristic’ (ModuleNotFoundError: No module named ‘homekit’)

The same command executed by openhabian work smoothly.

Python modules owner and group looks fine.

I have tried to move Homekit python site-packages in PATH to /usr/lib/bin but without success.

I have googled the error but without success (I’m not a python programmer nor a linux/raspberry expert).

Could you please give me some suggestions?

Release = Raspbian GNU/Linux 10 (buster)
Kernel = Linux 5.10.11-v7+
Platform = Raspberry Pi 3 Model B Plus Rev 1.3

Thank you in advance for your help.
Pierpaolo

Hi again. I’m going to answer myself :slight_smile:

To install homekit for openhab user the command is: sudo -u openhab pip3 install --user homekit[IP]

Probably also this command should work but I have not tested it: pip3 install --system homekit[IP]

To be honest I’m not able to understand if this can create problems on the raspberry installation or if it is ok.

Bye.

Pierpaolo

I have created a small instruction to patch the APK file and get all required info to interact with windows and unlock your home.
The app is only required once to get the all the keys.

Btw:
I was able to generate and exchange all other keys via web API except for the HashSignKey which seems to be generated when the app connects directly to the gateway. I could log that exchange with wireshark (~9 requests and responses between app + local gateway) but data seems to be encoded/encrypted.

But having all the keys allows to create own APIs (eg Node-RED).

Maybe this is useful to some people, like everything here was for me.

1 Like

Hi there, I have an OpenHAB setup with a KLF200 to control my windows and rollershutters. It works fine apart from the KLF 200 being a pain to work with (login via its own WI-FI only!). However, whenever I need to restart the OpenHAB service the KLF200 refuses any incoming connection and I have to keep unplugging it completely several times for long periods of time until it hopefully starts working agains. This seems totally random and sometimes takes days.
As this is not acceptable I was hoping the KLX300 could be a solution. Will there be a binding for OpenHAB eventually? I am also happy to tinker with copy-pasting code to make it work. Thanks!

Newer KLF200 devices work reliable only over LAN access. The internal WiFi access point should be disabled automatically 10 minutes after power connection. This has been added to the latest Pull Request documentation.
My setup is running fine for 2 month now.

I have 7 velux integra windows that i need connected to my openhab, but i dunno what solution to use klf200 or kix300.

and i rather not have netamo/velux active controls/sensors honing around the house.
My solution only to have one control in each room for windows/heating/etc…

I’m using a KIX300 (only gateway, no sensors) to manage three windows in different rooms, including curtains and shutters. It has been integrated in OH3 using the approach described in this thread. For my needs, it works well and in fact, I have completely forgotten the velux app :-).
In case, try to further elaborate on your requirements and use cases in order to get more detailed suggestions.

Hi Manuel, which approach did you succeed with - the homekit_python one?

Yes, correct, the homeKit version (actually there were at least two solutions in the thread, sorry… :slight_smile: ). Specifically this post and the related ones (such as this one).

Hi, is there any update on the KIX 300 syntax, as stated by Jacob? I am able to get the access tokens and the homesdata, but it looks like that the setstate syntax for the json data parameter has been changed. I played around with some options but with no luck. Can any control the shutters using the “syncapi/v1/setstate” url?
Greetings
Carsten

1 Like

Hey there,

did anyone tested this with the KIG 300 EU, which is actually offered in velux online store?

KIX300 = 200 EUR (third party retail)
KIG300EU = 128 EUR (official velux store)

Greetings
kapi

KIG 300 is the gateway that comes with the KIX 300 starter kit. The kit also includes KLA 300 and KLN 300.

1 Like

I have recently bought the KIG 300 , which is currently available for 98 EUR at Hornbach. I only have two solar powered shutters which are now easily controlled via Apple HomeKit. The problem is that my family does not use Apple except me. Our standard home automation system (heating and lights) is Fritz which I coupled to HomeKit via a Raspberry run Openhabian.

I decided to wait until someone comes up with an easy interface for KIG 300 in openhabian. The effort to program something is not worth it in my opinion.

Hi,

i am completely new in openhab and i have no idea what to do to integrate my Velux windows (KIX300). Is there allready a very very simple solution for this integration?

Greetings

Hi,

thanks for all your contributions! I can now control my windows with the methode desicbed by @brusch , thanks also to @pierlomb65.

However, I’m struggling to get the exec thing to work. I implemented everything as desribed, and my python command to open the windows works perfectly if executed in the terminal directly:

python -m homekit.put_characteristic -f velux -a velux -c 3.11 0 -c 5.11 0

But executing the exec binding brings the following error/warning:

2023-05-07 12:57:46.602 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Windows_Open' predicted to become ON
2023-05-07 12:57:46.606 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Windows_Open' changed from OFF to ON
==> /var/log/openhab/openhab.log <==
2023-05-07 12:57:46.607 [DEBUG] [ng.exec.internal.handler.ExecHandler] - Passing to shell for parsing command.
2023-05-07 12:57:46.608 [DEBUG] [ng.exec.internal.handler.ExecHandler] - OS: *NIX (Linux)
2023-05-07 12:57:46.616 [INFO ] [org.openhab.core.model.script.test  ] - executed
2023-05-07 12:57:47.077 [DEBUG] [ng.exec.internal.handler.ExecHandler] - Exec [OUTPUT]: 'Could not open "velux" because it does not exist'
2023-05-07 12:57:47.174 [DEBUG] [ng.exec.internal.handler.ExecHandler] - Transformed response is 'Could not open "velux" because it does not exist'

The thing is defined as follow:

Thing exec:command:Velux_Windows_Open "Velux_Windows_Open" [command="python -m homekit.put_characteristic -f velux -a velux -c 3.11 100 -c 5.11 100", interval=0, timeout=5, autorun=false]

I assume there is an issue with the role of pyhton. I already tried to execute it as sudo -u openhab python… but with no success.

@rlkoshak maybe you have an idea here?

Many thanks!

@nougad Greetings from the Loxone world. Just came here to thank you for all your efforts. I am on a quest to connect my Velux Integra shades to a Loxone installation without additional hardware, merely using REST API integration. Thanks to the 4 year old work of yours I can now control my shades via KIG300 and Postman. Next - embed the API calls into Loxone :slight_smile:
All the best!

Hi,
How did you manage to get the sign_key_id for opening windows.
I can only close them.
Thanks in advance.