Calling SimpleControl Activities from Indigo using Python

Posted on
Sun Jan 20, 2019 9:55 am
ginganinja offline
Posts: 12
Joined: Jan 14, 2019

Calling SimpleControl Activities from Indigo using Python

Hi all,

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))

Posted on
Sun Jan 20, 2019 11:08 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Calling SimpleControl Activities from Indigo using Pytho

Excellent job, I'm sure others will find it useful. Thanks for the contribution!

[MODERATOR NOTE] I'm moving this post over to the User Contributions»Python Scripts forum where I think it's more likely to be found, but I'll leave a shadow topic in the original place.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Jan 20, 2019 11:51 am
ginganinja offline
Posts: 12
Joined: Jan 14, 2019

Re: Calling SimpleControl Activities from Indigo using Pytho

Thanks Jay, much appreciated.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest