Hive Integration

Thanks, but I got the imports, although I did forgot to mention them.

OK, so there’s nothing obvious that springs to mind, so time to fire up PyCharm and see if I can see what’s going on, as it seems to me that in theory, hive & hive1 should be as isolated as ‘serviceA’ and ‘serviceB’, but I need to check whether pyhiveapi supports that form of isolation of two users. (My assumption is that it does and I’ve missed something, though!)

Hi @gwynevans,

The pyhiveapi should support it as the component creates a new instance, so hive will create a new instance and hive_1 will create a second instance.

having a quick look I can see the following which will need changing in the duplicate hive_1.py files so as to give it a chance to work:

In the main component file:
DOMAIN = 'hive' --> DOMAIN = 'hive_1'
DATA_HIVE = 'data_hive' --> DATA_HIVE_1 = 'data_hive_1'

In each platform file:
from homeassistant.components.hive import DATA_HIVE --> from homeassistant.components.hive_1 import DATA_HIVE_1
DATA_HIVE --> DATA_HIVE_1
DEPENDENCIES = ['hive'] --> DEPENDENCIES = ['hive_1']
session = hass.data.get(DATA_HIVE) --> session = hass.data.get(DATA_HIVE_1)

In your configuration yaml you will need to entries:

hive:
  username: YOUR_USERNAME
  password: YOUR_PASSWORD

and

hive_1:
  username: YOUR_USERNAME
  password: YOUR_PASSWORD

Hello @rendili

I see that you have done a lot of work on the hive integration with home assistant and I just have a few queries.
i have hive and I’ve been able to set it up on my home assistant. However, I have door sensors and home assistant does not register a change of state quick enough.
Just wondering if you have done any work on this and are able to help?

Hi @wallace_54

Unfortunately with the sensors (door or motion), they are registered with the Hive cloud, so when there is a state change they immediately push their new state change to the Hive cloud service and you will be able to see that state change immediately on the Hive app.

What we are doing with the Home-Assistant Hive integration is pulling data, including current states, from the Hive cloud via the API every 2 minutes (by default), so it could be up to 2 minutes after a state change on any of the Hive devices where you will see this state change in HA after it pulls the latest data from the Hive cloud service. There is nothing in the Hive cloud service or the actual Hive sensors which can push the state change directly to your HA instance.

With switches or heating the changes you make in HA are immediate as once you make a change via HA like turn on a switch, light or heating this is then immediately pushed to the Hive cloud via their API.

I hope this helps, let me know if I can help further.

Thanks @rendili for the quick response.

I thought this might be the case!
I did add the scan_interval in the configuration file and changed it so I could pull information more frequently but to no avail.

Hi @wallace_54

The scan_interval should enable you to decrease the time between updates from the default of two minutes to the minimum of one minute, so should be a little better:

hive:
  username: YOUR_USERNAME
  password: YOUR_PASSWORD
  scan_interval: 1

With the Hive sensors I don’t think there is any way of making it any faster, personally I use z-wave sensors directly registered to HA, Aeotec Multisensor 6, and these are pretty instant to push their state to HA

Thanks for the look, but it looks to me as if the issue is down in Pyhiveapi and to fix it properly will, as I believe you suspected from the start, take a bit of work. The specific issue is that Pyhiveapi does assume there’s only a single session and holds it’s details in a module-level HIVE_API instance (pyhiveapi.py:111), used in hive_api_json_call (pyhiveapi:139:144)…

I

@gwynevans,

sounds like you are more of an expert than me, do you think it would resolve it by moving lines 111 and 112 in pyhiveapi to inside class Pyhiveapi:?
To me this should be ok as theses instances would be inside the pyhivapi class and therefore the instance that HA creates for each component?

If so I could make this small change fairly quickly and update the HA hive integration to the new pyhiveapi version for the release after next for HA (if there was no negative side-effects for single Hive installation setups).

Unfortunately, I’m afraid not - it’s a start, although you’d need to create them in the init method as self.HIVE_API/HSC else they’d be class instances, but the problem then is that the classes within Pyhiveapi (Heating, etc) are not derived from Pyhiveapi so have no access to it’s instance variables. (They are sub-classes, but that’s more of a naming thing).

I’m having a play around, to see what I can come up with (in between other jobs!), but think it’ll need changes to the caller too, relating to how the sub-classes are created, so not just a move of couple of lines.

no, you are right, a full proper solution is more than moving a couple of lines, I was more hoping that this could help with the work around of duplicating the files to create a second separate instance, but sounds like it doesn’t either, sorry.

Hi - just for info, I’ve put a version of pyhiveapi.py up on github (https://github.com/gwynevans/pyhiveapi/blob/multi-session/pyhiveapi/pyhiveapi.py) that supports multiple accounts. Unfortunately, it’s based off 0.2.5 so I don’t think it’ll be of direct use until I’m able to rebase it onto your current HEAD, but it might be of interest.

Quite a lot of lines changed, but the basic functionality’s unchanged, it’s mostly moving things to use instance rather than module or class variables.

/Gwyn

that’s a lot of changes…

Afraid so, although I’m not suggesting they get merged at the moment, it was more of an working note of one possibility. I’ve not done enough serious Python to know if I’m overlooking things that would simplify it, but equally most of the changes are just to switch the original processing to using instance variables rather than the module and class variables currently used.

It is at all possible to access the motion sensor ‘Actions’ from the pyhiveapi - and switch them on and off?

What am I trying to do:
I would like to switch the motion sensors actions on and off dependent on the time of day/position of the sun

It may be easier for me to simply abandon the hive motion sensors… but they seem to work pretty well, just not configurable from HA… yet

@gwynevans, you are using your version of the library with duplicate hive files each with its own instance?

@Dan1, to clarify, you would like to update the Hive automations / actions to turn them on or off based on HA automations with HA giving the command to turn a specific Hive automation / action off or on?

HI Guys

Only had the hive heating installed this week, before then I’ve just been using bulbs an switches. I’ve been playing around with some basic automations but I can’t seem to get the climate.set_operation_mode to work specifically for turning it to “off”.

I can get it to change to heat a specified temperature no problem and if I add a set_temperature to my off automation it’ll set the temp, but this action as part of an automation:

    action:
  - service: climate.set_operation_mode
    data:
      entity_id: climate.heating
      operation_mode: off

Never works, I’ve stripped out any conditions and just left it as basic as possible but will never change the operation_mode to off.

Any ideas?

Thanks :slight_smile:

Have you tried

'off'

Haha wow, that works, thanks!

I was just going off the climate component info on the HA page.

As I’m a complete newbie to all of this type of stuff, I’m just learning as I’m going and haven’t done any sort of coding before, do you know why it will change the mode to heat without the single quotations, but it will only change to off with them?

Thank you again :slight_smile:

No worries :slight_smile:

I don’t know for sure, but my guess is that it is a behaviour of Python (whereby off is interpreted as 0 but ‘off’ is a string passed through the code; heat is not a reserved word, and is therefore ignored and hence passed straight through).

There are enough Python devs around here who know what they are talking about + will be able to confirm this.