[RPi] Switching lights

Door magiel op vrijdag 25 oktober 2013 16:00 - Reacties (2)
Categorie: Raspberry Pi, Views: 4.240

Inspired by the blog written by Weejewel (http://weejewel.tweakblog...met-een-raspberry-pi.html.

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:

code:
1
git clone https://github.com/gielus/lightm.git



What is in the repo?

- index.html
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)

- style.css
CSS to make it beautiful (which is a relative concept)

- lightm-web.py
Script to start the webserver

- lightm.py
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-bin/toggle.py
CGI script which is called pressing a button in the web browser

- lights.conf
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)

- init-script
Script which starts the web browser on boot of the Pi

- install-script
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.

Volgende: Receiving based e-mail separation 12-'14 Receiving based e-mail separation
Volgende: Provider & verhuizing 03-'13 Provider & verhuizing

Reacties


Door Tweakers user Thedr, vrijdag 25 oktober 2013 16:54

First: nice 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