Pir sensor to turn on lights

Hello.I m trying a project that if the pir sensor anticipates movement AND I’m not home AND it’s after 18.00 it will turn on my lights.
The part of combining conditions will be achieved with ifttt and apilio.
My problem is that I created with cayenne this pir sensor code that will trigger a boolean on the apilio and it isn’t working.it never triggers.my pir sensor responds correctly.any ideas what might happen?maybe because it’s on digital output?

is your trigger counter incrementing? how have you setup the trigger?

I have set up the trigger but no,it isn’t adding up.

can you share a screenshot of your trigger and the PIR code(if it is a arduino device).

happy to do it!!wait a second please!

my trigger

 #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

#define SENSOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

void setup()
	Cayenne.begin(username, password, clientID);

void loop()

int previousState = -1;
int currentState = -1;
unsigned long previousMillis = 0;

void checkSensor()
	unsigned long currentMillis = millis();
	// Check sensor data every 250 milliseconds
	if (currentMillis - previousMillis >= 250) {
		// Check the sensor state and send data when it changes.
		currentState = digitalRead(SENSOR_PIN);
		if (currentState != previousState) {
			Cayenne.virtualWrite(VIRTUAL_CHANNEL, currentState, "digital_sensor", "d");
			previousState = currentState;
		previousMillis = currentMillis;

are you trying to add trigger to motion sensor or digital output?

I was sending you my other trigger that actually triggers the output.(which works great!)

i see you have two widgets on the same channel. Delete both of them, and when the PIR detect motion it will auto produce a green temporary green widget on the dashboard. Add it on your dashboard by clicking on +. then add a new trigger for this widget.

that solved the problem!!!thanks so so much!!
also I need a help on my logic if you can.
I ve created the motion sensor trigger.Now I have to make the ifttt check if I m out of an area(easy)
BUT to do it in specific hours.)lets say after 18.00.
My last problem is how to ask cayenne even make the trigger we created false on a specific hour OR check only during night.any ideas??

1 Like

you can use scheduler (event) to set the time to ON a button on the cayenne dashboard and read it in the code and use it for further.

I ll check it and get back!!!thanks again!!

in short this:

int x;
  x = getValue.asInt();
void loop()
        if (x == 1)

add a schedule to a button(channel 2) on the cayenne dashboard.