snowdd1 / homebridge-knx

KNX platform shim for homebridge
https://github.com/nfarina/homebridge
GNU General Public License v2.0
97 stars 56 forks source link

"ServiceType": "Fan" with Characteristic.RotationSpeed #92

Closed migabc closed 7 years ago

migabc commented 7 years ago

Hi,

My Fan has 3 positions 0 -> Off 1 -> Low Speed 2 -> High Speed

How can I set the RotationSpeed to go from 0, 1, 2 (Like a 3 position switch)?

                "ServiceType": "Fan",
                "ServiceName": "HRV Fan",
                "Characteristics": [
                    {
                        "Type": "RotationSpeed",
                        "Set": [
                            "5/2/106"
                        ],
                        "DPT": "DPT5",
                        "minValue": 0,
                        "maxValue": 2,
                        "minStep": 1,
                        "Listen": [
                            "5/2/106"
                        ]
                    }
                ]

How can I limit DPT5 between 0 and 2?

snowdd1 commented 7 years ago

You cannot. RotationSpeed is a percentage type. See https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js#L1604-#1613

You would need to write an handler that converts the values 0,1,2 into the range 0-100 (e.g. 0,50,100) and that in both ways.

migabc commented 7 years ago

Hi, As you suggested, I wrote a handler for this.

onHKValueChange(field, oldValue, newValue) {
    log('INFO: onHKValueChange(' + field + ", " + oldValue + ", " + newValue + ")");
    if (field==="RotationSpeed") {
                    // RotationSpeed is DPT5.001 Percentage (0..100)
                    // need to convert to DPT5 Integer (0,1,2)
        var knxValue = (newValue*2/100);
        this.myAPI.knxWrite("RotationSpeed", knxValue, "DPT5"); // send the new knxValue to the KNX bus

It is working fine.

Thanks, Miguel

snowdd1 commented 7 years ago

Great to hear.