Arduino thermostat safety

I'm building a web-connected Arduino thermostat that goes between the central heating unit and our ordinary thermostat. By default it imitates the normal room thermostat, but an override can be enabled so that the Arduino will control the room temperature on its own.

The Arduino receives the temperature from a wireless sensor that sends out the temperature and humidity every minute. The Arduino keeps track of the last time it has received the temperature. If this is over 5 minutes ago, it considers the last temperature measurement unreliable and turns off the override (switches back to the normal room thermostat).

I've been having the problem that the Arduino tends to switch off the override by itself a lot. I've already increased the 'reliability' time from 5 to 20 minutes.

Could you think of a better security measure? I don't want the room freezing or getting too hot.

I can't hook up a wired temperature sensor, as the Arduino is not located in the living room.

Seems as if the connection between your wireless sensor and the Arduino may not be very reliable. In order to understand why that is you'd need to know what the communication mechanism was, whether it was suitable for the way you're trying to use it and whether it was being used correctly.

PeterH:
Seems as if the connection between your wireless sensor and the Arduino may not be very reliable. In order to understand why that is you'd need to know what the communication mechanism was, whether it was suitable for the way you're trying to use it and whether it was being used correctly.

The wireless sensor is fine. It's a purchased one. Most of the time the Arduino receives the temperature, just sometimes it appearantly doesn't.

Now that I think about it, it might be an error in the code. Could you check it for me?

unsigned long maxMillis = 1200000; // if the last temperature measurement was over 20 minutes (in milliseconds) ago, consider it unreliable and switch to the second thermostat.
unsigned long lastMillis = 4293767291; // millis() at the time of the last temperature measurement.

void thermostat(){
    if((millis() - lastMillis) > maxMillis){
      therm_override = false; //Consider the temperature measurement inaccurate, and fall back to following the other.
    }else{
      if(targetTemp - lastTemp >= tempOffset){
        digitalWrite(outputPin, heatOn);
        heating = true;
      }else{
        digitalWrite(outputPin, !heatOn);
        heating = false;
      }
    }
}

lastmillis is updated to millis() when the Arduino receives a temperature.

I suggest you find out, then, since it's a pretty fundamental problem and pointless trying to look for it in the wrong place. How about just printing a message to the serial port, or toggling an LED state, each time a message is received? It would be obvious then what sort of problem we're chasing.

I can't tell what that snippet of code does in isolation.