I saw some discussion on how Indigo might be used to call SimpleControl activities, I am new to Indigo but have been using SimpleControl with an ISY controller for some years now. Anyways, I did up a python script that I thought other may find useful.
A couple of things to note:
- I am new to python so forgive me if I don't quite do things right, also feedback is always welcomed.
- This script assumes SimpleControl hub is on the same server (I have no idea of this will work on different servers)
- I did this through an action group, I plan on taking a stab at making it a plugin at a later date.
- The script assumes your setting a variable to pass in the name of the activity, so you will have to update the variable ID for what ever variable you are using.
- SimpleControl allows for duplicate activity names between rooms, so the activity has to be preceded by a room name, like this <room>: <activity>. Here is an example:
Living Room: Watch TV
Let me know if you have any questions/suggestions.
Keywords:
SimpleControl
Simple Control
SimpleHub
- Code: Select all
import requests
import json
activity_name = indigo.variables[240209652].value # "SimConActivity"
indigo.server.log('attempting to run ' + activity_name + ' on the simple control hub')
# http request, this makes the assumption that Simple Control Hub is on the same server as indigo
# This request will grab the list of all the activities
r = requests.get('http://127.0.0.1:47147/api/v1/activities')
if r.status_code == 200:
# Request was successful, grab the data from the response
data = json.loads(r.text)
# Search through the list of activities looking for the one we want to run, then get the uuid of the activity
uuid = ''
for d in data['data']:
if d['name'] == activity_name:
uuid = d['uuid']
# We found the activity becase the uuid is not blank
if uuid != '':
indigo.server.log('found uuid ' + uuid + ' for ' + activity_name)
# Post to run the activity, assumes simplecontrol hub is on the same server
r = requests.post('http://127.0.0.1:47147/api/v1/runactivity', json = {'activity_uuid':uuid})
# The post was successful
if r.status_code != 200:
indigo.server.log('post request failed, error code ' + str(r.status_code))
else:
indigo.server.log('Activity ' + activity_name + ' requested to start')
else:
indigo.server.log('Could not find activity ' + activity_name)
else:
indigo.server.log('get request failed, error code: ' + str(r.status_code))