Hive Heating UK

Yeah, that would be fantastic, having two people working on it would be great. :cat2:

Just to let you know though, my re-write uses the “new” API Hive uses for their web dashboard. It’s much better in my opinion, but you can only get info on all devices at once, not individually like you could previously.
Anyway, having all this combined into one Hive platform would be great, just enter your username and password and we’ll discover all the devices on the account and add them to Home Assistant.
The only device/product I can think of that would be difficult to integrate though would be the the hot water/boiler, since Home Assistant doesn’t have a dedicated boiler platform yet, we could probably figure out a work around though (maybe an input_select?)

I hope we can get this implemented well. :smiley_cat:

1 Like

Just thought I’d upload the latest re-write anyway, should be better than before. Controlling plus getting the status of your heating are both there.

climate:
  username: [email]
  password: [password]

https://puu.sh/vqsac.py

Do you have any documentation for the new API? I have never seen that before, mine all runs from the 6.5 API

My new re-write works exactly as you described, just enter username and password on to a Hive platform and it does the rest adding all the devices it detects (so far only heating and hot water, plus sensors to separately get the different values out). To add more device types it should fairly straight forward, by adding a new custom component file in the relevant folder which talks to the same platform file

At the moment if you add the following config:

   hive:
    username: YourHiveUserName
    password: YourHivePassword

it does the following:


with the hotwater added as a climate device at the moment, but I cant imagine it would take long to convert to another type.

I am struggling with a couple of annoying issues, maybe tomorrow I will post what I have if anyone is interested.
One is an error where I am not understanding how things are initialised when HASS loads the platform, but that one is not so important,
The other one is the feedback to HASS and the GUI after setting a new heating, hotwater mode or temp change, the change is not reflected in HASS / GUI, but the change is made in the Hive system and you have to wait for the next API call to get the correct data.

To be honest I am close to giving up with this, it does what I want it to do, which is mainly reporting back the various current states, but it could be expanded much further.

GreenTurtwig, if you do have some reference material for the new API then I could try and update to work with this, and maybe this will solve my issue.

rendili - I’ve followed your other thread (and now this one) and thanks to you have the heating setup and grouped in my dashboard. Unfortunately I can’t for the life of me figure out the alternative that GreenTurtwig has done in terms of setting up the groups (which may well be my lack of understanding) but yours was very straightforward.
As such, please don’t give up!

1 Like

Thank Syx for those encouraging words. I took another look fresh this morning, and I think I have something.

Here is the new version of what I have, it will replace my previous components, the configuration file for adding the components is different to before, but any group configuration is the same as before, and it will maintain history.

As this version is one integrated platform and not two individual customcomponents, it is quicker when starting up HASS, it is kinder on the overall CPU usage and there are less API calls as it makes only 1 API call for all.

To setup:

  • Copy the hive.yaml (44.5 KB) file to “/custom_components/hive.py” taking care to change the file name from hive.yaml to hive.py
  • Copy the hive_climate.yaml (4.8 KB) file to “/custom_components/climate/hive.py” taking care to change the file name from hive_climate.yaml to hive.py
  • Copy the hive_sensor.yaml (10.1 KB) file to “/custom_components/sensor/hive.py” taking care to change the file name from hive_sensor.yaml to hive.py
  • Remove from configuration.yaml any sensor or climate setup for my previous version
  • Add the following to configuration.yaml to setup the new version
hive:
  username: YourHiveUserName
  password: YourHivePassword
  minutes_between_updates: 2
  devices:
    - hive_heating
    - hive_hotwater
    - hive_thermostat_batterylevel
    - hive_heating_currenttemperature
    - hive_heating_targettemperature
    - hive_heating_state
    - hive_heating_mode
    - hive_heating_boost
    - hive_hotwater_mode
    - hive_hotwater_state
    - hive_hotwater_boost

As before, minutes_between_updates: is optional and actually does not work at the moment, it will always set 2 minutes between updates.
Also the devices: section is optional, if you do not add this it will add all devices it detects. if you add this to the config, then specify which devices you would like added

I have added all devices and then added to them all to a group as below :

HiveHeating:
name: Hive Heating
entities:

  • sensor.hive_heating_mode
  • sensor.hive_heating_boost
  • sensor.hive_heating_state
  • sensor.hive_hot_water_mode
  • sensor.hive_hot_water_boost
  • sensor.hive_hot_water_state
  • sensor.hive_target_temperature
  • sensor.hive_current_temperature
  • sensor.hive_thermostat_battery_level
  • climate.hive_heating
  • climate.hive_hotwater

Once setup it should look like this:

At the moment the hotwater is set as a climate device, but as GreenTurtwig suggested it would probably be better as an input_select. I don’t know what component type that is, but I can work with GreenTurtwig to get that changed (If you are ok with that GreenTurtwig?)

Plus this is running from the same API as before, and not the new one that GreenTurtwig’s customcomponent is running from.

If anyone has other Hive devices such as lights, plugs, motion sensors, then hopefully working with GreenTurtwig we can update this platform to get them added

I hope this version works for those that are interested, please let me know either way if it works or not, it would be really great to know.

1 Like

