[RPi] Switching lights
In the desperate hope to save some energy, I want to switch my lights on and off automatically, based on the presence of my phone and detected motion in the room (I live in a relatively small studio near Amsterdam).
The switching of the lights is completely copied from the blog mentioned above. I wrote some Python scripts to switch (or toggle) the lights on and off based on a POST request from a web page.
The raspberry pi isn't very powerful, so I don't want a native web server running. My fortune, Python offers a simple CGI web server .
The code i've written can be obtained from github:
git clone https://github.com/gielus/lightm.git
What is in the repo?
index file which shows the buttons. The page is meant to be displayed on a full hd phone (i've own an Galaxy S4 active)
CSS to make it beautiful (which is a relative concept)
Script to start the webserver
Library (or package in Python) containing the functions calling the programs written by Weejewel. The function actually requires the files from Weejewel's blog to be in '/usr/local/bin/lights/'. But you can change this in the functions.
CGI script which is called pressing a button in the web browser
Definition of available lights (read: 433mhz switches). The program expects this in the following format:
$NAME $TYPE $FREQ $SWIT $FILE
NAME is the name you give to the switch. I've named them BANK,KAST,LED,DESK and KEUKEN.
TYPE is the type of 433mhz receivers you are using. I've got 3 Elro switches and 3 switches from the Action.
FREQ is the frequency the receivers are set to. I used this http://www.chauvetlightin...et-dip-switch-calculator/ dipswitch calculator to get the frequency from the dipswitch settings.
SWIT (nice abbreviation of 'switch') defines the receiver to address (A,B,C,D or E).
FILE is the file containing the state of the receiver (on or off)
Script which starts the web browser on boot of the Pi
Script which places everything in the right place. At least, that is what I expect it to do. I haven't tested it.
You need to include jQuery yourself (http://jquery.com/).
At this moment I have a service written in Python which pings my phone every two minutes. When two consecutive checks detect my phone is gone, the lights will be turned off.
The idea is that the lights will be turned on when:
- The IR motion detector detects movement, and
- My phone comes back in the network
but only when the input from the light sensor is high enough (the higher, the less light. Yeah, I too think this should have been the other way around)
I have some more thoughts on this but that might be more suitable for a next blog.
Second, to maybe save you some time/effort; have you ever heard of the pilight project? It's an open source home automation project using the RasPi and in example a 433MHz receiver and transmitter, founded by a fellow tweaker. You should definitely have a look at www.pilight.org and GoT: pilight - modulaire domotica voor de Raspberry Pi
I think they have built a very nice base for your project, even better than the one mentioned and I really think a lot of tweakers would be thrilled if you could contribute your ideas and skills to the project!
[Reactie gewijzigd op vrijdag 25 oktober 2013 17:01]
Reageren is niet meer mogelijk