Structure of IFs & timers

Its been a few years since I attempted Wiring so bear with me.

I need some guidance on proper nesting of IFs and timers to get my workflow to operate.

I have two fluid containers and each has two level sensors (closures).
In each container, one is for low level and one is for empty.

I want the code to send an email notification when the low sensor is closed, and I want it to send a new email at 8am every morning until it is open again.

If any of the empty sensors are closed then I want it to shut off the equipment and send an email, repeating hourly until resolved.

I love this hardware so far
Thanks everyone!

I’m shooting from the hip on this one, but here’s some hastily assembled pseudo-code typed in notepad. See if it makes any sense. Please excuse any typos or derps.

// Flags for low sensor warning e-mails
bool sensorLowWarning1 = false;
bool sensorLowWarning2 = false;

// Flags for empty sensor warning e-mails
bool sensorEmptyWarning1 = false;
bool sensorEmptyWarning2 = false;

// Flags for empty sensor states
bool sensorEmptyState1 = false; // False means it is NOT empty
bool sensorEmptyState2 = false; // False means it is NOT empty


void setup() {
	// Do stuff here
}


void loop() {
	// Check low sensor #1
	if(sensorLow1==closed && sensorLowWarning1==false && Time.hour()==8) {
		sensorLowWarning1 = true;
		
		// Code/function call to send e-mail
	}


	// Check low sensor #2
	if(sensorLow2==closed && sensorLowWarning2==false && Time.hour()==8) {
		sensorLowWarning2 = true;

		// Code/function call to send e-mail
	}


	// Reset the low sensor warnings at midnight
	if(sensorLowWarning1==true && Time.hour()==0) {
		sensorLowWarning1 = false;
	}

	if(sensorLowWarning2==true && Time.hour()==0) {
		sensorLowWarning2 = false;
	}


	// Turn stuff off if empty sensor is closed
	if(sensorEmpty1==closed && sensorEmptyState1==false) {
		sensorEmptyState1 = true;
		
		// Code to turn stuff off
	}

	if(sensorEmpty2==closed && sensorEmptyState2==false) {
		sensorEmptyState2 = true;
		
		// Code to turn stuff off
	}


	// Send empty warning e-mail
	if(sensorEmpty1==closed && sensorEmptyWarning1==false && Time.minute()==0) {
		sensorEmptyWarning1 = true;
		
		// Code/function call to send e-mail
	}

	if(sensorEmpty2==closed && sensorEmptyWarning2==false && Time.minute()==0) {
		sensorEmptyWarning2 = true;
		
		// Code/function call to send e-mail
	}


	// Reset empty warning flags half past the hour
	if(sensorEmptyWarning1==true && Time.minute()==30) {
		sensorEmptyWarning1 = false;
	}

	if(sensorEmptyWarning2==true && Time.minute()==30) {
		sensorEmptyWarning2 = false;
	}


	// Check to see if the empty sensors are now open again
	if(sensorEmptyState1==true && sensorEmpty1==open) {
		sensorEmptyState1 = false;
		
		// Code turn stuff on
		// Maybe send an e-mail here too?
	}

	if(sensorEmptyState2==true && sensorEmpty2==open) {
		sensorEmptyState2 = false;
		
		// Code turn stuff on
		// Maybe send an e-mail here too?
	}
}```
3 Likes

Very cool! thanks for the reply. Ill give it a shot

@wgbartley, you’re such a smarty pants :stuck_out_tongue: