Note most of the code examples below are calling methods on the object self
. In this context, self
is meant to be the Plugin instance as defined inside the plugin.py
file. To execute the sample code outside of Plugin instance methods use the indigo.activePlugin
object instead.
Important: For simplicity some of the samples below specify objects based on name (“office desk lamp”
). However, the preferred lookup mechanism is to use the object's ID which can be retrieved by control-clicking on the object name in Indigo's Main Window. By using the ID you ensure the object will be found even if its name is changed.
The Indigo Plugin SDK (available here) includes example plugins with full XML and python source. They are a great place to start when developing new plugins.
Included in the SDK are examples that create plugin based relay, dimmer, thermostat, sensor, speed control, sprinkler, energy meter and custom devices. Also included is an example showing basic Indigo database traversal, how to catch low-level X10/INSTEON messages, and how to create an Indigo telnet server using the python twisted framework.
We'll be adding additional example plugins in the future.
Additionally, below is a table of common plugin tasks and built-in plugins that implement those tasks in some form or another (from simplest to most complex):
Plugin task | Plugin that illustrates an approach |
---|---|
Parsing XML from an IP source | NOAA Weather, WeatherSnoop |
Integrating with native Mac Apps | Airfoil |
Sending RS232 (serial port & network serial port) Commands | EasyDAQ |
Reading RS232 (serial & network serial port) Input | EasyDAQ |
Interacting with an IMAP mail server | iCal Alarm Processor |
Creating custom devices with states | Simple: NOAA Weather, WeatherSnoop - Complex: EasyDAQ, iTunes |
Creating custom actions | Growl, Action Collection |
Creating custom events | Airfoil |
Each of these plugins is installed by default with Indigo 7 - in the /Library/Application Support/Perceptive Automation/Indigo 7/Plugins (Disabled)/
folder. To see the various XML and python source files, just right-click on it in the Finder
and select Show Package Contents
.
Both the SDK example plugins and the plugins included with Indigo above are great places to see working examples of plugins and their source code.
(useful, but very rough notes below)
self.pluginPrefs["somePrefKey"]
or, if you're not sure the key exists:
self.pluginPrefs.get("somePrefKey", "default value if key doesn't exist")
The latter will return the second parameter if they key doesn't exist in the dictionary - it's your responsibility to add it to the prefs dict if you want it to be stored permanently.
someVal = self.pluginPrefs["somePrefKey"] indigo.server.log("value is " + str(someVal))
self.pluginPrefs["somePrefKey"] = 1234
(useful, but very rough notes below)
.pluginProps
.dev = indigo.devices["den fixture"] newProps = dev.pluginProps newProps["onCycles"] = 5 newProps["moreData1"] = "abc" newProps["moreData2"] = True newProps["moreData3"] = 123.45 dev.replacePluginPropsOnServer(newProps)
dev = indigo.devices["den fixture"] onCycles = dev.pluginProps["onCycles"] indigo.server.log("onCycles is " + str(onCycles))
dev = indigo.devices["den fixture"] newProps = dev.pluginProps newProps["onCycles"] += 1 dev.replacePluginPropsOnServer(newProps) dev = indigo.devices["den fixture"] onCycles = dev.pluginProps["onCycles"] indigo.server.log("onCycles is now " + str(onCycles))
.globalProps
.
(useful, but very rough notes below)
<ConfigUI>
XML node. Every field id
is automatically mapped into the device instance .pluginProps
metadata dictionary (described above) as a unique key.<States>
XML node, and are used to define the transient state information for a device (ex: on/off setting, brightness, temperature, etc.).Device State Changed
options when that plugin device type is selected, and are automatically shown in the Control Page editor when a control is created inspecting that plugin device.heatSetPoint
by 1:dev = indigo.devices["Custom Plugin Thermostat"] dev.updateStateOnServer("heatSetPoint", dev.states["heatSetPoint"] + 1)
deviceStartComm
and deviceStopComm
to start/stop any hardware communication (normally via a new per-device thread):def deviceStartComm(self, dev): self.easydaq.startCommThread(dev) def deviceStopComm(self, dev): self.easydaq.stopCommThread(dev)
deviceStartComm
and deviceStopComm
are automatically managed by the Indigo Server and Indigo Plugin Host. When a plugin first connects all enabled device instances owned by the plugin will receive deviceStartComm
calls. Likewise, deviceStartComm
is called when a new plugin device is created or duplicated. deviceStopComm
is called whenever a plugin is disabled, deleted, or when the plugin is shutting down. Therefore, these two functions should be the primary bottlenecks for starting/stopping device hardware or network connections.
Explain Events.xml. Show example plugin subclasses of functions: triggerStartProcessing, triggerStopProcessing, didTriggerProcessingPropertyChange. Note it works very similarly to devices.
(useful, but very rough notes below)
Give examples of using indigo.devices.subscribeToChanges() and plugin subclasses of functions: deviceDeleted, deviceUpdated.
(useful, but very rough notes below)
Give examples of using indigo.*.subscribeToChanges() and plugin subclasses of functions: variableCreated, variableDeleted, variableUpdated, triggerCreated, triggerDeleted, triggerUpdated, scheduleCreated, scheduleDeleted, scheduleUpdated, actionGroupCreated, actionGroupDeleted, actionGroupUpdated, controlPageCreated, controlPageDeleted, controlPageUpdated.