Announcing some improvements to the Homekit plugin for openHAB 2

@Beluk I reverted the blinds support for now, since it caused things to fail in catastrophic ways. I’ll have to investigate more why it fails so hard, I suspect something is broken with WindowCovering support in HAP-Java.

@Beluk I was able to fix the issue in upstream HAP with WindowCovering; the 4th release of my forked homekit plugin has it enabled. Give it a try. I think the plugin is getting very good and robust now.

Thanks for the update, i’m very busy at the moment, but when i have some spare time i will try it out and give you some feedback.

@Tim_Harper I tried https://github.com/timcharper/openhab2-addons/releases/tag/v2.4.0-homekit-4, principally it is working, but the reaction is not good.

After opening Homekit on iPhone it tries to update 1-2 minutes long the items:
image
After that it tells me that there was no response:
image
But when clicking on the items they get working:
image

Unfortunately this happens every time the app is not in the foreground.

1 Like

Hello,

I am running OH 2.4 stable release. I was really glad to see that the HomeKit add-on started to get updated again.

I have been trying to move away from the bundled HomeKit add-on and use the one that you updated (latest -4 release) to have Thermostat working both directions and be able to use it for window blinds later on.

I did struggle during a few hours to move from the built-in binding to your build but eventually managed to get my single Thermostat paired in Home app.

Unfortunately, it does not work properly, for example, I don’t have the current temperature set point value displayed in Home app when adjusting (I had before), or the Thermostat colour does not seem to get updated following mode changes. Yet, I no longer have the “No response” issues.

With your build, I have error messages that I did not have before, regarding improper Characteristics tags on Items, which appear fine to me.

2019-01-30 11:29:23.133 [ERROR] [al.accessories.HomekitThermostatImpl] - Item F0_Salon_AirCond_SET has unrecognized thermostat characteristic: OLD_TARGET_TEMPERATURE
2019-01-30 11:29:23.135 [ERROR] [al.accessories.HomekitThermostatImpl] - Item F0_Salon_AirCond_HKMO has unrecognized thermostat characteristic: HEATING_COOLING_MODE

Here are the relevant items:

Number  F0_Salon_AirCond_SET     "Consigne clim. [%.1f °C]"				<ac_set> (gAirCond, gAirCond_SET, gF0_Salon, gPersistOnChange, gF0_Salon_AirCond_HK)  [ "TargetTemperature" ] 
Number  F0_Salon_AirCond_TEMP    "Température mes. (clim) [%.1f °C]"  	<temperature> (gAirCond, gAirCond_TEMP, gF0_Salon, gPersistOnChange, gF0_Salon_AirCond_HK) [ "CurrentTemperature" ]
Group gF0_Salon_AirCond_HK "Thermostat Chambre Matthieu" (gHK) [ "Thermostat" ]
String F0_Salon_AirCond_HKMO "Thermostat Heating/Cooling Mode" (gF0_Salon_AirCond_HK) [ "homekit:HeatingCoolingMode" ]

I also get some :

2019-01-30 12:08:01.815 [ERROR] [kit.internal.HomekitAccessoryUpdater] - Received duplicate subscription on F0_Salon_AirCond_SET

@Tim_Harper, do you think any of these errors could be the cause of the wrong behaviour in Home app ?

The whole reason why this happens is Apple’s approach to Accessory, where a Lightbulb accessory needs to have an ‘On’ Characteristic and optional a ‘Brightness’, ‘Hue’ and ‘Saturation’ characteristic, depending if the lightbulb also allows dimming and/or colors. When turning the light to a specific percentage value or even HSB color value, every characteristic is fired. First the ‘On’ characteristic changes to true, then the ‘Brightness’ characteristic changes to your specified value and so on.

In my plugin I tried to solve this issue first by only accepting the ‘Brightness’ characteristic and ignoring the ‘On’ characteristic, however when turning a light off sometimes ‘Brightness’ and ‘On’ gets triggered and sometimes only the ‘On’ characteristic. My solution involves a synchronization step, where every characteristic stores its value globally and also triggers a ‘commit’ function. This function runs as a singleton and waits for 250ms (this is enough time for every possible characteristic to be set). After the wait time it will read the state item from the characteristics and decide how to properly update the OH item. You can see the implementation here (_setState currently at line 56 and _commitState at line 65).

Cheers,

Frank

@Beluk this is because the homekit plugin treats “undef” or “null” as the thing is offline. I recommend you add persistence backend which restores the values. Perhaps this will be configurable in the future.

