Particle.Function () losing its value

Yes, you did.
You still have lastState as local variable and you need one instance of a lastState variable per state you want to keep track of (aka per sensor).

Your doorvalue() is missing a return value for the case you submit an unsupported command.

And I will repeat what I keep saying to others too:
When you have code blocks that do the absolutely same thing but only differ in variable names, then you should use arrays, loops and possibly enums to reduce code by reusing the active part of the code and just substitute the variables.

Potential candidates for that kind of cleanup:

 pinMode(BackDoor,INPUT);
 pinMode(Front,INPUT);
 pinMode(Garage,INPUT);
 pinMode(Basement,INPUT);
 pinMode(Bedroom,INPUT);
 // and
 BedValue = analogRead(Bedroom);
 BaseValue = analogRead(Basement);  
 GValue = analogRead(Garage);  
 BDvalue = analogRead(BackDoor);  
 FDvalue = analogRead(Front);  
 // and multiple instances of this block
 if (BaseValue < 3000 && lastState != true && armedcommand==1) {
    lastState = true;
    Particle.publish("Door_Open","Basement",60,PRIVATE);
    delay(5000);  // to cater for event rate limit
 }
 else if (BaseValue >= 3000) {
    lastState = false;
 }
 // and
 if (command=="garage"){
    return GValue;
 }
 else if (command=="backdoor") {
     return BDvalue;
 }
 else if (command=="frontdoor"){
     return FDvalue;
 }
 else if (command=="bedroomdoor"){
     return BedValue;
 }
 else if (command=="basementdoor"){
     return BaseValue;
 }

So your line count could easily be reduced by two thirds (I boiled it down to ~40 lines).

1 Like

Update. Adding resisters from each sensor to ground has helped the problem too. Even with the code above, I was getting two notifications. I put a 10ohm resister to ground on each sensor. Semi-related to another problem I had. Garage Door Detector Problem