Enocean Switch Dimming

I use it with a Tasmota Light but with a bit of code changeing you can use it with everything u need

More infos for Enocean
Enocean Gateway on Github

// Update the timers to the context store
let timers = context.get('timers') || {};
let intervals = context.get('intervals') || {};
let buttons = context.get('buttons') || {};
let light = flow.get('Licht') || {};


let status = msg.payload.telegram.zustand;
let button = msg.payload.telegram.schalter;

dim_speed=250; // dimmgeschwindikeit 1-1000(1000 = 1s)
color_speed=500;//

if (button === "A0" || button === "B0"  ){
	UP(button, status, dim_speed, color_speed);    
    }
else if (button === "AI" || button === "BI"  ){ 
    DOWN(button, status, dim_speed, color_speed);         
	}
else {

    }

    
// ****** Output Button A0 or B0 ****** \\
function UP(button, status, dim_speed, color_speed){
    if (status === "pressed" ){
        timers[button] = setTimeout(dimmerup, 1000);
        
        context.set('timers',timers);
        
        buttons[button] = false;
        context.set('buttons', buttons);
    }else if (status === "released"){
        if ( timers[button] ) {
            clearTimeout(timers[button])
            delete timers[button]
            if ( intervals[button] ) {
                clearInterval(intervals[button]);
                delete intervals[button];  
            }
            if (buttons[button] === false ){
                flow.set("prio",10);
                node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/POWER1", payload:true});
            }
        }
    }

    function dimmerup() {
        if(light === true){
            buttons[button] = true;
            context.set('buttons', buttons);
            counter_A0 = flow.get("dim");
            counter_B0 = flow.get("color");
            flow.set("prio",100);
            if (button === "A0") {
                intervals[button] = setInterval(function(){
                counter_A0 +=10;
                    if (counter_A0 > 100) {
                        clearInterval(intervals[button]);
                        delete intervals[button];   
                    }else{
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/Dimmer",payload: counter_A0},false); 
                    }
                }, dim_speed);
                context.set('intervals',intervals);
            }
            if (button === "B0") {
                intervals[button] = setInterval(function(){
                    counter_B0 += 36;
                    if (counter_B0 > 500) {
                        clearInterval(intervals[button]);
                        delete intervals[button];
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/CT",payload: 500},false); 
                    }else{
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/CT",payload: counter_B0},false); 
                    }
                }, color_speed);
                context.set('intervals',intervals);
            }
        }else{
            return;
        }
    }
}



// ****** Output Button AI or BI ****** \\
function DOWN(button, status, dim_speed, color_speed){
    if (status === "pressed" ){
        timers[button] = setTimeout(dimmerdown, 1000);
        
        context.set('timers',timers);
        
        buttons[button] = false;
        context.set('buttons', buttons);
    }else if (status === "released"){
        if ( timers[button] ) {
            clearTimeout(timers[button])
            delete timers[button]
            if ( intervals[button] ) {
                clearInterval(intervals[button]);
                delete intervals[button];  
            }
            if (buttons[button] === false ){
                flow.set("prio",10);
                node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/POWER1", payload:false});
            }
        }
    }

    function dimmerdown() {
        if(light === true){
            buttons[button] = true;
            context.set('buttons', buttons);
            counter_AI = flow.get("dim");
            counter_BI = flow.get("color");
            flow.set("prio",100);
            if (button === "AI") {
                intervals[button] = setInterval(function(){
                counter_AI -=10;
                    if (counter_AI < 10) {
                        clearInterval(intervals[button]);
                        delete intervals[button];   
                    }else{
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/Dimmer",payload: counter_AI},false); 
                    }
                }, dim_speed);
                context.set('intervals',intervals);
            }
            if (button === "BI") {
                intervals[button] = setInterval(function(){
                    counter_BI -= 36;
                    if (counter_BI < 153) {
                        clearInterval(intervals[button]);
                        delete intervals[button]; 
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/CT",payload: 153},false); 
                    }else{
                        node.send({topic:"Küche/Licht/cmnd/Panel_Kueche/CT",payload: counter_BI},false); 
                    }
                }, color_speed);
                context.set('intervals',intervals);
            }
        }else{
            return;
        }
    }
}

return;

This topic was automatically closed after 60 days. New replies are no longer allowed.