I am trying to integrate my new Nuki smart lock with openHAB and they have just released a beta version of their firmware that allows you to specify a callback URL which is called whenever the lock changes state.
The payload of the callback is JSON and the request is made with a header containing Content-Type=application/json. I have a virtual item setup in openHAB for receiving this payload and testing with Postman shows my item and rules (for decoding the JSON payload) is working great…
…as long as the request is made with Content-Type=text/plain.
The requests coming from the lock itself are failing, due to the Content-Type. Just wondering if there is a trick for getting the openHAB REST API to handle these types of requests?
Or am I going to need to code up a little proxy server to receive the lock callback requests and transpose to the appropriate format acceptable by the openHAB REST API?
I use a script to call my wireless sensor tag data and have to specify the content type as json. I haven’t had any trouble with this in OH2. Maybe something in what i’ve done will help.
Ah ok - so you are not actually using the REST API. I can’t poll the lock (as it kills the battery) so have to rely on these callback urls which is fine, just the REST API seems to bork when the Content-Type is not text/plain.
No - the issue is the Nuki lock is generating the request/payload (and I have no control over that). So I have configured the locks callback URL to be http://openhab:8080/rest/items/NukiCallback and it is then sending a POST request to that URL with application/json in the header.
I ended up knocking together a quick and dirty proxy using python/bottle which the lock publishes the JSON updates to, and it decodes and forwards the update to openHAB via the REST API (in the format it can accept).