Jump to content
Gen2 Devices: FW Update Required / Gen2 Geräte: FW-Update erforderlich ×

i4 + rgbw2 in white mode script crash


Recommended Posts

Hi People, I would like to ask your help.

I have two shelly rgbw2-s in white mode (4 channel white) and a shelly i4 and have been trying to remote control the rgbw2 group from the i4 without luck.
What I try to do is to remote turn on/off 3 channels out of 4 and do other functions as well like dimming, but I have a problem I can't figure out.
Here is the script, the original I found online and rewritten a little:
/**
 * @copyright shelly-tools contributors
 * @license   GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0.de.html)
 *
 * This script is intended to control a Shelly RGBW2 with a single button from
 * a Shelly Plus device. Every time the button from the Plus device is pushed it jumps to the next step 
 * defined in the sequence array. 
 */
 
// CONFIG START
// IP address or hostname(s) from RGBW2 device(s)
let REMOTE = {
    group: ["192.168.0.220","192.168.0.208"],
    channel: ["0","1","2"],
    input: 2, // ID from the push button: 0 for Shelly Plus 1 / Plus 1 PM or 0,1,2 or 3 for the Shelly i4.
};

// Dimming level 
let dimsequence = [
   '?brightness=65', // 65%
   '?brightness=33', // 33%
   '?brightness=11', // 11%
   '?brightness=2', // 2%
   '?brightness=100', // 100%
];
// CONFIG END 

// no need to change anything below this line..
let dimpos = 0;

// add an evenHandler for button type input and various push events
Shelly.addEventHandler(
    function (event, user_data) {
        //print(JSON.stringify(event));
        if (typeof event.info.event !== 'undefined') {
           
            if (event.info.event === 'double_push' && event.info.id === REMOTE.input) {
                for (let i=0; i<REMOTE.group.length; i++) {
                  for (let j=0; j<REMOTE.channel.length; j++) {
                    setRGBW(REMOTE.group[i], REMOTE.channel[j]);
                  }
                }
                dimpos = 0;

           } else if (event.info.event === 'single_push' && event.info.id === REMOTE.input) {
                for (let i=0; i<REMOTE.group.length; i++) {
                  for (let j=0; j<REMOTE.channel.length; j++) {
                    toggleRGBW(REMOTE.group[i], REMOTE.channel[j]);
                  }
                }

           } else if (event.info.event === 'long_push' && event.info.id === REMOTE.input) {
                for (let i=0; i<REMOTE.group.length; i++) {
                  for (let j=0; j<REMOTE.channel.length; j++) {
                    dimRGBW(REMOTE.group[i], REMOTE.channel[j], dimpos);
                  }
               }
               dimpos++;
               if (dimsequence.length === dimpos) {
                 dimpos = 0;
               }

           } else {
             return true;
           }
        } else {
            return true;
        }
    },
);

// send RBGW on command 
function setRGBW(group, channel) {
    Shelly.call(
        "http.get", {
            url: 'http://' + group + '/white/' + channel + '?turn=on&brightness=100'
        },
        function (response, error_code, error_message, ud) {
        },
        null
    );
};

 // send RBGW dimming command 
 function dimRGBW(group, channel, dimpos) {
   Shelly.call(
       "http.get", {
           url: 'http://' + group + '/white/' + channel + dimsequence[dimpos]
       },
       function (response, error_code, error_message, ud) {
           print(dimsequence[dimpos]);
       },
       null
   );
};

 // send RGBW toggle command
function toggleRGBW(group, channel) {
   Shelly.call(
       "http.get", {
           url: 'http://' + group + '/white/' + channel + '?turn=toggle'
       },
       function (response, error_code, error_message, ud) {
       },
       null
   );
}

If I only control 2 channels out of 3 on both of my shelly devices or I control only 1 shelly device and 3 channel on it, works fine, does what I ask from the rgbw2 controller.

If I want to control 3 or 4 channels on both of my shelly bgbw devices, my script crashes with the following error:

shelly_notification:209 Event from input:2: {"component":"input:2","id":2,"event":"btn_down","ts":1714545421.30} 08:37:01
shelly_notification:209 Event from input:2: {"component":"input:2","id":2,"event":"btn_up","ts":1714545421.53} 08:37:01
in function called from system 08:37:02
shelly_user_script.:388 error: Error in EjsCall 08:37:02
shelly_notification:209 Event from input:2: {"component":"input:2","id":2,"event":"single_push","ts":1714545421.80} 08:37:02
shos_rpc_inst.c:230 http.get via loopback 08:37:02
shelly_http_client.:306 0x3ffde5cc: HTTP GET http://192.168.0.208/white/0?turn=toggle 08:37:02
shos_rpc_inst.c:230 http.get via loopback 08:37:02
shelly_http_client.:306 0x3ffe1df0: HTTP GET http://192.168.0.208/white/1?turn=toggle 08:37:02
shelly_notification:163 Status change of script:2: {"id":2,"errors":["error"],"running":false} 08:37:02
shos_rpc_inst.c:230 http.get via loopback 08:37:02
shelly_http_client.:306 0x3ffe2220: HTTP GET http://192.168.0.208/white/2?turn=toggle 08:37:02
shos_rpc_inst.c:230 http.get via loopback 08:37:02
shelly_http_client.:306 0x3ffe3058: HTTP GET http://192.168.0.220/white/0?turn=toggle 08:37:02
shos_rpc_inst.c:230 http.get via loopback 08:37:02
shelly_http_client.:306 0x3ffe32ac: HTTP GET http://192.168.0.220/white/1?turn=toggle 08:37:02 shelly_http_client.:606 0x3ffe2220: Finished; bytes 295, code 200, redir 0/3, auth 0, status OK 08:37:02 shelly_ejs_rpc.cpp:77 No call record for 130 08:37:02 shelly_http_client.:606 0x3ffe32ac: Finished; bytes 295, code 200, redir 0/3, auth 0, status OK 08:37:02 shelly_ejs_rpc.cpp:77 No call record for 132 08:37:02 shelly_http_client.:606 0x3ffe3058: Finished; bytes 295, code 200, redir 0/3, auth 0, status OK 08:37:04 shelly_ejs_rpc.cpp:77 No call record for 131 08:37:04 shelly_http_client.:606 0x3ffe1df0: Finished; bytes 295, code 200, redir 0/3, auth 0, status OK 08:37:04 shelly_http_client.:606 0x3ffde5cc: Finished; bytes 295, code 200, redir 0/3, auth 0, status OK 08:37:04 shelly_ejs_rpc.cpp:77 No call record for 129 08:37:04 shelly_ejs_rpc.cpp:77 No call record for 128 08:37:04 

As you see, the script fails to execute http://192.168.0.220/white/2?turn=toggle  and just fails and exits instead.

I really can't figure what I'm doing wrong or how I should do it better to stop the script crashing on the i4 and control that last channel on the rgbw2.

Anyone could give me any clue? Many thanks!

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.

×
×
  • Erstelle neue...