Doorbell (Python) script in wiki
Posted: Wednesday 10 May 2017 15:19
Hi Folks,
I'm looking for the basics to connect my doorbell to GPIO of my RPI3.
In the WIKI i found this script, but as far as my understanding of Python goes, it seems that there is some part missing in the script!?
I'd like to work on this project and see if i can get it to work.
I see that "domoticzurl" is defined, but not used...
What appears to be missing is the part where the "domoticzurl" is called when GPIO18 goes low.
So, i guess that domoticzurl should be called somewhere in the if statement, before time.sleep(5.0) ofcourse, in order to trigger a switch in Domoticz. My question is, what will be the proper way to do this? (I'm no Python developer)
Wouldn't that be as simple as the below example?
Guess that we don't really need import urllib.request and import json unless we want to do something with the response, right?
Thanks!
Marco
I'm looking for the basics to connect my doorbell to GPIO of my RPI3.
In the WIKI i found this script, but as far as my understanding of Python goes, it seems that there is some part missing in the script!?
I'd like to work on this project and see if i can get it to work.
I see that "domoticzurl" is defined, but not used...
Code: Select all
# Settings for the domoticz server
domoticzserver="ipadres:8080"
domoticzusername = ""
domoticzpassword = ""
domoticzurl = 'http://'+domoticzserver+'/json.htm?type=command¶m=switchlight&idx=170&switchcmd=On'
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
time.sleep(5.0)
So, i guess that domoticzurl should be called somewhere in the if statement, before time.sleep(5.0) ofcourse, in order to trigger a switch in Domoticz. My question is, what will be the proper way to do this? (I'm no Python developer)
Wouldn't that be as simple as the below example?
Code: Select all
url = "http://maps.googleapis.com/maps/api/geocode/json?address=google"
response = urllib.urlopen(url)
#
# if you want to do something with Domoticz response... add below lines, otherwise leave them out or comment out with a #
#
data = json.loads(response.read())
print data
Thanks!
Marco