def user(): global mySensorIDs temp1, temp2 = p.readTemps(mySensorIDs, c.TEMPUNIT) temp1 = round(temp1, 1) temp2 = round(temp2, 1) myPumpMode, myPumpStatus, timestamp = p.getStatus() target = p.getTarget() for i in range(0, len(target)): target_new = (target[i]) target2 = p.getTarget2() for i in range(0, len(target2)): target2_new = (target2[i]) target4 = p.getTarget4() for i in range(0, len(target4)): target4_new = (target4[i]) timeStamp = '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) data = { 't1': temp1, 't2': temp2, 'tu': c.TEMPUNIT, 'pm': myPumpMode, 'ps': myPumpStatus, 'tar': target_new, 'ta2': target2_new, 'ta4': target4_new, 'ts': timeStamp } return render_template('user.html', data=data)
def debug(): mySensorIDs = p.getSensorIDs() temp1 = p.readTemps(mySensorIDs) timeStamp = '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) data = {'id1': mySensorIDs[0], 't1': temp1, 'ts': timeStamp} return render_template('debug.html', data=data)
def index(): if 'username' in session: mySensorIDs = p.getSensorIDs() temps = p.readTemps(mySensorIDs) timeStamp = '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) data = { 'temps': temps, 'ts': timeStamp, 'user': escape(session['username']) } return render_template('index.html', data=data) else: return redirect(url_for('login'))
def index(): global mySensorIDs if 'username' in session: uptime1 = p.uptime() uptime_new = round(uptime1, 2) temp1, temp2 = p.readTemps(mySensorIDs, c.TEMPUNIT) temp1 = round(temp1, 1) temp2 = round(temp2, 1) cpu1 = p.cpu() myPumpMode, myPumpStatus, timestamp = p.getStatus() target = p.getTarget() for i in range(0, len(target)): target_new = (target[i]) target2 = p.getTarget2() for i in range(0, len(target2)): target2_new = (target2[i]) target3 = p.getTarget3() for i in range(0, len(target3)): target3_new = (target3[i]) target4 = p.getTarget4() for i in range(0, len(target4)): target4_new = (target4[i]) target5 = p.getTarget5() for i in range(0, len(target5)): target5_new = (target5[i]) target6 = p.getTarget6() for i in range(0, len(target6)): target6_new = (target6[i]) timeStamp = '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) data = { 't1': temp1, 't2': temp2, 'cu': cpu1, 'tu': c.TEMPUNIT, 'pm': myPumpMode, 'ps': myPumpStatus, 'ts': timeStamp, 'tar': target_new, 'ta2': target2_new, 'ta3': target3_new, 'ta4': target4_new, 'ta5': target5_new, 'ta6': target6_new, 'up': uptime_new, 'user': escape(session['username']) } return render_template('index.html', data=data) else: return redirect(url_for('user'))
def status(): # Return temps and pump mode in Json format to any # system that calls the /status URL. e.g. Home Assistant global mySensorIDs, myPumpStatus, myPumpMode temp1, temp2 = p.readTemps(mySensorIDs, c.TEMPUNIT) if myPumpStatus == True: myPumpStatus = "On" else: myPumpStatus = "Off" return jsonify(watertemp=temp1, airtemp=temp2, pumpmode=myPumpMode, pumpstatus=myPumpStatus)
def debug(): uptime1 = p.uptime() uptime_new = round(uptime1, 2) temp1, temp2 = p.readTemps(mySensorIDs, c.TEMPUNIT) cpu1 = p.cpu() sensorIDs = p.getSensorIDs() mode, status, booststart = p.getStatus() hours = p.getSchedule() target = p.getTarget() target2 = p.getTarget2() target3 = p.getTarget3() target4 = p.getTarget4() target5 = p.getTarget5() target6 = p.getTarget6() timeStamp = '{0:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) if mode == "boost": boostremain = 900 + booststart - time.time() else: boostremain = 0 data = { 'id1': sensorIDs[0], 'id2': sensorIDs[1], 't1': temp1, 't2': temp2, 'cu': cpu1, 'tu': c.TEMPUNIT, 'pm': mode, 'ps': status, 'hrs': hours, 'tar': target, 'ta2': target2, 'ta3': target3, 'ta4': target4, 'ta5': target5, 'ta6': target6, 'up': uptime_new, 'ts': timeStamp, 'bt': booststart, 'br': boostremain } return render_template('debug.html', data=data)
mySensorIDs = p.getSensorIDs() # Set number of seconds to wait between loops loopDelay = c.LOOPDELAY # Set number of loops to wait before updating relay loopSendData = c.LOOPSENDDATA loopCounter = 0 if __name__ == '__main__': while True: # Read temperatures in C or F and send to # Emoncms every 1 loops temp1, temp2 = p.readTemps(mySensorIDs, c.TEMPUNIT) myPumpMode, myPumpStatus, booststart = p.getStatus() p.sendEmoncms(c.domain, c.apikey, c.emoncmspath, c.nodeid, temp1, temp2, myPumpStatus, myPumpMode) # Update relay every 3 loops loopCounter += 1 if loopCounter == loopSendData: # Read current schedule, pump status and mode # as it may have been changed by web interface since last loop myHours = p.getSchedule() target = p.getTarget() target2 = p.getTarget2() target3 = p.getTarget3() target4 = p.getTarget4()
# Set number of seconds to wait between loops & number of loops to wait before sending data loopDelay = c.LOOPDELAY loopSendData = c.LOOPSENDDATA loopCounter = c.LOOPSENDDATA - 1 # send on first loop #setup MQTT broker details broker_address = p.getIp() client = mqtt.Client("P1") client.username_pw_set("mqtt", c.MQTTPWORD) client.connect(broker_address, 1883, 60) client.loop_start() if __name__ == '__main__': while True: # Read temperatures and send to Thingspeak # every 5 loops loopCounter += 1 if loopCounter == loopSendData: temp1 = p.readTemps(mySensorIDs) logging.info('Read temperature') p.sendThingspeak(c.THINGSPEAKURL, c.THINGSPEAKKEY, 'field1', temp1) loopCounter = 0 logging.info('Publish temperature') client.publish("pool/temperature", temp1) # Wait before doing it all again time.sleep(loopDelay)