Super Simple Timer with Button

Posted on Sun 11 August 2019 in Home Automation,

I have a fan that I use as an exhaust. It's hung against a window, before I go to bed I like to switch the fan on, clear the air.

As a result, I often wake to find the fan still on, having run all night (because I fell asleep or forgot it) with the room colder than I appreciate in the mornings.

Something needed to be done about that. Heinous waste of electricity.

I have 433Mhz sockets all around the house, one of which was connected to the fan already but only for the purposes of remote control. I have a Pi set up with a 433MHz transmitter already...

If you haven't, read this: []

I wrote a super simple script that turns the socket on, waits 15 mins using a time.sleep function, then switches it off again.

The bit I like most however, I have a button on my mobile home screen that triggers it. No need to log in before bed and run it, just a simple tap.

Problem sorted.

Assuming you have a working Pi, 433Utils setup and the remote recorded.

Create a python file with the below script in it

import os
import time
os.system ("/433Utils/RPi_utils/codesend 5836955")
time.sleep  (900)
os.system ("/433Utils/RPi_utils/codesend 5836954")

Create a PHP file with the below code in it

system("sudo python /var/www/pihome/public_html/"); header("Location:");

What we're going to do now is host a webpage with a button on it. That button is going to call the PHP script, that will in turn, call the python script.

There are probably cleaner ways of doing this, such as including the PHP within the HTML, however this way also works. I also only realized that was possible, writing this guide. I did the original remote / button several years ago and have, apparently, learned some stuff since then. No point in reinventing the wheel.

To host a webpage you will need a web server. I previously used Apache, but have moved many projects over to flask. For this guide I will be working with Apache.

I wrote a guide explaining how to install and configure Apache []

Once you have Apache up and working, you will need an index.html with a button on it. Feel free to use mine.

alt text

You can make the page as fancy as you like, include .css if you want to but for this to work, you will just need a button.

Create an index.html file with the below in it

<!DOCTYPE html>
<title>Fan Button</title>
<img src="BlueButtonS.png"><a href="fan15.php">

Drop the, index.html, fan15.php, blueButtonS.png, and all in the same directory, under /var/www/websitename/public_html/

Reboot your Pi and go to it's address and what ever port you chose during the Apache guide.

You should see a button. Click it.

Now for the home screen icon. Download opera mobile browser.

Go to your button website. Click the button AND REALLY QUICKLY, open Opera's menu and click add to home screen.

alt text

I use Nova Launcher for Android that lets me customize icons.

alt text

Done. 15 min timer on the home screen.