Saturday, 17 November 2018

Vivarium Monitoring

This fellow is a new addition to our household:

We have a new vivarium for him and I wanted to be able to monitor the temperature inside from anywhere. I was thinking of using MQTT and Thingspeak, but a quick search came up with BLYNK!

Blynk is an app that is easy to link to with Arduino / ESP8266. The device sends data to Blynk's server and the app is SO easy to set up and display the data in graphical and text form.

I used info and code from these sources and adapted them to suit.

My code can be found here:

I have a Heltec ESP8266 with OLED display.

I may change this as I want the project to be battery powered.

Friday, 16 November 2018

Heltec ESP8266 with Built in OLED display

I'm still working on the home heating project, and now want to add room thermostats with displays on some of them,

I purchased this:

It was tricky to get going but this guide was fantastic:

If you see guides that say to use the Adafruit libraries -  feel free to give them a go, but the U82g library worked best for me. 

Friday, 23 December 2016

Home Heating IoT Project - Software planning

For this project I want to be able to control the room heating in my house either manually or on a timed system.

I decided to plan it using a flowchart, as I couldn't get my head around the programming easily without visualising it.

Here's the first draft and I'm pleased how it turned out:
This image was made at - so easy to use!

The earlier posts in this project can be found here:

Electracker - More energy consumption analysis

Now that I have a few weeks of data, I wanted to get daily graphs to look for patterns. I amended the original code to create them:

Not as useful as I'd hoped, but the average consumption per day is definitely interesting.

The coding is pretty terrible, sorry. If I was starting from scratch I'd use datetime module functions to do the date work and include some error handling to stop the program crashing when data is missing for an hour. Because I was pushed for time and had a working program already in place  to modify, it was the quickest solution.

Code, such as it is,  is here:

#program to analyse electricity use over time by hour.

#open a file

#for each hour:
#read it line by line
#bucket into hour
#get total
#get average for each hour

#enhancements to follow: daily charts, date range charts, movie!

import csv
import os
import matplotlib
import matplotlib.pyplot as plt

startDay = 20
startMonth = 12

while True:

 for i in range (0,24):     #for each hour
    with open ('feeds.csv', 'rb') as csvfile:
     rawelecdata = csv.DictReader(csvfile)

     for row in rawelecdata:
      if int(row['created_at'][11:13])==i and int(row['created_at'][8:10])==startDay and int(row['created_at'][5:7])==startMonth:
       hourelectot += float(row['field1'])
       j +=1
    print(i,hourelectot/j,j) #useful to for debugging

    elecByHour.append(hourelectot/j) #add average for the current hour to list

    #calculate average for day:
    dailyTotal = dailyTotal + hourelectot
    dailyReadings = dailyReadings + j

 dailyAverage = dailyTotal/dailyReadings
#plot the graph:

 y = (elecByHour)
 N = len(y)
 x = range(N)
 width = 1/1.5
 plt.xlabel ('Time of Day / hr')
 plt.ylabel ('kW')
 plt.title('Consumption for '+ str(startDay) + '/' + str(startMonth) + ' Average = ' + str(dailyAverage)+'kW'), y, width, color="blue")
 plt.savefig('elecByHour' + str(startMonth) + str(startDay) + '.png')
 #os.system('xviewer elecByHour.png &')
 startDay += 1

Tuesday, 29 November 2016

Pi Light and Movie Quote Alarm Clock

Sorry, No documentation on this one. Rough and ready test program.

Turns a blue LED on in the morning (and evening..don't ask) to wake me up, but also plays a random selection from a bank of quotes.  

from gpiozero import LED
from time import sleep
import datetime
import os
import random

led = LED(4)


print (pmOff)
while True:
        while overRide=='auto':

                soundchoice = str(random.randint(1,5))
                playsound=('aplay '+soundchoice+'.wav')
                if timeNow>pmOn and timeNow<pmOff or timeNow>amOn and timeNow<amOff:
                        print('led on')
                        if soundTrigger==1:
                        print('led off')

Live Energy Consumption in a 'Google Guage'

The author can't find a way to make this visualisation public. Wierd user interface at Thingspeak.

Monday, 28 November 2016

Electracker - Analysis of 2 weeks of data

Earlier this month I got serious about logging my home electrical energy consumption.

The Pi tasked with this job has run continuously for two weeks, happily logging data:

And is still doing so.

I wanted to analyse this data to get an average picture of the daily consumption, by hour:

A typical weekday looks like this:

The code is here:

The only thing I'd do to update this is to plonk the overall average consumption for the time period shown as a data box on the graph, e.g. "Average = 0.871 kW" for the main graph.