lynxcs / homebridge-ct200

Homebridge plugin for Bosch Easycontrol CT200
MIT License
21 stars 2 forks source link

Control Multiple Thermostats #10

Closed andrewbarnes666 closed 2 years ago

andrewbarnes666 commented 2 years ago

I'd love to be able to retrieve multiple Thermostats at the same time. I can define them in the home bridge config file, assign them to rooms, but the set points per room all seem to set themselves to 10 degrees Celsius

andrewbarnes666 commented 2 years ago

Actually - I think I've managed to answer my own question ... by using the Child Bridges feature - https://github.com/homebridge/homebridge/wiki/Child-Bridges

I created a unique child bridge for each thermostat - in particular:

  1. Unique MAC address for each child bridge "username" field
  2. Unique listener port for each child bridge "port" field

I matched the last digit of the username, and the port number - and matched it to the zone

I then added each child zone individually - by searching for it (rather than scanning the barcode

  "accessories": [
    {   
        "accessory": "ct200",
        "name": "CT200 - Front Hallway",
        "_bridge": {
           "username": "aa:bb:cc:dd:ee:ff:01",
           "port": 53111
        },
        "access": "xxx",
        "serial": "yyy",
        "password": "zzz",
        "zone": 1
    },
    {   
        "accessory": "ct200",
        "name": "CT200 - Kitchen",
        "_bridge": {
           "username": "aa:bb:cc:dd:ee:ff:02",
           "port": 53112
        },
        "access": "xxx",
        "serial": "yyy",
        "password": "zzz",
        "zone": 2
    },
    {   
        "accessory": "ct200",
        "name": "CT200 - Living Room",
        "_bridge": {
           "username": "aa:bb:cc:dd:ee:ff:03",
           "port": 53113
        },
        "access": "xxx",
        "serial": "yyy",
        "password": "zzz",
        "zone": 3
    },

and so-on !

lynxcs commented 2 years ago

When I wrote this plugin, I didn't image people would have multiple of these devices. Proper support for multiple CT200 units requires rewriting the plugin from an accessory to a service. I don't have an ETA for this feature, but I'll get around to it eventually.

markunca commented 2 years ago

I was testing it yesterday with 6 rooms as I have in these rooms valves. Unfortunately, with this number of rooms, as you are calling API independently several time in parallel, I got temporary ban on API to use it. So, in this manner for more rooms, for showing read data only need to be use /zones/list from API and the other calls should be called change requests only.

lynxcs commented 2 years ago

/zones/list endpoint responds with temperature and current status (heating / idle), that means in theory only target temperature and target state has to scale linearly with room number. There could, in theory, be an improvement from 7x to 2x + 4 requests for full status, where x is number of zones.

markunca commented 2 years ago

Not sure which info from /zone/list you are missing. I was thinking aboud /zone/list and /zone/zn1 the same way as you can see in bosch mobile app home screen. I think that for status of accessories in home app it should be ok to call just /zone/list and zone/zn1 as zn1 is ct200 main panel and additional request can be handle on change or detail only. But probably I overlooked something missing.

lynxcs commented 2 years ago

Currently, the plugin has in total 7 endpoints (not counting set, only get). When you use child-bridges that means that you have in total 7 * x requests (depending on how many devices you have). But if I switch to using /zone/list that takes care of 2 api calls (per device) to only a single request for all devices. That only leaves target temperature and target state, which will have to be made per device. Humidity / Away mode / Localization are also not per device, but general endpoints. /zone/zn1 only returns the list of further available endpoints. An endpoint that displays all info about a particular zone doesn't exist.

So, with a rewrite and some optimization, instead of having 7 requests per device, you can have 2 requests per device and 4 requests in general. This would avoid the issue of API ban.

I hope I've explained it clearly, couldn't think of another way to phrase it 😄

lynxcs commented 2 years ago

The rewrite is now in the main repo and on npm. Please test it out and let me know if everything is working correctly for multiple devices. Currently, the Away and Advance switches are not implemented yet.

Note: the config format has changed, since it's now a platform instead of an accessory.

@markunca It would also be great if you could check /system/sensors/humidity endpoint. I have only one device, so there is only one endpoint (/system/sensors/humidity/indoor_h1), but I'm not sure that number increases with device count.

EDIT: Away mode implemented. A few issues present: away mode can only be turned on (turning off doesn't do anything). Sometimes setting temperature fails. Fix coming soon. If you need stability, I'd recommend staying with V1 for now.

markunca commented 2 years ago

Humidity is present in API only for indoor_h1 as it is measured by CT200. I expect that valves dont have humidity sensors, unfortunately.

markunca commented 2 years ago

btw just saw, that bosch-xmpp also supports bridge mode which can help calling multiple times values, wdyt? https://github.com/robertklep/bosch-xmpp/issues/25

lynxcs commented 2 years ago

I believe that we are already using 'bridge' mode. I think it's more for when you have to call the CLI tool multiple times, to avoid setting up the same connection. But while using library, this already happens (.connect() is called once, and so is .end())

Though, currently, my code doesn't reconnect if some connection problem occurs, so that is one area I could improve. (and error handling in general)

andrewbarnes666 commented 2 years ago

The rewrite is now in the main repo and on npm. Please test it out and let me know if everything is working correctly for multiple devices. Currently, the Away and Advance switches are not implemented yet.

Note: the config format has changed, since it's now a platform instead of an accessory.

@markunca It would also be great if you could check /system/sensors/humidity endpoint. I have only one device, so there is only one endpoint (/system/sensors/humidity/indoor_h1), but I'm not sure that number increases with device count.

EDIT: Away mode implemented. A few issues present: away mode can only be turned on (turning off doesn't do anything). Sometimes setting temperature fails. Fix coming soon. If you need stability, I'd recommend staying with V1 for now.

Now using v2.1.6 - gotta say, I LOVE it, makes the whole process so much simpler and Just Works ™️ ! Thank you very much !

lynxcs commented 2 years ago

Closing this issue, since everything is 99.9% there.