When you leave home, are you sure the lights are turned off? With Ring, you can check it with a video camera and adjust them simply by sending a text message through live chat. Save energy!
Within an hour, a Savoir-faire Linux expert has built a device that allows him to control the lighting in his living room, while he is at the office. As Adrien Béraud has set his Ring account to automatically accept every call, he can see his living room remotely by simply initiating a video call to his home computer. He can then check if the lights are on, and turn them off as needed.
A simple device crafted with open hardware
Adrien first connected lamps in his living room to the Internet using a small connected system Particle Core (type Arduino) and a relay expansion board (Relay Shield). As his lightning is associated with a three-way switching circuit, it can easily control lights, even in the case of Internet failure or in case of problems with the relay. He then added a few lines of code in the documentation of the relay to connect it the Internet.
With some command line, your lights are connected
Once connected, he types a command line in the terminal of his Linux computer. For example, to turn off (LOW) the first lamp (r1):
curl https://api.particle.io/v1/devices/0123456789abcdef/relay -d access_token=123412341234 -d params=r1,LOW
Light control with Ring’s chat can then be done with this Python script:
#!/usr/bin/env python3
import re, json, http.client, urllib.parse
from controler import DRingCtrl
PARTICLE_API_TOKEN = '[your_api_token_here]'
PARTICLE_REQ_URI = '/v1/devices/[your_device_id_here]/relay'
PARTICLE_REQ_RE = re.compile('^(r[0-4],(?:HIGH|LOW))$')
class LightRingController(DRingCtrl):
def __init__(self):
super().__init__("LightController")
def tryParticleReq(self, params):
try:
conn = http.client.HTTPSConnection('api.particle.io')
p = urllib.parse.urlencode({'access_token': PARTICLE_API_TOKEN, 'params': params})
conn.request("POST", PARTICLE_REQ_URI, p, {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
ret = json.loads(conn.getresponse().read().decode())['return_value']
finally:
conn.close()
return ret
def onIncomingMessage(self, callid, ufrom, message):
super().onIncomingMessage(callid, ufrom, message)
msg = message['text/plain']
res = re.search(PARTICLE_REQ_RE, msg)
if res:
op = res.group(0)
print('Command:', op)
ret = self.tryParticleReq(op)
self.callmanager.sendTextMessage(callid, {'text/plain':'Got: '+str(ret)}, False)
if __name__ == "__main__":
ctrl = LightRingController()
ctrl.run()
IoT: endless possibilities
Many uses are possible, from simple to complex. For example, a Ring call can directly control lighting with such a script:
#...
class LightRingController(DRingCtrl):
#...
def onCallStateChanged(self, callid, state, statecode):
super().onCallStateChanged(callid, state, statecode)
if state == "HUNGUP":
self.tryParticleReq('r1,LOW')
elif state == "CURRENT":
self.tryParticleReq('r1,HIGH')
So imagine what you could do if your Ring software was connected to your heating or your garage door… The possibilities are endless!
You have ideas to share? Feel free to comment!
[…] RT @marclijour: 2016 will be the year of #IoT Software Development #HourOfCode @ICTC_CTIC @dougpete … […]
[…] an hour and could be used to control the door of his garage or his heater. (Read the article “How Ring communicates with connected devices” for […]