can I do this with rp-B?


6 posts
by seekertom » Mon Jun 19, 2017 12:57 am
:?: :?: :?: wondering if this is the way to go. I have a raspberrypi mod b. it has dust on it. :roll: :roll: :roll:

My end game is to have a list of on and off dates and times of my central ac, and calculate the duration of on and off times, and do it as simply as possible.

I can clamp a vane to my supply duct that activates a momentary contact micro switch when ac comes on and the airflow moves the vane, and again activates switch when ac turns off. I could use this switch closure to trigger a bluetooth camera shutter remote (hacking into the remote's switch) to take a picture (of a digital thermometer for additional info) using an old smartphone/camera, complete with date/time stamps.

The problem with this method is having to manually step thru the pics, write down the times, calculate time on, time off manually.

I would rather connect the micro switch to a port on rp and use some sort of software to date/time stamp each event, and then calculate on/off times automatically, and make that available as a printed report, or at least a file ready to dl to a pc. I'm not too sure how to begin.

So, searching for your ideas on whether or not my rp is the device to use, and what programming I need to learn for switch input, logging date/time, calculating time on/off, and ending with a report.
Any help would be greatly appreciated.
seekertom
Posts: 2
Joined: Mon Jun 19, 2017 12:34 am
by LetHopeItsSnowing » Mon Jun 19, 2017 10:29 am
This sounds like a doable project... However I know nothing of AC units (being from the uk, we rarely have days warm enough to worry!).

You seem to know how to get an input from your AC unit when it switches on / off, so I would hook this up to a GPIO pin on a Raspberry Pi (either via a relay or opto-coupler).

A simple python script could then monitor the state of the pin, when it switches write the time to a file, when it switches off do the same. You could even hook up a Picamera module to the Pi, to take pictures of the ac unit, if you wanted. After that you are only limited by your imagination and desire to learn new stuff!
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"
User avatar
Posts: 337
Joined: Sat May 26, 2012 6:40 am
Location: UK
by wh7qq » Mon Jun 19, 2017 10:53 am
You could also use an AC current transducer to sense the current to the HVAC system and connect that to a pi...simpler and more dependable than a jury-rigged mechanical system. Again, a fairly simple python script could do the logging. A DS18B20 temp sensor could also be included so the RPi is doing everything...so no need for a camera and digital thermometer. You would also need a web connection or a Real Time Clock (RTC) to keep track of the time.
Sent by WH7QQ from an RPi3/Raspbian/pixel desktop.
Posts: 555
Joined: Thu Oct 09, 2014 2:50 am
by pcmanbob » Mon Jun 19, 2017 1:08 pm
HI.

To do the time logging in python its as simple as this.
( assuming input is low when switch is off )
Code: Select all
import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(7, GPIO.IN)
difference = 0
seconds = 0
minutes = 0
hours = 0
off = time.time()

def convert():
    global difference, seconds, minutes, hours
    seconds = difference
    minutes = seconds // 60
    hours = minutes // 60

while True:
    # waiting for switch on
    while GPIO.input(7) == 0:
      time.sleep(0.5)
    else:
        on = time.time()
        now = (time.strftime("%a %b %d %Y %H:%M:%S"))
        #print "off ", off
        #print "on  ", on
        difference = on - off
        convert()
        print "switch on at ", now
        print "time since switch off"
        print "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        print " "

    # waiting for switch off
    while GPIO.input(7) == 1:
      time.sleep(0.5)
    else:
        off = time.time()
        now = (time.strftime("%a %b %d %Y %H:%M:%S"))
        #print "off ", off
        #print "on  ", on
        difference = off - on
        convert()
        print "switch off at ", now
        print "time since switch on"
        print "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        print " "


just prints to screen as it is but could just as easily save the information to a text file.
just let me know if you want help with the saving to file.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
Posts: 1165
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK
by seekertom » Sun Jun 25, 2017 5:35 pm
thanks to everyone for their input on my project.
Current sensors cost, and I have microswitches in my junk box. easy to slap together a mount using pinchy clamp, temp attach to ac supply grill.

Air temp not priority, just something to aim the camera at...

The code provided is extremely helpful, and I definitely would like help expanding it to end up with a text file which could be exported, from sd to pc?

all in all, at 72, it's hard for me to get into learning a new programming language. I can think of lots I could do with it once learned, but time is at a premium now, so I need to seek out the simplest solutions.

While rpi will remain on the stove, I'm thinking "simple" means just find a way to interface that switch of mine with a spreadsheet... minimal coding required here.

Really love my pi, no matter how dusty it is. Thanks folks for the help. Gives me lots of ideas!
tom
Posts: 2
Joined: Mon Jun 19, 2017 12:34 am
by pcmanbob » Sun Jun 25, 2017 6:57 pm
Here you go

Changed the program to output times to a text file call times.txt in /home/pi directory

Code: Select all
import RPi.GPIO as GPIO
import time


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(7, GPIO.IN)
difference = 0
seconds = 0
minutes = 0
hours = 0
off = time.time()


def convert():
    global difference, seconds, minutes, hours
    seconds = difference
    minutes = seconds // 60
    hours = minutes // 60

while True:
    # waiting for switch on
    while GPIO.input(7) == 0:
      time.sleep(0.5)
    else:
        on = time.time()
        now = (time.strftime("%a %b %d %Y %H:%M:%S"))

        difference = on - off
        convert()
        #print "switch on at ", now
        #print "time since switch off"
        #print "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        #print " "
       
        delay = "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        result = open("/home/pi/times.txt","a")
        result.write("switch on " + now + "\n")
        result.write("time since switch off " + delay + "\n")
        result.write(" \n")
        result.close()       

    # waiting for switch off
    while GPIO.input(7) == 1:
      time.sleep(0.5)
    else:
        off = time.time()
        now = (time.strftime("%a %b %d %Y %H:%M:%S"))

        difference = off - on
        convert()
        #print "switch off at ", now
        #print "time since switch on"
        #print "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        #print " "

        delay = "%02d:%02d:%02d" % (hours, minutes % 60, seconds % 60)
        result = open("/home/pi/times.txt","a")
        result.write("switch off " + now + "\n")
        result.write("time since switch on " + delay + "\n")
        result.write(" \n")
        result.close()       
   

   


it will produce this in the txt file

Code: Select all
switch on Sun Jun 25 2017 19:54:45
time since switch off 00:00:07
 
switch off Sun Jun 25 2017 19:54:53
time since switch on 00:00:07
 
switch on Sun Jun 25 2017 19:55:03
time since switch off 00:00:10
 
switch off Sun Jun 25 2017 19:55:17
time since switch on 00:00:13
 
switch on Sun Jun 25 2017 19:55:23
time since switch off 00:00:06
 
switch off Sun Jun 25 2017 19:55:28
time since switch on 00:00:04
 
switch on Sun Jun 25 2017 19:55:32
time since switch off 00:00:04
 
switch off Sun Jun 25 2017 19:55:38
time since switch on 00:00:05
 
switch on Sun Jun 25 2017 19:55:42
time since switch off 00:00:04
 
switch off Sun Jun 25 2017 19:55:44
time since switch on 00:00:02
 



I will leave it to you to make any changes you want to what each line actually says.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
Posts: 1165
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK