NIBE Heat Pump Monitoring using Python instead of Perl

One of the most popular topics on this Blog is using the NIBE Uplink API to retrieve operational data reported by the Internet-connected NIBE heat pumps. That API is protected by OAuth2 authentication, which is a robust solution but which is rather more complicated than other APIs which simply expect an API Key or a non-expiring Token for authentication purposes.

There’s a Technical Articles page dating from 2016 which explains how to use the Perl scripting language on Linux to call the NIBE Uplink API, navigating the multiple steps of the OAuth2 handshake – see NIBE Heat Pump Monitoring via NIBE Uplink API (Perl Version). I originally chose Perl because that’s the language I was familiar with – and there was a Perl Module which handled many of the OAuth2 complexities.

Recently I’ve been learning Python for work and that’s proven to be a bit more friendly for this sort of thing. It’s also a language that more people are familiar with – and it’s rather more commonly used on different platforms, notably Microsoft Windows.

I’ve therefore adapted the original Technical Article to use Python rather than Perl and published that as NIBE Heat Pump Monitoring via NIBE Uplink API (Python Version). The Perl version is still relevant so will remain available too (especially since it has some valuable comments and responses) but my advice is for new users to follow the Python version instead.

I’ve also included some more general updates (such as the new NIBE S-Series heat pumps using an alternative API connected to myUplink.com) and some new screenshots. The script code is also now in a GitHub Repository rather than being embedded in the Blog page – and I intend to add some more comprehensive script examples once I migrate my other scripts from Perl to Python.

CC BY-SA 4.0 NIBE Heat Pump Monitoring using Python instead of Perl by Marsh Flatts Farm Self Build Diary is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

10 thoughts on “NIBE Heat Pump Monitoring using Python instead of Perl

  1. Hello,
    I also have a NIBE heat pump, many months ago I tried the old article of you to get the API working. But this was on linux, and to difficult for me.
    so now I saw you made a new one for windows and tried this:
    And i’m following your instructions for API:
    https://www.marshflattsfarm.org.uk/wordpress/?page_id=4988
    But I have troubles with this:
    “2. The second requirement is the Requests-OAuthlib library
    On Windows, use a Command Prompt to run: pip3 install requests-oauthlib”
    If i open CMD en type “pip3 ……” I get a fault message:
    ‘pip3’ is not recognized as an internal or external command, operable program or batch file.
    I also tried this sollution that i found on google, but still fault message:
    https://blog.finxter.com/how-to-install-requests-oauthlib-in-python/

    Is it possible to give me more info?
    thank you very much.

    Gr Sven from Belgium.

    • Hi Sven,

      That error message (‘pip3’ is not recognized…) means that no Python installation is being found in the Command Prompt window – or the Python version is too old to have the ‘pip3’ command included.

      The first step is to ensure you have Python 3.4 or newer installed. Get it from https://www.python.org/downloads/windows/ – most people will want the “Windows installer (64-bit)” option.

      With the Python environment installed, when you open a Command Prompt and run “python3 –version” you should get confirmation of the Python version. Running “pip3 –version” should also return version details.

      If Python is installed but those commands are not working, there is probably an issue with the PATH setting that is preventing Windows from locating the Python programs.

      Until those ‘–version’ commands are working, the problem is with the installation of the Python environment, not the addition of requests-oauthlib.

      There is more detail about pip3 here: https://www.activestate.com/resources/quick-reads/how-to-install-and-use-pip3/

      David

  2. David,

    Eureka!!!
    Together with your explaination. I got my system ID and System name as respond on the “py simple_call_to_protected_api.py” in CMD.
    This site was very helpfull for me, like you suggested:https://www.activestate.com/resources/quick-reads/how-to-install-and-use-pip3/

    The next step for me is to get the info from Nibe.uplink to my domotica server.
    I have KNX installation, controlled by Jigsaw (https://www.comfortclick.com/Products/Servers/Jigsaw)
    I found here the information:
    https://www.comfortclick.com/BOS/KnowledgeBase/Http
    But I don’t understand quit good what to do. 🙁

    David, perhaps you have a idea? or do you know someone who connected his Nibe heatpump to a server from comfortlick.
    I don’t find anything in google 🙁

    Thank you!!!!

    • Hi Sven,

      That’s excellent news. It’s great that your persistence paid off.

      I’m not familiar with the ComfortClick systems but from a quick look at the links you posted their bOS seems similar to openHAB or HomeAssistant.

      I don’t think the bOS HTTP driver will be able to call NIBE Uplink since there doesn’t seem to be an option to do OAuth authentication (only ‘Basic’ Authentication).

      Most home automation systems provide some way to call a script on a regular cycle (e.g. every 5 minutes) and interpret the output. Is there some way to do that with the ComfortClick bOS? I see there is a Basic / Command option but I’m not sure what that does.

      If you can get bOS to call a Python script which prints out a number (that might be a Temperature from the heat pump) then you “simply” have to adapt the simple_call_to_protected_api.py script to grab the real readings and print those, perhaps using JSON format.

      If there’s no option to call a script from bOS then you might be able to use the RCP driver to talk to a Python HTTP server which then talks to NIBE Uplink – but that would be more complicated.

      David

      • David,
        For me your last 3 alineas are not clear 🙁
        But perhaps I’m running to fast.

        Maybe I first should get the API working on my windows desktop and next step is bOS.
        So I’m at the point to get a system ID and name in CMD!
        After that i’m lost.
        – I searched some info on youtube about JSON/API….
        – I checked the “functions” tab on nibe.uplink.api….
        – and your examples below the title:
        “JSON Response Formats”
        But i can’t make a connection?
        If I open this link in a browser: https://api.nibeuplink.com/api/v1/systems –> i get: {“message”:””}
        If I a open this link in a browser:
        https://api.nibeuplink.com/api/v1/systems/$system/serviceinfo/categories (and fill in my ID on the place of $system)
        –> i get {“message”:””}
        If i press both times on F12 then is see “failed to load resource: the server responded with a status of 400 (Bad request)

        Can you light me up? 🙂
        thanks again.
        PS: amasing that you cleared it op by yourself.
        I don’t get any help from Nibe for the API, even not in sweden. Quit strange for me.

  3. David,

    After some evenings this week on Youtube I succeeded to get some extra info about my heat pump!
    Perhaps this is helpfull for someone else, beceause i knew nothing of JSON or API ;-( :
    This youtube video was very usefull:
    https://www.youtube.com/watch?v=qbLc5a9jdXo
    I downloaded “Postman”
    after the GET command i filled in: https://api.nibeuplink.com/api/v1/systems/……
    below that there is a tab called: “authorization”:
    – type: OAuth 2.0
    there i placed for:
    – Name: Nibe
    – Grant Type: Authorization Code
    – Callback URL: https://www.marshflattsfarm.org.uk/nibeuplink/oauth2callback/index.php
    – Auth URL: https://api.nibeuplink.com/oauth/authorize
    – Access Token URL: https://api.nibeuplink.com/oauth/token
    – Client ID: “my private client ID”
    – Client Secret: “my private client secret”
    – Scope: READSYSTEM
    – State: STATESTRING
    – Client Authentication: send client credentials in body
    after pressing GET NEW ACCES TOKEN i need to fill in my email adres and password in a web browser. after clicking on some buses and fire hydrants i get a message from postman: Authentication complete
    –> press “use token”
    –> press “send”
    And at the bottem i get respond!!!
    now i need to investigate some more the “functions” and automatic refresh of the token.
    Gr Sven.

  4. Hello,
    David, to complete my API story:
    I got contact with the third party API specialist of Comfortclick in Slovenia.
    He was able to extract 1 Array, and 1 signal.
    then i did the rest of the signals with copy paste. 🙂
    Also thanks for your “expanded version” you placed on GitHub, this was helpful!

    If somebody needs the info to connect the api to Comfortclick.
    Follow the excellent steps of David on this blog.
    Then do this in comfortclick:
    add a HTTP driver in bOS:
    With this url: https://api.nibeuplink.com/
    make a POST command to “oauth/token”
    With the following:
    – Content Type: “application/x-www-form-urlencoded;charset=UTF-8″
    – Post Data: grant_type=refresh_token&client_id=”YOUR PERSONAL CLIENT ID”&client_secret=”YOUR PEROSNAL CLIENT SECRET”&refresh_token=”YOUR PERSONAL CLIENT”
    And send it cyclical for example 1700 sec.
    The tricky part of this is, that my secret was coded,
    so perhaps you need to encode it:
    https://www.urlencoder.org/
    As response you get your “acces token”

    Then insert a new HTTP driver with this URL:
    https://api.nibeuplink.com/api/v1/systems/
    and a new command:
    With for example this request:
    “YOUR SYSTEM ID”/serviceinfo/categories/STATUS
    Header: Authorization: Bearer “YOUR PERSONAL ACCES TOKEN”
    Method type: GET
    as response data you get the array in JSON of that request.
    if you copy/past the response data to https://jsoneditoronline.org/
    then you can see where the data is and parse it out.

    with this done, i made a visualisation page were a placed all imported values for me, and also made some loggings.
    With this I hope to optimize the heatpump even more.

    Gr. Sven.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.