brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

LightSensor Units #116

Closed danward79 closed 6 years ago

danward79 commented 6 years ago

Hi,

In the Home app on iOS, the units for light level are lux. I have set the unit to Percentage and the app does not change the unit and remains as lux.

Example code below

func New(baseTopic string, displayName string) *Sensor {
    acc := Sensor{
        Accessory:         accessory.New(accessory.Info{Name: displayName}, accessory.TypeSensor),
        TemperatureSensor: service.NewTemperatureSensor(),
        LightSensor:       service.NewLightSensor(),
        topic:             baseTopic,
    }

    acc.TemperatureSensor.CurrentTemperature.SetValue(0)
    acc.TemperatureSensor.CurrentTemperature.SetMinValue(-40)
    acc.TemperatureSensor.CurrentTemperature.SetMaxValue(100)
    acc.TemperatureSensor.CurrentTemperature.SetStepValue(0.1)
    acc.AddService(acc.TemperatureSensor.Service)

    acc.LightSensor.CurrentAmbientLightLevel.SetValue(0)
    acc.LightSensor.CurrentAmbientLightLevel.SetMinValue(0)
    acc.LightSensor.CurrentAmbientLightLevel.SetMaxValue(100)
    acc.LightSensor.CurrentAmbientLightLevel.SetStepValue(1)
    acc.LightSensor.CurrentAmbientLightLevel.Unit = characteristic.UnitPercentage
    acc.AddService(acc.LightSensor.Service)

    return &acc
}

Does anyone have any ideas, why the unit is not changing in iOS? I have also tried this with a custom light sensor type, with the same result.

Thanks

brutella commented 6 years ago

I suspect that the unit of a predefined characteristic cannot be changed – HomeKit expects lux as the unit for the current ambient light level characteristic.

Why not use a read-only brightness characteristic instead?

danward79 commented 6 years ago

Thanks, that sounds like a sensible idea!