snowdd1 / homebridge-knx-de

German Issue/Discussion forum for homebridge-knx
https://github.com/snowdd1/homebridge-knx
20 stars 4 forks source link

Farbtemperatur LED/Panel steuern #54

Open slev1n opened 6 years ago

slev1n commented 6 years ago

Hallo zusammen,

ich möchte gerne meine Beleuchtung mit Farbtemperatur steuern. An/Aus und dimmen funktioniert bereits: "DeviceName": "Bett", "Services": [ { "ServiceType": "Lightbulb", "Handler": "millis", "ServiceName": "Bett", "Characteristics": [ { "Type": "On", "Set": [ "0/0/13" ], "Listen": [ "0/0/14" ], "DPT": "DPT1" }, { "Type": "Brightness", "Set": [ "0/0/20" ], "Listen": [ "0/0/17" ], "DPT": "DPT5.001" } ], "subtype": "" } ], "UUID": ""

Aber wie füge ich die Farbtemperatur steuerung hinzu? Mit meinen MDT Led Controller kann ich folgendes steuern:

  Nummer Name Objektfunktion Beschreibung Gruppenadresse Länge K L S Ü A Datentyp Priorität
  98 LED TW 2 Schalten Ein/Aus ikea schalten 0/0/13 1 bit K - S - - Schalten Niedrig
  100 LED TW 2 Farbtemperatur (Anteil KW in %) Dimmen Absolut ikea ft dimmen absolut prozent 0/0/18 1 byte K - S - - Prozent (0..100%) Niedrig
  101 LED TW 2 Farbtemperatur (Kelvin) Dimmen Absolut ikea ft dimmen absolut kelvin 0/0/19 2 bytes K - S - - Absolute Farbtemperatur (K) Niedrig
  102 LED TW 2 Helligkeit Dimmen Absolut ikea helligkeit dimmen absolut 0/0/20 1 byte K - S - - Prozent (0..100%) Niedrig
  103 LED TW 2 Übergang (Farbtemperatur und Helligkeit) Dimmen Absolut ikea farbe und temepratur dimmen absolut 0/0/21 6 bytes K - S - - Helligkeit Farbtemperaturübergang Niedrig
  104 LED TW 2 Farbtemperatur (Anteil in %) Dimmen Relativ     4 bit K - S - - Dimmer Schritt Niedrig
  105 LED TW 2 Helligkeit Dimmen Relativ     4 bit K - S - - Dimmer Schritt Niedrig
  106 LED TW 2 Status Ein/Aus ikea schalten status 0/0/14 1 bit K L - Ü - Status Niedrig
  107 LED TW 2 Farbtemperatur (Anteil KW in %) Status Dimmwert ikea ft status prozent dimmen 0/0/15 1 byte K L - Ü - Prozent (0..100%) Niedrig
  108 LED TW 2 Farbtemperatur (Kelvin) Status Dimmwert ikea ft status kelvin dimmen 0/0/16 2 bytes K L - Ü - Absolute Farbtemperatur (K) Niedrig
  109 LED TW 2 Helligkeit Status Dimmwert ikea helligkeit status dimmen 0/0/17 1 byte K L - Ü - Prozent (0..100%) Niedrig

Kann mir da jemand helfen bzw. mir sagen wo ich das einbauen kann?

Gruß, Matthias

slev1n commented 6 years ago

In meine FORK ist der Handler 'CTLight.js' zu finden. Damit lässt sich die Farbtemperatur in Kelvin einstellen, allerdings wurde der Pull request node-eibd für DPT7 von @farmio noch nich angenommen.

Gruß, Matthias

snowdd1 commented 5 years ago

Ist er jetzt schon.
@slev1n möchtest Du Deinen Handler als pull request zur Verfügung stellen?
Danke
Raoul

Cocco17 commented 4 years ago

Ich wäre auch sehr interessiert an der Steuerung von TunableWhite Leuchten - ich habe deinen Handler kopiert und die entsprechenden Zeilen in mein config file kopiert, allerdings bekomme ich dann folgenden Fehler:

(/usr/local/lib/node_modules/homebridge-knx/lib/knxdevice.js:89:58)
    at KNXPlatform.configure (/usr/local/lib/node_modules/homebridge-knx/index.js:220:23)
    at KNXPlatform.<anonymous> (/usr/local/lib/node_modules/homebridge-knx/index.js:94:9)
    at HomebridgeAPI.emit (events.js:327:22)
    at HomebridgeAPI.signalFinished (/usr/local/lib/node_modules/homebridge/lib/api.js:81:14)
    at Server.start (/usr/local/lib/node_modules/homebridge/lib/server.js:79:18)
    at cli (/usr/local/lib/node_modules/homebridge/lib/cli.js:88:12)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

ich nutze knxd als Schnittstelle zum KNX-Bus. Müsste es mit diesem Plugin nicht gehen?

Cocco17 commented 4 years ago

Da der Handler von @slev1n bei mir nicht richtig funktionierte, habe ich für meine LED Controller (MDT AKD-0xxx) kurzerhand selbst einen Custom Handler geschrieben, den ich mich euch teilen möchte:

Custom Handler for Tunable White Lights - CWWW.js

