Particle Variables & IFTTT

I have a HTU21D-F temperature and humidity sensor and IR breakbeam sensor. I am able to send the temperature and humidity values to the Particle Cloud and visualize them in the Dashboard. If the IR beam is broken I made a recipe to receive a notification through IFTTT. Is there any way I can include the readings of the temperature and humidity in the IFTTT notification?

I am not sure if I can achieve the above with IFTTT. Is there any other route I can take to have only one notification including the IR status and environmental conditions?

Any suggestion is greatly appreciated!

You can combine the readings on the device and publish that as one event?

Hello @Moors7,

I am not quite sure how to combine the readings in one event. What should I use as is(Event Contents) in the Trigger Field of IFTTT?

For more clarity here is the code:

#include "HTU21D/HTU21D.h"

HTU21D htu = HTU21D();

const int irSensor = D3;  //IR Sensor 
const int ledPin = D6;      //For debug.
double tempVal, humidVal;

void setup() {
    Serial.println("HTU21D test");
    if (!htu.begin()){
        Serial.println("Couldn't find sensor!");

	pinMode(irSensor, INPUT);
	pinMode(ledPin, OUTPUT);
	digitalWrite(irSensor, HIGH);	//Turn on the pullup resistor for IR Sensor 
	digitalWrite(ledPin, LOW);
	Particle.variable("tempValue", tempVal);
	Particle.variable("humidValue", humidVal);


void loop() {
    Serial.print("Temp: "); Serial.print(htu.readTemperature()); Serial.print(" C");        //Debug
    Serial.print("\t\tHUM: "); Serial.print(htu.readHumidity()); Serial.println(" %");      //Debug
    tempVal = htu.readTemperature();
    humidVal = htu.readHumidity();
    static int Case = 0;
    if(IR_Sensor() == false && Case !=1){
        Case = 1;
        digitalWrite(ledPin, HIGH);     //Debug
        Particle.publish("TEST", "IR Beam Broken. \nTemperature: "+String(tempVal)+"C. \nHumidity: "+String(humidVal)+"%.", PRIVATE);  //<------ NOT SURE HOW TO PUBLISH THIS AS ONE EVENTE


bool IR_Sensor(){

	int sensorState = 0;		//For IR Sensor 
	int sensorLastState = 0;	//For IR Sensor 
	sensorState = digitalRead(irSensor);	//Read the state of IR Sensor 
	if(sensorState && !sensorLastState){
		return true;
	if(!sensorState && sensorLastState){
		return false;
	sensorLastState = sensorState;

In the Particle.publish function what string data should I use to have only one event? I am confused with the use of the variables…

You’ll have to concatenate several strings together to publish all the data in one publish event. The String class is really adaptable and makes concatenating as easy as this…
String 3 = String 1 + String 2;
You would make String 1 = temperature data.
Make String 2 = humidity data.
Then concatenate them together into String 3.
Then just publish the concatenated string in the publish event in the data field.
The firmware docs for the String class can spell out any details you might want.

1 Like

While String can be used, a nicer (better?) way to build a string containing multiple values would be sprintf()/snprintf() or if it has to be a String object and you don’t care about heap fragmentation, you can use String::format() which also provides printf() formatting.

The String::format works just fine! What is the formatting of the % symbol? I. e. 50 % in my notification I’m not getting the %. I tried % but it does not work. Thank you.

That would be “%%”

For a comprehensive overview of formatting codes look here

That’s what I was looking for! :smile:
Thank you very much!