oischinger / ha_vicare

Inofficial Home Assistant custom component for Viessmann ViCare API
61 stars 33 forks source link

Support multiple devices #78

Closed bbock closed 1 year ago

bbock commented 2 years ago

As described in detail here, I have a hybrid installation containing a heatpump and a gas burner as support. The Home Assistant integration currently can only support one device, which happens to be the first one returned by the API.

It would be great if all available devices show up in Home Assistant.

ringo0385 commented 2 years ago

Also interested in this as I have the same scenario!

oischinger commented 2 years ago

The limitation to support only a single device can only be handled by a multi-step config flow which allows the user to configure each device individually (especially the heating type).

For my understanding, to see if this would be the right direction could you please try the following: If you change the mentioned code device = vicare_api.devices[0] to device = vicare_api.devices[1] you should get different entites for your heating device. If all of these entities would be created for both heating devices, would any of those be duplicates or would all sensors, water_heater and climate entities be unique to the respective device?

ringo0385 commented 2 years ago

Sounds promising.. How does one modify this code to test? Sorry, I'm new to HA in general, so any pointers would be appreciated. :)

oischinger commented 2 years ago

Are you using the custom integration or the one bundled with Home Assistant? You would need to use the custom component from this repository, and copy the contents of https://github.com/oischinger/ha_vicare/tree/master/custom_components/vicare to /config/custom_components/vicare/

bbock commented 2 years ago

Changing the index absolutely works, the other device is recognized after HA restart and all sensors and entities are discovered. I do not have duplicated values, but all entities are actually belonging to the 2nd device (in my case, gas consumption, burner hours etc are showing up, while the 1st one shows sensors related to the heat pump).

From my point of view, everything works exactly as expected with vicare_api.devices[1].

ringo0385 commented 2 years ago

Thanks for the pointer. I can confirm the same behavior and both devices show up when I play around with the array value. Obviously, I can only see/control one device at a time as the other device entities will show as 'unavailable'.. Hope it's easily adaptable! :D

Hartislap commented 2 years ago

I will get my third heater this week (home, parents, parents-in-law) from Viessmann, are there any plan to include the integration of multiple devices in the ViCare Integration soon? For now it is working as I have "my" heater in HA, but it would be really nice to include the other two heaters for statistical/visual purposes (solar temp etc) in my HA.

oischinger commented 2 years ago

I looked into it some time ago and it turned out to be more work than expected. I'm sorry to say that I just didn't find the time to do it yet. PRs are welcome though.

oischinger commented 1 year ago

I know this has been a long wait but I finally got around to do some work for this. In case anyone is interested to do some very early testing please check out this PR: https://github.com/oischinger/ha_vicare/pull/120

Note that you will have to remove your existing vicare configuration to avoid getting duplicate entities

bbock commented 1 year ago

This is awesome, thanks a lot @oischinger .

I just installed the branch and the first impression is very positive. It seems to work well on the first glance. As noted already, I got duplicate entries, so I wiped the old configuration and re-added the integration. Everything is clean and in a working state now.

Only difference I noticed right away (this is probably intentional, for disambiguation if one has >1 devices of the same type): The device names have an appended "-0". If anything, this is a purely cosmetic issue.

I will report back any additional findings in the next couple of days as I am monitoring the entities closely.

oischinger commented 1 year ago

@bbock Can you make sure you are on the latest commit of the branch and send me screenshots of your devices on the entities page? And ideally you could alsp download/attach diagnostics.

Since I myself don't have multiple Viessmann devieces this feedback is very helpful

bbock commented 1 year ago

I am on commit 038b018.

As linked on the initial description of this ticket, I have a hybrid heatpump / gas installation consisting of Vitocal 200-S and Vitodens 200-W.

diagnostics-log.json.gz

Entites overview screenshot:

vicare_entities

oischinger commented 1 year ago

Thanks!

You already noticed the new suffix: e.g. "0". This is the device ID delivered by viessmann. it's now part of the HomeAssitant device as well.

Looking at the diagnostics json I'm a bit confused because I would have expected more entries in the data section(line 72) image

Maybe both of the devices have the ID "0", then in the diagnostics dump, I would only show one of them.

Can you please also make a screenshot of the HA integrations page: image

bbock commented 1 year ago

As far as I can see, both devices indeed get the ID 0:

vicare1

vicare1

oischinger commented 1 year ago

@bbock I suspect that you have multiple installation IDs and either one has a device with ID0. I uploaded a new commit which includes the installation ID. Can you please check it out and provide the diagnostics result again?

Sorry for keeping you busy with this but everyone has different setups and your input helps alot!

bbock commented 1 year ago

You are correct, the installation IDs are different. As those IDs are masked in the URLs as private data, I'm not too comfortable posting them publicly in a GitHub issue.

What's the best way to send it in private? PyVicare Discord? e-mail?

oischinger commented 1 year ago

Good point. I didn't think of that data being privacy relevant. Can you just search/replace them in the json file with some fake ids? otherwise you can share it via email to hans.oischinger@gmail.com and I'll delete after use

bbock commented 1 year ago

You're right, I just replaced the IDs. Here's the file:

config_entry-vicare.json.gz

Iminet72 commented 1 year ago

