Jump to content
New translation feature for the Shelly Forum ×

Color mixer with Shelly Plus i4 & Shelly RGBW2


JakubS

Recommended Posts

Hello everyone,

I'm trying to code a color mixer with i4 & RGBW2. When one of the buttons on i4 is pressed, one of the channels on RGBW2 should start to increase it's brightness.

var red = 0;
var blue = 0;
var green = 0;
var input;
 

//code sniphet that check which input is currently pressed

//tried to make a function with input parameters if(e.component === "input:" + input), so I wouldn't have to else if it, but that didn't work. 


  Shelly.addStatusHandler(function(e) {
    if (e.component === "input:0") {
      if (e.delta.state === true) {
        input = 0;
      }
    }
    else if (e.component === "input:1") {
      if (e.delta.state === true) {
        input = 1;
      }
    }
    else if (e.component === "input:2") {
      if (e.delta.state === true) {
        input = 2;
      }
    }
  });

}

 

//this function only adds RGB 0 0 0
function RGBIncrease() {
    Shelly.addStatusHandler(
      function(e) {
        if (e.component === "input:0") {
          if (e.delta.state === true) {
            if(green < 255) {
              green ++;
              }
            } 
          }
        
        else if (e.component === "input:1") {
          if (e.delta.state === true) {
            if(blue < 255) {
              blue ++;
              }
          }
        }
        else if (e.component === "input:2") {
          if (e.delta.state === true) {
            if(red < 255) {
              red ++;
              }
          }
        }
       }
     );
  Shelly.call(
      "HTTP.POST", {
        "url": "http://10.66.0.163/color/0?",
        "body": "turn=on&red="+red+"&blue="+blue+"&green="+green+"&gain=100"
      }
     );
}

Timer.set(
    /* number of miliseconds */ 500,
    /* repeat? */ true,
    /* callback */ RGBIncrease
  );

 

 

The problem is that the script runs for 2 seconds and then I get an error message "Uncaught Error: Too many subscriptions".

My suspisions are that I have somewhere a memory leak or I'm exceeding the device limit and it can't handle it (maybe too many calls). 

Either way any advice helps.

Link to comment
Share on other sites

On 4/30/2024 at 5:12 PM, JakubS said:

Hello everyone,

I'm trying to code a color mixer with i4 & RGBW2. When one of the buttons on i4 is pressed, one of the channels on RGBW2 should start to increase it's brightness.

var red = 0;
var blue = 0;
var green = 0;
var input;
 

//code sniphet that check which input is currently pressed

//tried to make a function with input parameters if(e.component === "input:" + input), so I wouldn't have to else if it, but that didn't work. 


  Shelly.addStatusHandler(function(e) {
    if (e.component === "input:0") {
      if (e.delta.state === true) {
        input = 0;
      }
    }
    else if (e.component === "input:1") {
      if (e.delta.state === true) {
        input = 1;
      }
    }
    else if (e.component === "input:2") {
      if (e.delta.state === true) {
        input = 2;
      }
    }
  });

}

 

//this function only adds RGB 0 0 0
function RGBIncrease() {
    Shelly.addStatusHandler(
      function(e) {
        if (e.component === "input:0") {
          if (e.delta.state === true) {
            if(green < 255) {
              green ++;
              }
            } 
          }
        
        else if (e.component === "input:1") {
          if (e.delta.state === true) {
            if(blue < 255) {
              blue ++;
              }
          }
        }
        else if (e.component === "input:2") {
          if (e.delta.state === true) {
            if(red < 255) {
              red ++;
              }
          }
        }
       }
     );
  Shelly.call(
      "HTTP.POST", {
        "url": "http://10.66.0.163/color/0?",
        "body": "turn=on&red="+red+"&blue="+blue+"&green="+green+"&gain=100"
      }
     );
}

Timer.set(
    /* number of miliseconds */ 500,
    /* repeat? */ true,
    /* callback */ RGBIncrease
  );

 

 

The problem is that the script runs for 2 seconds and then I get an error message "Uncaught Error: Too many subscriptions".

My suspisions are that I have somewhere a memory leak or I'm exceeding the device limit and it can't handle it (maybe too many calls). 

Either way any advice helps.

@Kristian Todorov can you help there ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...