OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) OSPi – Interval – Garage Door Sensing and Control – Success Re: Re: OSPi – Interval – Garage Door Sensing and Control – Succ

#24916

dennyfmn
Participant

With some great help from Dan, I now have a button on the home page that will open or close the garage door when clicked.

Dan has also implemented the per station rain sensor option so that is really cool too. If you look at the screen shot below, you can see that the Deck and Window Boxes stations are still active even though the Lawn stations are off because rain has been detected.

Here’s how to put a button on the home page and get it to do something when clicked.

First I wanted a button with a suitable icon that would match the good looking ones on the page. I searched for free 32×32 bit png icons and couldn’t find one that looked like a garage door, but I found one that I could edit to serve. http://www.zoobapps.com has lots of free icons, the one I chose is http://www.zoobapps.com/free_icons/index.php?icon_id=25220&cat_id=

[attachment=2:2dczcqz9]reloadall-5777.png[/attachment:2dczcqz9]
I rotated it 270 degrees and edited the tails off the arrows. I did the editing with Windows Paint, but found that neither the Win7 or WinXP version would save the icon with its transparency. I had to use Gimp to restore the transparency to the white backround so that the icon would look like the others. Gimp calls it the alpha layer. Saved the output as svc_updown.png to comply with the naming convention and uploaded it to ../OSPi/static/images/icons.

[attachment=1:2dczcqz9]svc_updown.png[/attachment:2dczcqz9]
To get the button to show up on the page, add a line to ../OSPi/static/scripts/java/svc1.8.3/home.js. I put it right after the commented out http://igoogle.wunderground.com line. I’ll show where the link argument is pointing to in just a minute.


w("");

So now the home page looks like this:

[attachment=0:2dczcqz9]ToggleDoorButtonAdded.JPG[/attachment:2dczcqz9]

Now to get the button to do the action, here’s what gets added to ../OSPi/ospi.py

Since I have previously added as documented above the pin definition for the door control and had initialized it to be an output, I needed to add a function to raise and lower the output for a short time to activate the relay that simulates a button push for the door. Added to the Functions section:


# Simulate garage door button push by turning relay on for a short time
def ToggleDoor():
GPIO.output(pin_door_control, GPIO.HIGH)
time.sleep(1)
GPIO.output(pin_door_control, GPIO.LOW)

Now to integrate the action into the web page add a url to the bottom of the urls section:


'/rev', 'show_revision',
'/tgd', 'toggle_garageDoor', <---- added
]

Notice that ‘tgd’ is the parameter used in home.js where the button is placed on the page and the onclick link defined.

The last step is to define a class to service the url, added to the bottom of the Classes section:


class toggle_garageDoor:
"""Open and close garage door"""
def GET(self):
ToggleDoor()
time.sleep(12) # Give the door time to open or close before refreshing the home page
raise web.seeother('/') # This line refreshes the home page

Notice that the class name is the same as the one defined in the urls section. The time.sleep(12) is there so that the new state of the door is displayed when the home page is refreshed. When opening, the door clears the “closed” sensor very quickly, but when the door is closing, it takes about 11 seconds to trip the “closed” switch.

That’s it. Click the button on the home page, the door goes up, click it again, the door goes down. What fun!

Hopefully you can use this as-is or as a template to get OSPi and Interval to do all kinds of cool things.

Thanks to Dan for all his help in getting this going! Having him explain the magic of the url and class was the key!