Showing posts with label IoT. Show all posts
Showing posts with label IoT. Show all posts

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:

http://amzn.eu/d/2tnupPt

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

https://robotzero.one/heltec-wifi-kit-8

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 lucidchart.com - so easy to use!


The earlier posts in this project can be found here: http://raspitech.blogspot.com/2016_10_01_archive.html

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:
https://github.com/jcwyatt/electracker/blob/master/elecanalDailyGraphs.py





#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
matplotlib.use('agg')
import matplotlib.pyplot as plt



startDay = 20
startMonth = 12

while True:
 elecByHour=[]
 dailyTotal=0
 dailyReadings=0

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

     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.ylim((0,6))
 plt.title('Consumption for '+ str(startDay) + '/' + str(startMonth) + ' Average = ' + str(dailyAverage)+'kW')
 plt.bar(x, y, width, color="blue")
 plt.savefig('elecByHour' + str(startMonth) + str(startDay) + '.png')
 plt.close()
 
 #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)

overRide='auto'
amOn=datetime.time(05,50,00)
amOff=datetime.time(06,30,00)
pmOn=datetime.time(21,30,00)
pmOff=datetime.time(22,45,00)

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

                timeNow=datetime.datetime.now().time()
                soundchoice = str(random.randint(1,5))
                playsound=('aplay '+soundchoice+'.wav')
                if timeNow>pmOn and timeNow<pmOff or timeNow>amOn and timeNow<amOff:
                        led.on()
                        print('led on')
                        soundTrigger+=1
                        if soundTrigger==1:
                                os.system(playsound)
                else:
                        led.off()
                        print('led off')
                        soundTrigger=0
                sleep(60)

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:

https://thingspeak.com/channels/182833

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:

https://raw.githubusercontent.com/jcwyatt/electracker/master/elecanal.py


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.

Tuesday, 15 November 2016

Electracker - Domestic Energy Consumption Logger

I've written about this project before but I revived it after a visit to Jersey Tech Fair and meeting the nice chaps at Jersey Electricity. They tried to sell me 'Nest', a home heating automation system (they may have succeeded. Watch this space.) But we also discussed electricity consumption.

I've had a Pi attached to my electricity meter for over a year now, but doing nothing.
Now rekindled, it seems to be happily tracking my energy usage and logging the results at Thingspeak.

I'm going to leave it for a bit and then plan to do a frequency analysis on a few days worth of data.

https://thingspeak.com/channels/182833





I also added this widget to my phone:

https://play.google.com/store/apps/details?id=ua.livi.thingspeakmonitor&hl=en

So now I can see live updates of my energy consumption as long as I have wifi/3G:








The code is here at github:

https://github.com/jcwyatt/electracker/blob/master/electracker_bars.py







Things I've learnt:

1) The wifi connection was really flaky - an Edimax attached to a Pi Zero. I've replaced the Edimax with a bulky Netgear with an ariel but this seems quite erratic too. Tried a better power supply.  Seems slightly better now. Made it a real pain to SSH into the Pi and also writing to Thingspeak.

2) You can't have it all ways (yet). I was initially recording every interval between flashes, and getting a really accurate reading, but couldn't write this to Thingspeak as it took too long and caused missed readings and errors due to the delay.
Now I'm counting the number of flashes in a 2 minute period and writing a calculated consumption based on this to Thingspeak. Advantages are that it give a consistent rate of readings, which looks great on Thingspeak, and at high consumption rates it should be very accurate, albeit for an average consumption over 2 minutes. However at low consumption rates the accuracy drops off; the small number of flashes per 2 minute interval kills the resolution on the measurements.

Solution:


Some kind of hybrid where it records the interval between flashes and averages this out over 2 minutes, and then writes this average data to TS.
Should be possible:

<pseudocode>
while True:
     Reset total time to 0
     Reset flashes to 0
     Wait for a flash
     Start the timer
     For 2 minutes:
            Wait for a flash
            stop the timer
            record the flash interval
            start the timer
            flashes +=1
            total time = total time + flash interval
            wait 0.07s to check the LED is off again
            repeat
      average = totaltime/flashes
      Consumption = 1.125/average
      Write Consumption to Thingspeak
</pseudocode>

Sunday, 30 October 2016

Home Heating IoT Project - Interface Designed

The interface is now built:


It uses PHP to write to a CSV and the interface reads from the current settings (in csv format) where present, and set these as the default selections.

Ideally I'd like to use AJAX to update the info live.

The html and css are here at git hub.

It's meant to be a mobile ready design but although it picks up the mobile version in a small desktop browser window, my phone displays only the desktop version.



Saturday, 22 October 2016

Home Heating IoT Project - Project Planning



Detailed Requirements:

1) each heater should have 2 programmable time slots, for morning and evening heating

2) it should be possible to turn each heater on or off manually from the interface

3) each heater should have a manual override to turn/stay off or on regardless of program.

4) there should be an override to turn all heaters off.

5) it should be possible to set the heat level (using mark space ratio)

6) it could be possible to link the heat level to outside temp.

7) the program data will be stored on a local csv file (or google sheet?)

8) there will be a php-based interface with the csv file to allow changes to be made, and the current status of the heater to be known.

9) a python program will manage the relays, using the csv file to determine required state of the output.



Schedule data (csv):

sleep (all off)
room1, start1, end1, start2, end2, rm1override on, rm1override off, heatlevel1
room2, start1, end1, start2, end2, rm2override on, rm2override off, heatlevel2
room3, start1, end1, start2, end2, rm3override on, rm3override off, heatlevel3
room4, start1, end1, start2, end2, rm4override on, rm4override off, heatlevel4




Sunday, 27 March 2016

Node Red

I've had a play with Node Red for the first time tonight. In a matter of minutes I was able to operate an LED through the Node Red interface, something I'd been wanting to do for a long time.




I couldn't be much simpler to use. I could do quite a lot of things in Node Red after just one evening playing around. The web side of things is still puzzling for now, with websockets and HTTP the next nut to crack.

I reckon I could control my home heating now just using Node Red and the right hardware.

LATER THAT SAME EVENING........

Couldn't let it lie so I had another play. Now the status of the LED can be output to wherever, e.g. twitter:



Output:




Copy and paste the code below if you want to try it (minus the twitter feed) - I used pin 11 (GPIO 17) to drive the LED.


[{"id":"d82e83d.f27d18","type":"inject","z":"2fc3a5ef.d03c5a","name":"LED on","topic":"","payload":"1","payloadType":"string","repeat":"","crontab":"","once":false,"x":295,"y":112,"wires":[["24897f1c.db768","1b8bd14c.e4742f"]]},{"id":"795f97e3.86a068","type":"inject","z":"2fc3a5ef.d03c5a","name":"LED off","topic":"","payload":"0","payloadType":"string","repeat":"","crontab":"","once":false,"x":297,"y":187,"wires":[["24897f1c.db768","1b8bd14c.e4742f"]]},{"id":"24897f1c.db768","type":"rpi-gpio out","z":"2fc3a5ef.d03c5a","name":"Yellow LED","pin":"11","set":true,"level":"0","out":"out","x":497,"y":146,"wires":[]},{"id":"4a42382a.b5bdc8","type":"debug","z":"2fc3a5ef.d03c5a","name":"LED status","active":true,"console":"false","complete":"payload","x":622,"y":286,"wires":[]},{"id":"1b8bd14c.e4742f","type":"change","z":"2fc3a5ef.d03c5a","name":"Create Human Readable Output","rules":[{"t":"change","p":"payload","from":"0","to":"LED is OFF","re":false},{"t":"change","p":"payload","from":"1","to":"LED is ON","re":false}],"action":"","property":"","from":"","to":"","reg":false,"x":356,"y":287,"wires":[["4a42382a.b5bdc8"]]}]

Thursday, 31 December 2015

Home Heating IoT Project - MQTT? Node.js? Both? - Initial Thoughts

This is the plan:


In my house, I have 4 Redwell heaters in upstairs rooms. They were installed inexpertly (not by me) with the receiver/relay units downstairs, so the room thermostat's RF send signal is not always picked up. This results in heaters staying on all day sometimes.

An IoT solution would solve this problem as well as giving me a host of other useful features. Most desirable:


  • Programmable on/off times (very desirable option: with thermostat control)
  • Manual on/off override of timing program.
  • All on / all off override for if we are out on an evening.
  • Webpage interface.
  • Internet access from outside the home.
From what I have read so far, it looks like MQTT could be very useful, as could node.js. (see also here)

First step is to build a mini-mock-up. On current form this will take months!




Monday, 21 December 2015

MQTT - Mosquitto - To control IoT stuff

I'm coming to realise that MQTT is probably the tool I need to get my head around for basic home automation / monitoring.

On reading up a bit here:




I saw a link to Andy Standford-Clarks ' House that Twitters':


with the audio from the talk at oggcamp here:
http://stanford-clark.com/andysc_oggcamp.mp3


 Less Technical talk by ASC:



Things I want to check out further:
Easyradio
X10 appliance control signalling via mains cables: http://www.x10.com/

Also useful:
http://oliversmith.io/technology/2010/02/26/mqtt-mosquitto-and-php/
(And lots of other stuff from @chemicaloliver )

Idea: AIS - Ship-plotter - Condor??

Further research needed: Websockets.