(Classic) Controlling the Lights in SquareTag

Phil Windley has written about setting up a lighting system controlled by services and apps inside SquareTag. The system uses both a set of Hue lights and various Insteon devices

The diagram that shows how this all connects together is shown here:

There are several important points:

  • Since the Hue lights are merely responding to commands, they do not raise any events into the system. The Hue service (see the code) watches for events from other applications (e.g. explicit:office_lights) and uses the API in the controller to talk to the lights. 
  • The Insteon devices are working through a Universal Devices ISY994i controller that has the capability of making HTTP requests. The controller is programmed to act as an event endpoint and raise events over HTTP.   The Insteon service (see the code) responds to those events as well as events from other apps. The Insteon service also sends commands to the controller based on events from other apps.
  • The Light Controller app (see the code) is a SquareTag application that makes use of data from both of the services as well as second control signals to which both services respond. There are important lessons in semantic translation (see Chapter 12 of The Live Web for more information).  Defining event translation rules in this way creates more flexible, loosely-coupled systems. 
  • The Light Controller app also listens for thermostat:new_temperature events and responds be looking at the temperature trend and setting the color of one of the Hue lights to indicate the temperature trend (red = warmer, amber = no change, blue = cooler). 

Copyright Picolabs | Licensed under Creative Commons.