I have a sketch which, by using a DS18B20 temperature sensor, will turn on a wireless socket switch (with a radiator plugged in) if the temperature is below specified temperature. The ifs inside the loop is posted below. The delays seem necessary for the remote switch to work, so now my sender sends a signal for one second, every two seconds.
I would like to involve a variable which would render unecessary the continued sending of a signal after the switch is on or off. That is, outside the loop, I would have to say something in the lines of "if temperature<19 set status=off" and "if temperature>=19 set status=on" And then in the conditionals I would say "if temperature<19 and status=off, then send the on-signal, and redefine status=on" and similar for the other if. How do I go about this?
My current conditionals:
if(temperature>=19.00) {
delay(1000);
unsigned long sender = 9076822;
unsigned int recipient = 2;
bool command = false;
bool group = false;
homeEasy.sendAdvancedProtocolMessage(sender, recipient, command, group);
}
if(temperature<19.00) {
delay(1000);
unsigned long sender = 9076822;
unsigned int recipient = 2;
bool command = true;
bool group = false;
homeEasy.sendAdvancedProtocolMessage(sender, recipient, command, group);
}
Serial.println(temperature);
delay(2000);
}