Connecting HomeKit to light sensor: Percentage to lux conversion issue

Hello,
I just did the upgrade to 4.0. One of the issues I can’t solve yet is around a light sensor (Livisi) that provides values in percentage. I want to connect this to HomeKit, which expects lux.

In OpenHab 3.4.3 I used this JS transformation for a rough conversion (not very accurate, but usable for me):

| Math.pow(2, parseInt(input)/9+2)

I could get this working in OpenHab 4.0.1 again as a Thing To Item transformation like this:

| Math.pow(2, parseFloat(input)/9+2)

For some reason I have to use parseFloat now instead of parseInt.

The light sensor item has Number:Dimensionless. I set the item metadata to Number:Illuminance

Now I see in the item the expected value, e. g. 322.3 lx. But the HomeKit integration throws an error:

19:32:22.406 [WARN ] [ristics.impl.base.FloatCharacteristic] - **Detected value out of range 322.5398. Returning max value instead. Characteristic io.github.hapjava.characteristics.impl.lightsensor.CurrentAmbientLightLevelCharacteristic@130469**

In Apple HomeKit I get 100 lux.

When I inspect the HomeKit configuration, I see:

openhab> openhab:homekit show 221276695
221276695 Lichtsensor Büro
Services:
  Service Type: LightSensorService (00000084-0000-1000-8000-0026BB765291)
    Characteristics:
      CurrentAmbientLightLevelCharacteristic: {"iid":0,"type":"6B","perms":["pr","ev"],"format":"float","value":100.0,"minValue":0.0,"maxValue":100.0,"minStep":0.00010,"unit":"lux"}

Why is the LightLevel characteristic set to expect a maxValue of 100? Is it still taking over the “percentage” from the Number:Dimensionless of the Thing?

I think I solved it myself by adding a configuration to the HomeKit metadata:

value: LightSensor.LightLevel
config:
maxValue: 100000

Why this is necessary though I don’t understand as it should be the default maxValue for Illuminance.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.