Example - “Who is home?”

Share your macOS, iOS, and iPadOS shortcuts here. Post your shortcut in a new topic and be sure to describe thoroughly (screenshots, full text of any scripts, apps used, etc).
User avatar
mundmc
Posts: 1068
Joined: Fri Sep 14, 2012 4:34 pm

Example - “Who is home?”

Post by mundmc »

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)
Moderator's Note: Adds "Example" to the title.

Return to “Apple Shortcuts”