fruggy83 / openocean

27 stars 11 forks source link

Add EEP A5-30-03 (Eltako FHMB and FRWB) #90

Closed benderl closed 4 years ago

benderl commented 4 years ago

I recently got some other devices, I would like to use with openhab. They use EEP A5-30-03 which is more a general profile for digital inputs but eltako makes use of this for heat and smoke detectors.

I managed to get it running with a general thing and the following JS transformation:

// Wrap everything in a function (no global variable pollution)
// variable "input" contains data passed by openHAB
( function( inputData ) {
    // simple implementation for EEP A5-30-03 (read only)
    // ORG = 0x07
    // Data_byte3 = 0x00
    // Data_byte2 = temperature 0..40°C
    //              linear 0xFF..0x00
    // Data_byte1 = 0x0F = alarm
    //              0x1F = no alarm
    // Data_byte0 = 0x08
    // Teach-in telegram: 0xC0182D08

    //var logger = Java.type("org.slf4j.LoggerFactory").getLogger("JS-EEP_A5-30-03");
    //logger.warn("Input: '" + inputData + "'");
    var channelType = inputData.split("|",2)[0];
    var rawValue = inputData.split("|",2)[1];

    // get alarm state
    var rawAlarm = rawValue.substring(4,6);
    var alarm = "OFF";
    if(rawAlarm == "0F")
        alarm="ON";

    // get temperature
    var rawTemperature = parseInt(rawValue.substring(2,4),16);
    var MAX_INPUT = 255; // 0xff
    var MIN_INPUT = 0; // 0x00
    var MAX_TEMPERATURE = 0; // 0xff = 0
    var MIN_TEMPERATURE = 40; // 0x00 = 40
    var SCALE_FACTOR = (MAX_TEMPERATURE - MIN_TEMPERATURE) / (MAX_INPUT - MIN_INPUT);
    var temperature = Math.round( ( MIN_TEMPERATURE + ( rawTemperature - MIN_INPUT ) * SCALE_FACTOR ) * 2 ) / 2;
    //logger.warn("channelType: '" + channelType + "' rawValue: '" + rawValue + "' Alarm: '" + alarm + "' Temperature: '" + temperature + "'");

    // return value depends on channelType
    switch (channelType) {
        case "genericSwitch":
            return "OnOffType|"+alarm;
        case "genericNumber":
            return "DecimalType|"+temperature;
        default:
            // for debugging
            return "StringType|"+rawValue;
    }
})( input )
benderl commented 4 years ago

Just one modification to my script: As 40°C divided in 255 steps results in an accurancy of 0,16 degrees, I changed the rounding of the temperature to 0,2 degrees:

var temperature = Math.round( ( MIN_TEMPERATURE + ( rawTemperature - MIN_INPUT ) * SCALE_FACTOR ) * 5 ) / 5;
fruggy83 commented 4 years ago

Hi @benderl thanks a lot for your work. I have added this EEP to the smoke detector PR in the official binding.

benderl commented 4 years ago

Hello @fruggy83 , I maybe noticed a bug regarding the genericThing of the binding. If I add a smoke detector with the device discovery in paper ui, I get a generic thing in my inbox, can configure it, link items to the channels and everything is running fine. But if openhab get restarted, the thing remains in the state "UNINITIALIZED - HANDLER_CONFIGURATION_PENDING". The log does not show anything else regarding the thing or any other enocean related errors. I tested with the latest 2.5.2-alpha release after I found this with 2.5.1.0. Log is set to trace.

benderl commented 4 years ago

Implemented in upstream.