Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 5 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
| ||||||
|
I've seen tanks overflowing which is a waste of water and hence decided make this prototype.
Automatic maintaining of water level via Python program:
Controlling pump via Alexa:
Web page to view water level and control the pump:
Python program for automatic water level control
PythonRunning the following code will check water level every 10 seconds and display it. If the water level is below 20%, pump is switched ON and when it reaches 100% the pump is switched OFF.
import json,time,requests
from boltiot import Bolt
mybolt = Bolt("API Key","Device ID")
while True:
response = requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=getAnalogValues&deviceName=Device ID")
data = json.loads(response.text)
csv = data["value"]
temp = csv.split(",")
arr=[]
for i in range(len(temp)-1):
arr.append(int(temp[i]))
print(arr)
if arr[0] < 100:
print("Water Level below 20%. Turning pump on")
requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOn&deviceName=Device ID")
elif arr[4] > 100:
print("Water level 100%. Turning pump off")
requests.request("GET","https://cloud.boltiot.com/remote/API Key/serialWR?data=pumpOff&deviceName=Device ID")
else:
if arr[3] > 100:
print("Water level is at 80%")
elif arr[2] > 100:
print("Water level is at 60%")
elif arr[1] > 100:
print("Water level is at 40%")
elif arr[0] > 100:
print("Water level is at 20%")
else:
print("Error")
time.sleep(10)
To check and control via Website
HTMLThis is a website to see the water level and control pump manually.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Water Level</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="column s12">
<div class="card">
<div class="card-content">
<div id="level">The water Level is : </div>
<div id="temp" ></div>
</div>
<div class="card-action">
<button class="btn" onclick="handle()">Update</button>
<button class="btn" onclick="on()">Switch On</button>
<button class="btn" onclick="off()">Switch Off</button>
</div>
</div>
</div>
</div>
</div>
<script>
function handle(){
setKey("Your API Key","Your Device ID");
serialWR('getAnalogValues','10','temp');
setTimeout(()=>{
var el = document.getElementById("level");
var arr = temp.innerText.substring(11).split(",");
if(arr[0]<100){
el.innerText += " Below 20%";
}
else if(arr[4]>100)
{
el.innerText += " 100%";
}
else{
if(arr[3]>100)
el.innerText += " 80%";
else if(arr[2]>100)
el.innerText += " 60%";
else if(arr[1]>100)
el.innerText += " 40%";
else if(arr[0]>100)
el.innerText += " 20%";
}
},1500);
}
function on(){
serialWR('pumpOn','10','temp');
}
function off(){
serialWR('pumpOff','10','temp');
}
</script>
<script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>
</body>
</html>
To control pump via Alexa
XMLIn IFTTT, create two applets:
- One having Alexa trigger as "Pump on"
- And the other having "Pump Off"
- For "That" section, select Webhooks and insert the given urls respectively.
- One having Alexa trigger as "Pump on"
- And the other having "Pump Off"
- For "That" section, select Webhooks and insert the given urls respectively.
https://cloud.boltiot.com/remote/ Your API Key /serialWR?data=pumpOn&deviceName= Your Device ID
https://cloud.boltiot.com/remote/ Your API Key /serialWR?data=pumpOff&deviceName= Your Device ID
Comments