IFTTT going away, need some pointers

This is pretty much what I want to do as well, however no idea how to get a permanent Particle API access token?

You can create a non-expiring token using the Particle CLI:

particle token create --never-expires

Or from your browser:

https://docs.particle.io/reference/cloud-apis/access-tokens/#create-a-token-browser-based-

1 Like

Thanks, that worked, however another issue. I’ve gone through the thread of this post and here… IFTTT | Getting Started | Particle on how to Call a function, but not too sure why I’m getting this error (see attached photo)

What do you have in the Body box of your Web Request configuration?

Even if your function does not require arguments you should specify an empty argument:

{"arg":""}

Hi, I have this…

You have square brackets [] in the Body field; they must be curly brackets {}.

2 Likes

Na, still failing. So to be clear, the action I want to send to my 4-channel relay Particle board is “3on” which I have at the end of the url field i.e. https://api.particle.io/v1/devices/<redacted>/3on
and also have it in the Body field as seen in previous screenshot. I have also tried the {“arg”:“”} which also failed a 404 error.

Can you show your code?
Are you really exposing a function 3on by calling Particle.function("3on", someFn); in your setup()?

Does that mean that you have eight distinct functions 1on, 1off, … 4on and 4off?

If I wanted to control four relays via a Particle.function() I’d have a single function (e.g. setRelay) and then control which relay and what state in the parameter/argument sent to that function (e.g. 1:0 = 1off, 3:1 = 3on).

Hi, all I’m trying to do is mirror what I had setup using IFTTT directly - see example below which is the “then that” portion following a day/time “if this” command. I have a few more commands than the 8 (off/on etc.)

Probably your URL should be:
https://api.particle.io/v1/devices/123456789987654332189/controlRelay

And then the body box probably can be

{"arg":"3on"}

But that’s just my guessing
Will be much earlier, as @ScruffR mentioned, if you could show us your code especially the setup()
Part.

But for sure it’s no good to expose device id

Best

1 Like

Are you meaning the code for the particular Particle relay board? If so, is this what you are after?..

// **********************************************************************


/* This function is called once at start up ----------------------------------*/
void setup()
{
    Particle.function("controlRelay", triggerRelay);
    Serial.begin(115200);
    relayController.setAddress(0,0,0);
}

/* This function loops forever --------------------------------------------*/
void loop()
{
    int status = relayController.readAllInputs();
    int a = 0;
    for(int i = 1; i < 9; i*=2){
        if(status & i){
            debugTrips[a]++;
            if(debugTrips[a] >= minTrips){
                if(!tripped[a]){
                    tripped[a] = true;
                    //set input trip event to true
                    String eventName = "Input_";
                    eventName+=(a+1);
                    Particle.publish(eventName, "ON");
                    Serial.print("eventName: ");
                    Serial.println(eventName);
                    Serial.print("eventContents: ");
                    Serial.println("ON");
                }
            }
        }else{
            debugTrips[a] = 0;
            if(tripped[a]){
                tripped[a] = false;
                //set input trip event to false
                String eventName = "Input_";
                eventName+=(a+1);
                Particle.publish(eventName, "OFF");
                Serial.print("eventName: ");
                Serial.println(eventName);
                Serial.print("eventContents: ");
                Serial.println("OFF");
            }
        }
        a++;
    }
}

int triggerRelay(String command){
    if(command.equalsIgnoreCase("turnonallrelays")){
        relayController.turnOnAllRelays();
        return 1;
    }
    if(command.equalsIgnoreCase("turnoffallrelays")){
        relayController.turnOffAllRelays();
        return 1;
    }
    if(command.startsWith("setBankStatus:")){
        int status = command.substring(14).toInt();
        if(status < 0 || status > 255){
            return 0;
        }
        Serial.print("Setting bank status to: ");
        Serial.println(status);
        relayController.setBankStatus(status);
        Serial.println("done");
        return 1;
    }
    //Relay Specific Command
    int relayNumber = command.substring(0,1).toInt();
    Serial.print("relayNumber: ");
    Serial.println(relayNumber);
    String relayCommand = command.substring(1);
    Serial.print("relayCommand:");
    Serial.print(relayCommand);
    Serial.println(".");
    if(relayCommand.equalsIgnoreCase("on")){
        Serial.println("Turning on relay");
        relayController.turnOnRelay(relayNumber);
        Serial.println("returning");
        return 1;
    }
    if(relayCommand.equalsIgnoreCase("off")){
        relayController.turnOffRelay(relayNumber);
        return 1;
        
    }
    if(relayCommand.equalsIgnoreCase("ton")){
        Serial.println("Turning on relay");
        relayController.turnOnRelay(relayNumber);

// this is where you'd add your relayTimer[relayNumber].start();
        
        relayTimer[1]->start();

        Serial.println("returning");
        return 1;
    }
    if(relayCommand.equalsIgnoreCase("timeron")){
        Serial.println("Turning on relay");
        relayController.turnOnRelay(relayNumber);

        relayTimer[1]->changePeriod(ToMilliseconds(9));      
        relayTimer[1]->start();

        Serial.println("returning");
        return 1;
        
        
    }
    if(relayCommand.equalsIgnoreCase("t3on")){
        Serial.println("Turning on relay");
        relayController.turnOnRelay(relayNumber);
        
        relayTimer[3]->start();

        Serial.println("returning");
        return 1;
        
    }
    if(relayCommand.equalsIgnoreCase("off")){
        relayController.turnOffRelay(relayNumber);
        return 1;
    }
    if(relayCommand.equalsIgnoreCase("toggle")){
        relayController.toggleRelay(relayNumber);
        return 1;

    }
    if(relayCommand.equalsIgnoreCase("momentary")){
        relayController.turnOnRelay(relayNumber);
        delay(300);
        relayController.turnOffRelay(relayNumber);
        return 1;
    }
   //Both lights On
    // always call this message with 1son or 2son never as just son
    if(relayCommand.equalsIgnoreCase("son")){
        // tripTime = millis();
        // checkTripTimer = true;
        relayController.turnOnRelay(2);
        relayController.turnOnRelay(4);
        return 1;
    }
    
    // Both lights Off
   if(relayCommand.equalsIgnoreCase("soff")){
       // checkTripTimer = false;
        relayController.turnOffRelay(2);
        relayController.turnOffRelay(4);
        return 1;

    }
    return 0;
}

Exactly as I guessed and indicated with this question

Obviously you are not and hence I feel backed up by and agree with @dreamER's clarification

Then you'll pass the respective "action command" for that function into the {"arg": "command"} parameter as pointed out by Rick.


I'm always amazed to see people answering unasked questions but fail to address the questions that are :wink:

Sorry, I don’t quite understand, being a non-programmer myself. When you say "are you exposing a function 3on by calling Particle… well yes I am trying to i.e. trying to mirror what I had programmed in the IFTTT applet but getting confused with what to enter in the Webhooks parameters, including device ID and access token etc. How am I supposed to send an input command of “3on” to my particle-1 board as this is the command it requires to turn relay #3 on?

FYI I’ve tried putting url as https://api.particle.io/v1/devices/123456789987654332189/controlRelay
and Body as {“arg”:“3on”}, but I still get a
[Action failure message: Your server returned a 400. Unable to make web request to https://api.particle.io/v1/devices…] error

You may want to test the function via console.particle.io before moving on to IFTTT.
Only after you established that the function is accessible on the device with that device ID there is any point to move on. Otherwise you’d need to find out why you cannot reach that device.

I’m not convinced 123456789... is your device ID and hence the URL (with an invalid device ID) would have to cause a HTTP 400 (bad request).

(since it’s good practice to not disclose your device ID we were not sure whether this is the actual URL or just a “redacted” substitute)

Hi ScruffR - that device ID is fake as you suggested I don’t expose it on this forum. If I simply enter
https://api.particle.io/v1/devices/4b***************3433/?access_token=6b******************************1215fd
into a webpage I receive the below which shows that I’m connecting to the board… (edited)

{"id":"4b*****************3433",
"name":"Particle-1",
"last_ip_address":"58.xx.xx.xx",
"last_heard":"2022-08-17T22:02:29.049Z",
"last_handshake_at":"2022-08-17T10:32:31.430Z",
"product_id":2583,
"online":true,
"connected":true,
"platform_id":6,
"cellular":false,
"notes":null,
"firmware_updates_enabled":true,
"firmware_updates_forced":false,
"functions":["controlRelay"],
"variables":{},
"status":"normal",
"serial_number":"PH-160918-A9QP0",
"system_firmware_version":"2.2.0",
"current_build_target":"2.2.0",
"default_build_target":"2.3.0",
"firmware_product_id":6,
"groups":[],
"firmware_version":65535,
"desired_firmware_version":null,
"targeted_firmware_release_version":null,
"development":false,
"quarantined":false,
"denied":false,
"owner":"xxxxxxxx@gmail.com"
}

Not sure how to “drive” console.particle.io so don’t know how to test the function. I can just access and read only :slight_smile:

If you give it a try you’ll find Particle Console is pretty self-explanatory :wink:

When you just go there, log in (if you aren’t already) and find yourself on the devices page.
There you find and click your desired device to go to the page for that device.
There you should find a section ‘FUNCTIONS’ with an entry for your controlRelay.
In the respective input box, you enter your command (e.g. 3on) and hit CALL.

image

However, looking at the device descriptor you posted above, it appears that device is part of a PRODUCT and for that I’m not sure whether the bearer access on IFTTT works the same way as for sandbox devices. Maybe @rickkas7 can chime in on that.

Thanks for the explanation on using Particle Console. I tried that and received a “controlRelay = 1” - I take it that is a positive result??

1 Like

Hi All, I’m still stuck in the same place i.e. recieving an error “Action failure message: Your server returned a 404. Unable to make web request to https://api.particle.io/v1/devices/123456789xxxxxxx/controlRelay” when trying different parameters in the webhooks fields. As per above I can successfully call function “3on” via Particle Console so this argument / input definitely works. Can someone perhaps help me populate all the webhooks fields correctly please?

Right. The Particle Cloud docs suggest that putting the token in the URL is a bad idea since I assume these go out in the clear. The Additional Headers format with the Authorization: Bearer XXXX form works. Either way, the token appears in the IFTTT logs for the “applet”.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.