I also tried the modification "vicare_api.devices[1]" I have two boilers, one 100 series and one 200 series. When I change the ID, I see 200 because it is 1 ID. Actually, it's mainly what I need. If you need information, I will be happy to help I also have a test environment separate from the live system, try that too if that helps.

RikyUnreal commented 1 year ago

I have the same problem, descibed here: https://community.home-assistant.io/t/viessmann-component/77873/863

Hope you find a workaround to fix it. I'm not a developer or a skilled programmer, but if you need me to do some testing, let me know.

RikyUnreal commented 1 year ago

Hi @oischinger, I read you leave the official vicare codeowners

So I'm bit confused (sorry I'm not an expert) To handle multiple devices, should I uninstall the official component and install the 1.0.0-alpha.3 via HACS ?

oischinger commented 1 year ago

Hi @RikyUnreal Yeah unfortunately I cannot maintain it as part of HA Core anynore but I decided to maintain and improve this custom integration. It supports multiple devices. If you want to test it please install via HACS (see Readme).

I'd be glad to hear your feedback.

RikyUnreal commented 1 year ago

I'd be glad to hear your feedback.

Unfortunately I can't see the "ViCare" integration in the HACS repository list. It is my fault? Cantsee

(you can move or delete this off-topic message)

oischinger commented 1 year ago

You need to add this repo to the HACS repos. It's not yet in the official list

RikyUnreal commented 1 year ago

Nice! It all seems to work like a charm.

I see the same sensor as @bbock . The sensors with the same name are distinguished by "_2" suffix.

001 002

Now I'll do some tests and I'll inform you if I find any issue. Thank you very much for your efforts in this integration.

Iminet72 commented 1 year ago

I installed it and it works great. I can see both boilers

RikyUnreal commented 1 year ago

Hi there, the integration still works fine, but now, with two devices, I'm exceeding the 1450 API calls-per-day (basic free plan of the Viessmann Developer Portal).

I've tried to disable the entities that I'm not interested in (I need only twenty entities or so of the of the 66 available), but it seems the number of the API calls remains the same.

Is there a way to reduce the API calls rate? Maybe remove the unnecessary entities instead of disabling them?

This is the log error:

Last logged: 5:57:31 PM

Vicare API rate limit exceeded: (PyViCareRateLimitError(...), 'API rate limit development portal "bef5501f-6b26-4995-81b3-954afd864a06" daily limit exceeded. Max 1450 calls in timewindow. Limit reset at 2023-04-08T00:00:03.866000.')
RikyUnreal commented 1 year ago

I've been thinking about it. Your integration probably makes an API call every minute (regardless of the number of entities available), so ~1440 calls-per-day. But with two devices, we have 1440 x 2 calls per day, and that exceeds the limit.

Is it possible to add a configuration parameter to let the user adjust the API call ratio? In my case, I could set a 2 minutes interval for the API calls. I would get "less dense" data and graphs, but that would still be acceptable for my purposes, and I would be within the limit.

oischinger commented 1 year ago

@RikyUnreal actually I considered that: See https://github.com/oischinger/ha_vicare/blob/187c57a577f04757b3057422c6875fd308500076/custom_components/vicare/__init__.py#L131 But it seems that it'snot working as expected. I will have a look

oischinger commented 1 year ago

@RikyUnreal can you please update to 1.0.0-alpha.5

It should fix the issue. Please let me know if it helped

RikyUnreal commented 1 year ago

It should fix the issue. Please let me know if it helped

Hi Hans, I updated to alpha.5, but the problem still persists. However, something is changed. Now the sample rate seems to be 91 seconds, so I reach the limit after about 16 hours.

If it is possible, increase it more to cover 24 hours.

RikyUnreal commented 1 year ago

Hi Hang @oischinger , any news for this issue?

Despite the changes introduced with the alpha.5version, the problem persists.

As you can see from the report on the Viessmann API portal, daily requests remain at 2900, or 2 per minute.

API

oischinger commented 1 year ago

@RikyUnreal I believe I finally fixed the issue. Can you please check 1.0.0-alpha.6 ?

RikyUnreal commented 1 year ago

I believe I finally fixed the issue. Can you please check 1.0.0-alpha.6 ?

Cool! I'll try immediately.

RikyUnreal commented 1 year ago

After 5 hours running the alpha 6, according to the report on the Viessmann API portal, I have 90 calls per hour. Still too many... and I don't know why exactly 90 instead of 60.

To be sure, I'll post a new update tomorrow after the reset of the Viessmann counter.

oischinger commented 1 year ago

That's really weird. I'll need to investigate what's wrong here. But thanks for the feedback!

RikyUnreal commented 1 year ago

Good morning Hans, I confirm the trend.

I took the screenshot below at 9:00 local time (Italy). The Viessmann counter is reset at 00:00 UTC (2:00 local time).

As you can see, after 7 hours I have 631 API calls: exactly 7 x 90.

API

RikyUnreal commented 1 year ago

Hi Hans, I'm trying to do some "empirical testing" (as I already said, I'm not a Python programmer) and I discovered that if I change the DEFAULT_SCAN_INTERVAL value in const.py, I get a change in the actual number of API calls .

Right now I set DEFAULT_SCAN_INTERVAL to 150, and I have only 40 calls per hour! (I don't really know why exactly 40...).

I hope this is useful for your investigation.

oischinger commented 1 year ago

Fixed with at least 1.0.0-beta1