Requirements: Shortcuts, Pythonista, devices or variables on Indigo representing people home or not
- Code: Select all
#! /usr/bin/env python2.7
# -*- coding: utf-8 -*-
import requests
from requests.auth import HTTPDigestAuth
import json
import speech
people=['dan', 'nicole', 'erin']
peopleHome = []
for person in people:
url = 'http://IPADDRESS:8176/devices/PERSON_'+person+'.json' #I use virtual devices to represent people home or not
response=requests.get(url,auth= HTTPDigestAuth('USER', 'PWD'))
thisDict=json.loads(response.content)
if thisDict['isOn']:
peopleHome.append(person)
print peopleHome
numHome=len(peopleHome)
#BELOW JUST FORMATS AND SPEAKS WHO IS HOME
output=''
i=0
for person in peopleHome:
output=output+peopleHome[i]+' '
i+=1
if i==numHome-1: output=output+('and ')
if i>1: output=output+' are home'
else: output=output+' is home'
speech.say(output)
Moderator's Note: Adds "Example" to the title.