yenoiwesa / homebridge-daikin-airbase

A Homebridge plugin for the Daikin Airbase WiFi module
Apache License 2.0
21 stars 4 forks source link

[Feature] Implement zones support #7

Closed TimofeyK closed 4 years ago

TimofeyK commented 4 years ago

@yenoiwesa I know it might be a long shot but I am getting a Daikin zone controller installed next Monday and keen to see zones support in this plugin one day

I totally understand that creating support for something that you don’t have yourself is hard so willing to help in any way I can

yenoiwesa commented 4 years ago

Happy to have this implemented once you have it working at your home! Let me know when your installation is done 👍

TimofeyK commented 4 years ago

Got it installed today. Usability of the controller is awful but controlling zones from URL works :-)

I figured out the following details:

  1. http://< IP >/skyfi/common/basic_info

en_setzone=1

1 indicates zones support

  1. http://< IP >/skyfi/aircon/get_model_info

en_zone=4

Number of zones. This is controlled by a field setting on the aircon and can be set to 1-8. Airbase app will show switches for the set number of zones

en_common_zone=0

Common zone enabled/disabled. Controlled by a field setting. If enabled you can turn all zones off (common zone will still let air through), if disabled, the controller will refuse to turn off the last active zone to prevent aircon damage from the pressure buildup

  1. http://< IP >/skyfi/aircon/get_zone_setting

ret=OK,zone_name=%44%6f%77%6e%73%74%61%69%72%73%3b%4d%61%69%6e%3b%42%65%64%72%6f%6f%6d%20%32%3b%42%65%64%72%6f%6f%6d%20%33%3b%5a%6f%6e%65%35%3b%5a%6f%6e%65%36%3b%5a%6f%6e%65%37%3b%5a%6f%6e%65%38,zone_onoff=1%3b1%3b1%3b1%3b0%3b0%3b0%3b0

Returns list of all 8 zones names and if they are on/off (even if number of enabled zones is less than 8). All characters are encoded for parameter values

  1. http://< IP >/skyfi/aircon/set_zone_setting?zone_name=%44%6f%77%6e%73%74%61%69%72%73%3b%4d%61%69%6e%3b%42%65%64%72%6f%6f%6d%20%32%3b%42%65%64%72%6f%6f%6d%20%33%3b%5a%6f%6e%65%35%3b%5a%6f%6e%65%36%3b%5a%6f%6e%65%37%3b%5a%6f%6e%65%38&zone_onoff=1%3b1%3b1%3b1%3b0%3b0%3b0%3b0

This is to set zones on/off. You have to send all 8 zone names and all 8 on/off values, otherwise Airbase returns error. All characters in parameter values has to be encoded, otherwise Airbase returns error

Basically I took the result from the get_zone_setting and send it back only replacing a comma between parameters with & and it worked. Tried to flipping 0/1 and changing zone names - worked

I think in the plugin it's best not to generate zone names and just send them back as is to avoid accidental changing them

TimofeyK commented 4 years ago

The logic would be: If en_setzone=1 - enable support for zones and generate number of switches based on en_zone value. Name switches from get_zone_setting

If en_common_zone=0 don't allow turning off the last active switch

TimofeyK commented 4 years ago

Probably makes sense to implement zone switches as a separate grouped accessory with multiple switch services. The main aircon device already has 4 services so adding more might make a mess. Especially with the way how Home app sorts accessories

This also will match the logic of a physical wall controller where zones are completely independent from the mode controls

yenoiwesa commented 4 years ago

@TimofeyK how do you set the fields settings on the aircon? I am curious.

TimofeyK commented 4 years ago

That depends on the controller. There is little documentation available but for my new one it was in the manual. Search YouTube for Daikin field settings and there are several videos for most common settings

yenoiwesa commented 4 years ago

@TimofeyK wow that's great I finally found how to change the fan speed of my unit, it was at the maximum possible setting and even on low fan speed, it was quite noisy! Thanks so much for helping me discover field settings! Haha

yenoiwesa commented 4 years ago

@TimofeyK I have a first version of the plugin with zone support. I have not been able to test any of the zone functionality so there is a 150% change it will fail dramatically. I am now running with that version in my home and the basic aircon functionality has not regressed (so far).

Please install the following version:

npm install yenoiwesa/homebridge-daikin-airbase#69c66ddc096ace1f8f82cbe2224eaef1f4058b6d

And start your Homebridge server in debug mode. Let me know what happens 😬

TimofeyK commented 4 years ago

Installed, restarted Homebridge but nothing new happened. I can see a new zone-switch.js file in the npm module folder but nothing in logs related to zones

Do I need to do anything other than installing?

TimofeyK commented 4 years ago

OK, I needed to use install -g

