I found a solution in this topic :Push button ( physical and virtual )
my sketch now .
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid = “xxxxxxxxxx”;
char wifiPassword = “xxxxx”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxxxxxxxx”;
char password = “xxxxxxxxxxxxxxxxx”;
char clientID = “xxxxxxxxxxxxxx”;
// Sound Pin
int soundPin = 3;
// Relay Pin
int relayPin = 2;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(relayPin, OUTPUT); // Relay
digitalWrite(relayPin, LOW);
pinMode(soundPin, INPUT); // Sound
}
void loop() {
Cayenne.loop();
}
CAYENNE_IN(2) {
if (getValue.asInt() == 1) { // NOTE: Channel = Virtual Pin
digitalWrite(relayPin, HIGH);
delay (1000);
digitalWrite(relayPin, LOW);
}
//else {
//digitalWrite(relayPin, LOW);
//}
else {
digitalWrite(relayPin, HIGH);
delay(1500);
digitalWrite(relayPin, LOW);
}
}
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
}