“Who is home?”

Posted on
Fri Nov 09, 2018 7:04 am
mundmc offline
User avatar
Posts: 837
Joined: Sep 14, 2012

“Who is home?”

Use case: Tells me who is home.
Requirements: Shortcuts, Pythonista, devices or variables on Indigo representing people home or not

Image

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)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest