NIBE Uplink API component (non S-series)

Hello world!
I am currently trying to integrate my NIBE heat pump to HA but I have run out of luck. I am not nearly as skilled in the arts of API and Oauth as I would like to be at the moment.

So is there any one else out there that would like a NIBE heat pump component? (or maybe some other kind of integration to HA, via some existing component?)

For the skilled out there, here is some info:
NIBE Uplink API uses the same credentials as the normal NIBE Uplink. Even if you don’t have a NIBE heat pump you can still create a user (at https://www.nibeuplink.com/) and then get access to the API site (at https://api.nibeuplink.com/) where the documentation is available.

The API is a RESTful API running conventions using HTTPS over the api.nibeuplink.com domain and authenticates via the OAuth 2 protocol. All data is sent and received as JSON.

More from NIBE:
Users are authenticated via the OAuth 2 protocol. NIBE Uplink currently supports the Authorization Code Grant flow and the Implicit Grant flow. The Authorization Code Grant flow targets clients which the OAuth 2 specification deems confidential, such as web applications and mobile apps while the Implicit Grant flow is a shorter flow which targets public clients that can’t keep the confidentiality of the OAuth credentials, such as browser based JavaScript applications.

Under no circumstances is the client allowed to process or handle a user’s secret login credentials.

The following URL:s are used for the OAuth 2 requests:
Authorize endpoint NIBE Uplink™
Token endpoint /oauth/token - NIBE Uplink™ API

I tried this guide my self but got lost in the Oauth 2 process…
http://www.marshflattsfarm.org.uk/wordpress/?page_id=3480

Some initial hacks/attempts here:

Got some temperatures at least. Will see when I can continue.

Some generic oauth2 client in hass would simplify it a lot.

6 Likes

Oh, nice work @elupus. I know, the oauth2 process seems “easy” to understand at first but unnecessarily complicated to implicate in reality.

Anyone that knows if there are other components or stuff that uses oauth2 in the same way?

I’d very much like this too as I both use HA and have a Nibe F750 :slight_smile:
I’ve not done any HA development before but managed yesterday too get OAuth2 working when labbing in Postman and managed to retrieve some sensor values from the api:

[
    {
        "parameterId": 40004,
        "name": "outdoor_temperature",
        "title": "utetemperatur",
        "designation": "BT1",
        "unit": "°C",
        "displayValue": "22.3°C",
        "rawValue": 223
    },
    {
        "parameterId": 40033,
        "name": "indoor_temperature",
        "title": "rumstemperatur",
        "designation": "BT50",
        "unit": "°C",
        "displayValue": "20.9°C",
        "rawValue": 209
    },
    {
        "parameterId": 40013,
        "name": "hot_water_temperature",
        "title": "varmvatten topp",
        "designation": "BT7",
        "unit": "°C",
        "displayValue": "50.1°C",
        "rawValue": 501
    },
    {
        "parameterId": 40014,
        "name": "40014",
        "title": "varmvatten laddning",
        "designation": "BT6",
        "unit": "°C",
        "displayValue": "47.4°C",
        "rawValue": 474
    }
]

If needed I’d like to help out in this component project. It can include functionality discussions, testing or just cheering on. :laughing:

1 Like

Edit old news: I am not using the MODBUS interface from husdata any more, only elpus/hass_nibe.

@imist nice to see some more people cheering on :slight_smile: and of course, all help is welcome.
I am using a Nibe F1145 that is currently connected through an interface from @husdata (husdata.se), works great btw.

But I would like to get by on a single raspberry (distance to the heat pump for me requires two raspberrys at the moment to maintain) and perhaps also get some additional information from the heat pump that is currently not available from the H1-interface at the moment (electricity price, some run time hours, compressor frequency etc.).

Cool!

There is a project called Domoticz RPC for Domoticz - maybe that can give you some pointers. I am running a Domoticz server just to get values from my Nibe 1255 into Home Assistant. Domticz published them to MQTT and the I resorted to use Node-RED to parse the data (never figured out how to use templates in home assistant) and republish it to MQTT which in turn is subcribed in Home assistant. Works great as such, but it has a workaround-feeling to it. :smiley:

/Johan

Found this …

may help…

How do i test this?

Iam very new to all this…

Hi
Not entirely sure, but I will look into this later this weekend if I get the time. Seems by just looking at the readme very quickly, it could work by setting itself up as a MQTT-client and might be run as a script in the background perhaps?

1 Like

As mentioned before a rudimentary hass plugin is available here: https://github.com/elupus/hass_nibe/ , you need to register on nibe uplink for an api key and register a redirect url. can be pretty much anything.

Install the plugin in your custom_components directory.

It should then try to guide you throw the oath2 process. It’s messy right now but work for the most part :).

Nice!
I didn’t get time to try anything this weekend (the weather was too good :slight_smile: ). This looks really promising!
Hopefully I can test this today or later this week when the rain stops me from working on the house outside :wink: .

I tried this and it seems requests_oauthlib is missing. Any tips on how to install this and where to put it?

2017-08-14 20:06:38 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.nibe. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/loader.py", line 142, in get_component
    module = importlib.import_module(path)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/mist/.homeassistant/custom_components/nibe.py", line 30, in <module>
    from requests_oauthlib import OAuth2Session
ImportError: No module named 'requests_oauthlib'

Found it! :slight_smile:

pip3 install requests requests_oauthlib

Now I’ve got tons of Nibe sensor values in HA! :slight_smile: Great work elupus! :+1:

1 Like

I feel a bit stupid right now… I get to the Nibe authorize-site, get past the captcha and get my complete, and very long url.
I then paste this to the “Nibe Uplink Code”-configurator but then what? No “accept”-button or anything?

What should happen next?

Ok, found the issue… the “Set configuration”-button didn’t appear in any of my tries with my browser (Chrome) on either my laptop or my phone but when I opened the iOS app for HA it was suddenly there and behold, all those sensors I wanted!

I wonder what the problem could have been there…

Also some of the readings are of by a factor 10 for me, specifically the operating hours for compressor operating time, hot water production and also the fuse size. How does he code handle the readings? The “raw value” reads correctly.

And could I perhaps customize the output for price of electricity to a numerical reading instead of a state, I would like to see if the smart price adaptation actually works =)

1 Like

i have the same problem! but I dont have a IOS device.
Have tested all browsers i can find. =) Chrome, Edge, old explorer , but nothing.

I also get “Invalid captcha.” from NIBE when trying to Authorize.

Not sure why configurator doesnt show up in normal browsers. It did work last I tried it. But that was a few hass versions ago. Maybe something in hass broke or changed.

Regarding captcha: That has nothing to do with the plug-in.

Regarding scaling: yes there are issues with that… the problem is that the scaling of the raw value can’t be deducted in any way. I tried to do it based on unit, but that seems not reliable. The other option would be to parse the display value and strip the unit from that.

Okej… Will try to find ä iOS device…

And to be sure, is the callback url:
IP-adress:8123

Now i testet the IOS app and safari Still No Burton

Can i enter this manual ?

The callback url can be pretty much any url. But it must be a full url including http prefix.

http://localhost:8123/ should work for example.

1 Like