Push Button Independent

Hello everyone.

I have an Arduino connected to Cayenne platform.
Is working well , I can control the lamps in my house perfectly.

I would like to add a physical switch for lamps , working independently .

I’m having trouble writing the code , could someone help me?

Thank you in advance to all of this community.

My push button

My Code

_include "CayenneDefines.h"_
_include "BlynkSimpleEsp8266.h"_
_include "CayenneWiFiClient.h"_

include <Wire.h>

int LAMP = D2;

char token = “token”;
char ssid = “ssid”;
char password = “pass”;

void setup()
pinMode(LAMP, OUTPUT);
Cayenne.begin(token, ssid, password);

int currentValue = getValue.asInt(); // 0 to 1
if (currentValue == 0) {
digitalWrite(LAMP, HIGH);
} else {
digitalWrite(LAMP, LOW);

void loop()

I need use only phisical switch for one lamp.

Is this button a manual over ride (like a regular light switch on your wall) or a button connected to the Arduino?

I think, using software-
“XOR” 2 values,
make the Arduino integrated into the actual lamp,
rewire the existing lamp switch, make it a GPIO input.
use a Cayenne connected relay to switch lamp power,
and you will have a boolean exclusive OR.
XOR the existing physical lamp switch
with an existing Cayenne widget toggle.