Pump alarms - simple alerts for any switch input

I recently installed a Heat Pump Water heater. The new water heater produces condensate which has to be pumped out of my basement. The pump is the same as one installs for an AC system, and so now I have two such pumps in the basement. These pumps have a switch on them that is normally closed, and will be opened if the water in the pump gets too high, indicating that something has gone wrong with the pumping.

I created a quick Blynk app to alert me if with pump was experiencing a problem.

The Blynk app is simple enough, having two large LED widgets to show the status for each pump. It also has email and notification widgets. If either pump switch opens, I get an email and a notification on myphone. It also turns on the built-in LED light on the ESP8266. The two pump switches are connected to GND and D5 & D6.

The code running on an ESP8266 module:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "Alarm.h" // defines auth, ssid, password, version, email address and subject

// =========================================================
// pins
const byte AC = V1; 
const byte WH = V2; 
const byte WF = V3;
const byte ACpin = D5;
const byte WHpin = D6;
const byte LED = D4;

// colors
#define BLYNK_GREEN     "#23C48E"
#define BLYNK_RED       "#D3435C"

BlynkTimer timer;
WidgetLED ACled(AC);
WidgetLED WHled(WH);

boolean ACstate = true;
boolean WHstate = true;

void sendMail(String param) {
 String emailcontent  = param + " pump is having a problem";

 Blynk.notify(emailcontent); // send an app notification

//return; //xxx dont actually send mail during testing
  Blynk.email(emailMe, emailsubject, emailcontent);

void readstates()     // Read switches
  boolean isOpen = (digitalRead(ACpin) == HIGH);  // contacts are NC

  if (isOpen != ACstate) {
    if (isOpen) {

      Blynk.setProperty(AC, "color", BLYNK_RED);
    } else {
      Blynk.setProperty(AC, "color", BLYNK_GREEN);
    ACstate = isOpen;
    Serial.print("AC ");

  isOpen = (digitalRead(WHpin) == HIGH); // contacts are NC
  if (isOpen != WHstate) {
    if (isOpen) {
      sendMail("Water heater");
      Blynk.setProperty(WH, "color", BLYNK_RED);
    } else {
      Blynk.setProperty(WH, "color", BLYNK_GREEN);
    WHstate = isOpen;
    Serial.print("WH ");
  }  // changed
  if (ACstate || WHstate) {
    digitalWrite(LED,LOW); // reverse logic!

BLYNK_WRITE(WF) {    // Network status
  int ask = param.asInt() ; // assigning incoming value 
  if (ask == 1) {
}  // V3

void showversion(int pin){
  Blynk.setProperty(pin,"label","Ver " + String(FW_VERSION));

void shownetwork(int pin){
  long rssi = WiFi.RSSI();
      Blynk.setProperty(pin,"offLabel","📶 " + String(rssi) + "dBm");
   // show version of firmware

  // start reading
  timer.setInterval(500L, readstates);

void setup()
  Blynk.begin(auth, ssid, pass); // get onto wifi network

  // set the switch pins as input

void loop()

1 Like

the alarm.h file was requested…

here is a stripped out version:

char auth[] = "your Blynk auth code"; 

char ssid[] = "wifiname";
char pass[] = "wifipassword";

Const long FW_VERSION = 2019111601  ; // yyyymmddnn

const String emailsubject = "❗ Condensate pump problem";  
const char* emailMe = "yourmail@example.com";