Digital Motion Sensor Not responding after MQTT Switch

can you share the code you are using and also the screenshot of the triggers.

The code is the same as listed above in this topic for the sensor box.

/*
This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  2. Compile and upload the sketch.
  3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
    */

//#define CAYENNE_DEBUG // Uncomment to show debug messages
//#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “XXX”;
char password = “XXX”;
char clientID = “XXX”;

#define LUXSENSOR_PIN 0
#define TEMPSENSOR_PIN 7
#define MOTIONSENSOR_PIN 2
#define WHITELIGHT_PIN 3
#define GREENLIGHT_PIN 6
#define YELLOWLIGHT_PIN 5
#define REDLIGHT_PIN 4
#define VIRTUAL_CHANNEL1 1
#define VIRTUAL_CHANNEL2 2
#define VIRTUAL_CHANNEL3 3
#define VIRTUAL_CHANNEL4 4
#define VIRTUAL_CHANNEL5 5
#define VIRTUAL_CHANNEL6 6
#define VIRTUAL_CHANNEL7 7

OneWire oneWire(TEMPSENSOR_PIN);
DallasTemperature sensors(&oneWire);

void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
sensors.begin();
pinMode(WHITELIGHT_PIN, OUTPUT);
pinMode(GREENLIGHT_PIN, OUTPUT);
pinMode(YELLOWLIGHT_PIN, OUTPUT);
pinMode(REDLIGHT_PIN, OUTPUT);
}

void loop()
{
Cayenne.loop();
checkSensor();
}

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(MOTIONSENSOR_PIN);
Serial.println(currentState);
if (currentState != previousState) {
Cayenne.virtualWrite(VIRTUAL_CHANNEL3, currentState, “digital_sensor”, “d”);
previousState = currentState;
}
previousMillis = currentMillis;
}
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL1, analogRead(LUXSENSOR_PIN));
}

// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
// Send the command to get temperatures.
sensors.requestTemperatures();
// This command writes the temperature in Celsius to the Virtual Channel.
// Cayenne.celsiusWrite(VIRTUAL_CHANNEL, sensors.getTempCByIndex(0));
// To send the temperature in Fahrenheit use the corresponding code below.
Cayenne.fahrenheitWrite(VIRTUAL_CHANNEL2, sensors.getTempFByIndex(0));
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL4)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL4, WHITELIGHT_PIN, value);
// Write the value received to the digital pin.
digitalWrite(WHITELIGHT_PIN, value);
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL5)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL5, GREENLIGHT_PIN, value);
// Write the value received to the digital pin.
digitalWrite(GREENLIGHT_PIN, value);
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL6)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL6, YELLOWLIGHT_PIN, value);
// Write the value received to the digital pin.
digitalWrite(YELLOWLIGHT_PIN, value);
}

// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL7)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL7, REDLIGHT_PIN, value);
// Write the value received to the digital pin.
digitalWrite(REDLIGHT_PIN, value);
}

can you PM me your account email_id

you are using trigger to turn ON/OFF lights on same device which is reading temperature value? if so, you can code to do this.

Yes, it is the same device.

then use a if condition to turn ON/OFF lights.

I believe that is what I am using with the triggers.

you are using cayenne trigger, do not use them.
in your code add them directly.

Then the lights on / off will not show on the dashboard. I can do that but it does not seem to be consistent with using Cayenne to set it up. I assume that means the triggers will not work properly for this purpose.

Before the upgrade to the MQTT system these were working great.

you are having multiple trigger for single temperature sensor widget.
eg: trigger Below 80 Red Light Off and Above 77 Yellow Light On both will true when temperature data is 78. So what do you think this will do?
it will work but if you are having both actuator and sensor on same device, then why are you using cayenne trigger.

These devices are in remote locations. It is just a visual on the dashboard to see what is showing on the site.

A simple if condition like:

int x = sensors.getTempFByIndex(0) ;
if ((x > 70) && (x < 80) )
{
  digitalWrite(WHITELIGHT_PIN, HIGH);
 digitalWrite(YELLOWLIGHT_PIN, LOW);
}

Similarly do for other.

Thank you for your time. I will rework my code.