/* Lightbulb extension for Tunable White Lights
* Infos:
*   - used in combination with KNX LED-Controller MDT AKD-0xxx
*   - controls the "absolute" adresses for brightness and color temperature in percent [DPT5.001]
* Issues: 
*   - The LED-Controller offers smooth switch on and off effects for HCL-Mode (Human Centered Lighting). However, it also sends the current brightness value during that, which triggers the handler to adjust the brightness
*       --> Workaround: Deactivate status information during HCL changes. 
*/
/* jshint esversion: 6, strict: true, node: true */
'use strict';
/**
 * @type {./handlerpattern.js~HandlerPattern}
 */
var HandlerPattern = require('./handlerpattern.js');
var log = require('debug')('CWWW');

/**
 * @classdesc A custom handler for light apperatures with tunable white functionality
 * @extends HandlerPattern
 */
class CWWW extends HandlerPattern {

    /****
     * onKNXValueChange is invoked if a Bus value for one of the bound addresses is received
     *
     */
    onKNXValueChange(field, oldValue, knxValue) {
        log('INFO: onKNXValueChange(' + field + ", " + oldValue + ", " + knxValue + ")");
        switch (field) {
            case "On":
                this.myAPI.setValue(field, knxValue); // knxValue: values either 0 or 1
                break;
            case "Brightness":
                this.myAPI.setValue(field, knxValue/255*100); // knxValue: values between 0-255
                break;
            case "ColorTemperature":
                let currentwhite_M = this.convertBetweenMiredandAbsolute(knxValue) // knxValue: values between 0-255
                this.myAPI.setValue(field, currentwhite_M);
                break;
        }
    }

    convertBetweenMiredandAbsolute(value) {
        // K=Kelvin, M=Mired
        var warmwhite_K = this.myAPI.getLocalConstant("max_warmwhite");
        var coldwhite_K = this.myAPI.getLocalConstant("max_coldwhite");
        var currentwhite_K = ((value/255)*(coldwhite_K - warmwhite_K)) + warmwhite_K;
        var currentwhite_M = (Math.pow(10, 6) / currentwhite_K)
        return currentwhite_M;
    }

    // onBusValueChange
/* ********************************************************************************************************************** */
    /****
     * onHKValueChange is invoked if HomeKit is changing characteristic values
     *
     */
    onHKValueChange(field, oldValue, newValue) {
        log('INFO: onHKValueChange(' + field + ", " + oldValue + ", " + newValue + ")");
        switch (field) {
            case "On":
                //skip "turn on" knx message if brightness has just been set
                if ((newValue? 1:0) !== (oldValue? 1:0)) {
                    if (newValue !== 1 || !this.brightnessSet) {
                        this.myAPI.knxWrite(field, newValue, "DPT1");
                    }
                }
                break;
            case "Brightness":
                this.myAPI.knxWrite(field, newValue, "DPT5.001");

                // set "brightness has just been set" flag to true for next 2s
                this.brightnessSet = true;
                var that = this;
                if (this.timer) clearTimeout(this.timer);
                this.timer = setTimeout(function () {
                    that.brightnessSet = false;
                    },2000);
                break;
            case "ColorTemperature":
                var absolute = this.convertBetweenAbsoluteAndMired(newValue);
                log('INFO Writing color temperature in absolute value of ' + absolute + ' to KNX bus');
                this.myAPI.knxWrite(field, absolute, "DPT5.001");
                break;
        }
    }

    convertBetweenAbsoluteAndMired(value) {
        // K=Kelvin, PC=Percent
        var warmwhite_K = this.myAPI.getLocalConstant("max_warmwhite");
        var coldwhite_K = this.myAPI.getLocalConstant("max_coldwhite");
        var currentwhite_K = Math.round(Math.pow(10, 6) / value);
        let currentwhite_PC = ((currentwhite_K - warmwhite_K) / (coldwhite_K - warmwhite_K))*100;
        return currentwhite_PC;
    }
// onHKValueChange
} // class

module.exports = CWWW;

/* **********************************************************************************************************************

config.json The config for that should look like this (Reverse keyword is not allowed for custom handlers)

"Services": [
    {
        "DeviceName": "Panel",
        "Services": [
            {
                "ServiceType": "Lightbulb",
                "Handler": "CWWW",
                "ServiceName": "Panel",
                "Characteristics": [
                    {
                        "Type": "On",
                        "Set": [
                            "5/0/23"
                        ],
                        "Listen": [
                            "5/0/24"
                        ],
                        "DPT": "DPT1"
                    },
                    {
                        "Type": "Brightness",
                        "Set": [
                            "5/0/33"
                        ],
                        "Listen": [
                            "5/0/34"
                        ],
                        "DPT": "DPT5.001"
                    },
                    {
                        "Type": "ColorTemperature",
                        "Set": [
                            "5/0/29"
                        ],
                        "Listen": [
                            "5/0/30"
                        ],
                        "DPT": "DPT5.001"
                    }
                ],
                "KNXReadRequests": [
                    "5/0/24",
                    "5/0/30",
                    "5/0/34"

                ],
                "LocalConstants": {
                    "max_warmwhite": 2700,
                    "max_coldwhite": 6500
                }
            }
        ]
    }
]