(EDIT) I just saw you said “this happens every time the thing is not in the background”. I’m not seeing this same behavior in my own tests, and I know of at least one other person who is using the window covering support without any issues. I do suspect that an item’s value might be null in some way, but aside from that, I’m not sure what could be causing it right now. Are there any log messages that may be of help?

Can you describe in detail the ideal firing sequence? Perhaps I can improve it. I don’t have any HSB bulbs.

IE:

When I change the color, then:

  1. Only HSB value should change

When I change the on state, then

  1. The bulb should be turned on
  2. The HSB value should be sent (in this order)

etc.

@tarag Thermostat mode has always been really broken for me in Homekit. Please try my latest release, which improves things and gets it working again for me:

WRT to the “duplicate subscription”, you should be able to ignore these. I see them without any impact to functionality. I haven’t really dug in to what’s happening.

Hi Tim,

Great job ! I’m happy to see there is again evolution on this topic.
I did some brief test and it’s looking good !

One small improvement on the sensors I suggest, is to make a specific tag for a door sensor (refering to the Homekit “Door” Service). Behavior is the same as the other sensor but it will show up as a door the HomeApp.

I had tried this in the past when programming homekit, and it did not work. Homekit ignored it and expected me to specify the door type, regardless.

Anyways, if you long press the contact sensor in the Home app, you can change the type. Have a look:

hi Tim,
ok Super! I didn’t know tag “ContactSensor” was supported ! Works as you showed !

Hi Tim,

thanks for you work at the homekit plugin! :+1:

I´ve got three homematic thermostats and have them added to Alexa.
I was able to ask Alexa “how´s the temperature in the kitchen” and Alexa was able to answer with the current temperature.
Currently Alexa only answers “kitchen currently doesn´t answer”.

Item:

Number:Temperature itmHeizung_Kueche_IST "Temperatur Kueche [%.1f °C]" <heating> (Kueche, Temperatur, gPersist, gCharts) ["CurrentTemperature"] {channel="homematic:HG-HM-CC-RT-DN:default:<SERIALNUMBER>:4#ACTUAL_TEMPERATURE"}

I´m not using TargetTemperature as the heating is controlled by an central thermostat.

The device is recognized by Alexa and shows the openHAB config.
The Home app is not able to connect to openHAB.
I´m using your latest 2.4.0-5 version.

Is this an homekit or Alexa issue?
Could you please add something like -5 to your versions to make it clear which version oH is currently working with?

kind regards
Michael

Alexa issue.

That’s a great idea; I don’t think it would require very much of me to bump the version here :slight_smile: I’ll do that for future releases.

Thanks, I’ll try the -5 version.

While we are taking about Thermostats, right now I had to create a virtual HomeKit mode item that does a proxy between the binding and HomeKit because the Thermostat appliance binding (Daikin in my case) has separate On/Off and mode (Auto/Coll/Heat - Fan and Dehumidifier also) items. This does not allow and 1:1 mapping with HomeKit so there are rules to process updates to/from HomeKit, for example to set HomeKit mode to Off if the thermostat is switched Off but remains in Auto.

It would be interesting if the add-on could manage this kind of situation.

My problem is not only on window covering. It happens to all items i have configured. If you can tell me which log you need and how to get it i will provide them.

I should be able to understand what’s happening better if you get me the following info (feel free to mail to my email):

events.log (see /var/log/openhab2 ?)
openhab.log (same)
The result of curl http://{my-openhab-instance}/rest/items
Screenshots of homekit

Also, did you try the canonical homekit plugin (the one distributed in the 2.4.0 default repositories?) Is your observation a regression caused by my changes?

With a homekit thermostat…how does it work if you have mulitple temp sensors…or for it to work properly is there only supposed to be one?

And does it control power on/off, or it designed for getting and maintaining a temp (as opposed to if temp less than so and so turn on heating, turn off at time)

Hi, Tim,
thanks for your work on the Homekit plug in. I have a beginner question about the installation.
Is it correct to first delete the old version via the Paper UI, download your -5 version and replace the previous file? Then restart and continue with the configuration over Paper UI as described?

Do you mean how do i control the heating?
I´m using the tado thermostat as my residence has a central gas heating unit.
The tado thermostat comes with an app that allows multi user access and geofence based heating.
The Homematic thermostats are not talking to the tado thermostat, they´re just lower the temp when opening a windows or it´s night.
I purchased them and had a much more complex plan before i found the tado thermostat.