[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Auto-discovery finished with 1 device(s) found
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Sent: http://10.0.1.30/skyfi/common/basic_info With Values: undefined Response: {
  version: '1.1.3',
  name: 'Daikin',
  zonesSupported: true,
  ssid: 'DaikinAP08350'
}
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Sent: http://10.0.1.30/skyfi/aircon/get_model_info With Values: undefined Response: {
  model: 'N/A',
  type: 'N',
  isHumidifierSupported: false,
  zoneCount: 4,
  setTemperatureSupported: true,
  fanRateSupported: true,
  fanDirectionSupported: false,
  autoModeSupported: true,
  dryModeSupported: true,
  coolMinTemperature: 16,
  coolMaxTempertature: 32,
  heatMinTemperature: 16,
  heatMaxTemperature: 32,
  fanRateSteps: 2,
  autoFanRateSupported: true
}
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Found Aircon Daikin
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Starting polling for Aircon state every 5 minute(s)
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] TypeError: this.getRawZoneSetting is not a function
    at DaikinAirbasePlatform.accessories (/usr/lib/node_modules/homebridge-daikin-airbase/src/daikin-airbase-platform.js:58:54)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
[3/29/2020, 9:37:31 PM] [My Daikin Airbase Hub] Initializing platform accessory 'Daikin'...
yenoiwesa commented 4 years ago

Ah, some bad copy paste. I fixed it, please install:

npm install -g yenoiwesa/homebridge-daikin-airbase#ab714eb34969279a08d6f4ac02775ca5f8e20293
TimofeyK commented 4 years ago

Much better! :) Reading status correctly, setting fails because AirBase wants ALL characters to be encoded, not just special symbols. Also the URL in the log seems to be encoded twice. Look at my examples above - that the only form that the controller accepts

[3/29/2020, 11:14:35 PM] [My Daikin Airbase Hub] Sent: http://10.0.1.30/skyfi/aircon/set_zone_setting?zone_name=Downstairs%253BMain%2520bedroom%253BBedroom%25202%253BBedroom%25203%253BZone5%253BZone6%253BZone7%253BZone8&zone_onoff=1%253B1%253B1%253B1%253B0%253B0%253B0%253B0 With Values: {
  zoneNames: [
    'Downstairs',
    'Main bedroom',
    'Bedroom 2',
    'Bedroom 3',
    'Zone5',
    'Zone6',
    'Zone7',
    'Zone8'
  ],
  zoneStatuses: [
    1, 1, 1, 1,
    0, 0, 0, 0
  ]
} Response: null
yenoiwesa commented 4 years ago

@TimofeyK so somehow, Daikin engineers have decided to not use standard URI encoding for the zone names parameters but instead use custom percent hex encoding, and yet use standard URI encoding for the zone on/off 😩

Either way, I made a fix, could you please try:

npm install -g yenoiwesa/homebridge-daikin-airbase#3c8bdbf70b63d7be06b1ae2477c7c221f17e9ae7
TimofeyK commented 4 years ago

Woo-hoo! It works! Thank you @yenoiwesa

Daikin API is really weIrd. Updating zone names in the same call as turning them on/off for example. But at least the controller is very stable. In a year it went offline only once and only when I was doing a lot of changes and restarts to my wifi mesh network

yenoiwesa commented 4 years ago

That's great news! Coding in the dark is not the easiest lol.

Would you have a screenshot to share so I can see how it looks? :-)

TimofeyK commented 4 years ago

B73D6C2A-47CA-46A2-B638-69F9B02E2875 8BA867D6-48BD-4D0A-9B20-B381B9A3D076

yenoiwesa commented 4 years ago

Nice! Thanks.

I will wait for a day or two to make sure you have time to find bugs, and if I don't hear back I will just merge this branch into master and officially release it.

TimofeyK commented 4 years ago

So far so good! I haven’t seen any issues

Few things that aren’t bugs but worth mention in readme:

yenoiwesa commented 4 years ago

If a zone name is changed you need to restart Homebridge for the plugin to pick new name. I thought it might overwrite the name back but the plugin correctly reads the new name and sends in back when setting zones. It will not refresh names for zone switches (expected, because it set on start) and will not be able to read the state of the renamed zone (acceptable)

Yes I also think the behaviour is acceptable. I wouldn't expect people to change zone names often on the Daikin Wall Controller.

The plugin allows to turn off all zones but if there is no common zone configured in the aircon, the controller will ignore turn off for the last active zone. The plugin will reflect that on next refresh

Homekit does not allow to disable a switch, so the only thing I could do for that is to check whether it is the last switch on, discard the command and then quickly update the state of the switch back on. That would be a bit tricky, so I think code wise it's better the plugin does not make assumptions about that mode for now.

Sorting of accessories in the Home app is kind of unpredictable: it sorted “Downstairs” in front of “Bedroom” but the rest are sorted alphabetically. Best to mention that the plugin has no control over sorting and this can only be done by changing zone names

Yes I will make a note in the README file about that.

yenoiwesa commented 4 years ago

Version 2.0.0 of the plugin has now been released! 🎉

You can update your homebridge server to the official release with the following command:

npm install -g homebridge-daikin-airbase@2.0.0