Hi @rendili. I have tried your new scripts. They don’t seem to create any sensors for me. Looking through the logs I can see the following error:

17-04-21 12:17:18 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform hive
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 153, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/hive.py", line 409, in setup_platform
    HiveSession_Current.UserName = config[CONF_USERNAME]
KeyError: 'username'

My username and password are definitely correct. Any ideas?

Hi gr4z,

It looks like it could be setting up the Hive platform as a sensor in your configuration, plus maybe the old version file used instead of the three new files from the new version?

The Hive: entry is at the top level and is its own custom component type, not a custom sensor component
So instead of having:

sensor:
 - platform: hiveheating
   username: YourHiveUserName
   password: YourHivePassword
   
climate:
  - platform: hiveheating
    username: YourHiveUserName
    password: YourHivePassword

You need to have instead:

hive:
  username: YourHiveUserName
  password: YourHivePassword

plus please could you double check that the 3 new files from this thread posted above have been copied to the correct folders and sub folders?
The hive.py file in the “/custom_components” folder should be the big main one at 44.5KB
The hive.py file in the “/custom_components/climate” folder should be the climate device file at 4.8KB
The hive.py file in the “/custom_components/sensor” folder should be the sensor device file at 10.1KB

I hope this helps, let me know :slight_smile:
If it is still erroring then please could you post the relevant section of your configuration.yaml file? (taking care to replace the username and password with dummy text :slight_smile: )

Working as you describe - made the changes to the sensor/climate configuration and did not edit my group… all seems to be operating with a seamless transition. Thank you!

(Note, I’m only using a few of the sensors to save dashboard space)

1 Like

Excellent, good news :slight_smile: glad to hear the change to the new version went smoothly and all is working

Thank you so much for letting me know

(also pleased to hear that adding the functionality for the optional device configuration to add certain devices is of use and being used :slight_smile:)

Mmm, still the same error

17-04-21 15:57:11 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform hive
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 153, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/hive.py", line 409, in setup_platform
    HiveSession_Current.UserName = config[CONF_USERNAME]
KeyError: 'username'

Definitely only have hive.py in custom_components, custom_components\climate and custom_components\sensor folder.

My configuration.yaml file has:

hive:
  username: <redacted>
  password: <redacted>

Will have another dig around.

Hi gr4z

Are you sure you downloaded the three new files and placed each one in the three different folders?

Line 409 from your error message with the UserName is where the old version file takes the username from the configuration and adds it to a variable.

Your configuration as you pasted it looks good.

it might be easier to delete all previous hive files from your custom component folder structure, then re-down load the new three different files and re-copy the correct file to the correct folder.
Just to confirm, that there are three file links above and each one is a different file that needs to be downloaded separately and needs to go in the correct folder for it to all work

OK deleted everything and recreated the relevant files. All seems to be good now. So it must of been some legacy data :slight_smile: thanks for your help.

1 Like

glad to hear it is all working now for you, glad I could help :slight_smile:

just to check, and you could have the device somewhere else or you could have decided not to add it, but in this version you can add “- hive_hotwater” to your config to add hotwater control. you can then add “- climate.hive_hotwater” to your group config

@rendili Yeah, sure thing.

First you’ll have to get token by sending a POST request to https://beekeeper.hivehome.com/1.0/gateway/login with the content type set as application/json (otherwise you get a MALFORMED_REQUEST error) and the username and password in the body: {"username":"[email]","password":"[password]"}. Not going to post the response for privacy purposes :wink:.

Then after that you can request all the products the user owns by sending a GET request to https://beekeeper.hivehome.com/1.0/products with the content type set as application/json again and the authorization header as the token you got from the first request. You should get a list of products they own (heating, hot water, e.t.c) and their individual IDs, schedules, statuses, e.t.c.

You can set modes/temperature of a product by sending a POST request to https://beekeeper.hivehome.com/1.0/nodes/heating/ + the ID of the product. You’ll have to set the content type and authorization headers again, but this time you can send what to set the product to in the body. E.g.: {"mode":"SCHEDULE"} or {"target": 20} or {"target": 22, "mode": "MANUAL"}.

One last thing you can request are all the individual devices (hub, thermostat, boiler controller) by a GET request to https://beekeeper.hivehome.com/1.0/devices, although it’s not that useful, apart from getting the battery percentage from the thermostat.

That should be most of it, just ask if you need help with any of it. :cat2:

1 Like

@Syx All mine does is add the thermostat to Home Assistant with full control e.t.c. it’s entity name should be: climate.hive_thermostat. You can check by going to “States” in the HA dev tools.

Thanks GreenTurtwig. I’m still fairly new to HA so getting to grips with groups and really couldn’t figure out how to get the climate sensor into the same group as the rest so thats very helpful!

I get the following, should you get any more info for the water?

No, that is everything for hotwater.
It would be great if we could change the HotWater device type from a climate to something better suited, but I don’t know Home Assistant enough to know what we could use instead

Hoping GreenTurtwig has some ideas on what component type could be used instead of climate :wink:

thanks @GreenTurtwig I will look in to that
How did you hear about the new API, is this an official one from British gas now?