# Enocean Switch Dimming

**URL:** <https://discourse.nodered.org/t/enocean-switch-dimming/28315>\
**Category:** Share Your Projects\
**Created:** [14 June 2020 14:03 UTC](https://discourse.nodered.org/t/enocean-switch-dimming/28315 "2020-06-14T14:03:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Techserv-krY](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/techserv-kry/32/8255_2.png) [@Techserv-krY](https://discourse.nodered.org/u/Techserv-krY)\
**Post date:** [14 June 2020 14:03 UTC](https://discourse.nodered.org/t/enocean-switch-dimming/28315/1 "2020-06-14T14:03:42Z")

</div>

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](https://github.com/Techserv-krY/EnOcean_ESP8266_Gateway)

```auto
// 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;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 August 2020 14:04 UTC](https://discourse.nodered.org/t/enocean-switch-dimming/28315/2 "2020-08-13T14:04:02Z")

</div>

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