Software Overview  |  Sitemap  |  Downloads  |  Developers  |  Forums

Recipe for a Timer Controlled Socket that Senses Current and Light

This Recipe uses a Virtual Device Interval Timer and Digi XBee Smart Plug to give timed on/off control over a light or appliance. The Smart Plug is a wirelessly controlled electrical socket, and it also monitors electrical current and senses ambient light.


For this Recipe you will need:

  • an XBee Smart Plug
  • an XBee Coordinator (XStick)

Before installing the Smart Plug, inspect the Smart Plug case until you find its serial number label. It often has a bar code at the top, and has a string underneath that begins with "SN:(S)". The serial number follows the "SN:(S)" and is a string with the digits 0-9 and the letters A-F. The serial number is a 16 digit (64 bit) hexadecimal number (a number in base 16). Write the serial number down, as you will need it for this Recipe.

Plug the Smart Plug into an electrical socket where you wish to control a light or appliance, and plug the XStick into a USB port on your host computer. Keep the XStick and the Smart Plug less then a few tens of feet apart to begin with, as the two are wireless devices and can get out of range. Once you have things working, you can experiment over greater distances.

Here is the Script you need to run for this Recipe:

# Install an XBee Smart Plug under timer control

# get the XBee address of the Smart Plug
# get Coordinator's USB port

# get the days of the month for the timer - default to all days
# get the intervals for the timer - give an example to work with
optional_script_parameters(timer_interval:"9:00 to 12:00, 16:00 to 18:00")

# Add a Coordinator
run_script("Scripts/Device/XBee/Coordinator", id:"coordinator", port_location:coordinator_port)

# Add the smart switch
run_script("Scripts/Device/XBee/SmartPlug", address:plug_address, id:"smart_plug", port_location:coordinator_port)

# Add a timer
run_script("Scripts/Device/Virtual/TimerInterval", days:timer_days, id:"timer", intervals:timer_interval)

# wire the timer to the Smart Plug
wire("timer:out", "smart_plug:1")

To run this Script, you need 4 parameters: the "plug_address", the "coordinator_port", the "timer_days", and the "timer_interval".

The plug_address parameter is the serial number of the Smart Plug. To convert the serial number to the plug_address parameter, strip any leading zeros from the serial number and replace them with "0x". The coordinator_port parameter is the name of the USB port of the Coordinator. On *nix hosts, the USB port name is in the "/dev" directory. To see the devices in order of their creation, type "ls -lrt /dev" at a shell prompt and look near the bottom of the list for your Coordinator's USB port.

The timer_days parameter is a string containing all the days of the month (1-31) you wish the timer to run. The parameter is a string with the days separated by commas. The empty string means run on all days. The timer_interval is a string containing the intervals you wish the timer to run within. Intervals are hours:minute strings, with the hours measured in military time.

As an example, for a Coordinator at USB port "/dev/cu.usbserial-00002006" and a Smart Plug with serial number "0013A200406B0263", with an Interval Timer running on the odd days of the month from 8AM to 12PM and 12:30 PM to 9PM, the Script parameters are:

coordinator_port: "/dev/cu.usbserial-00002006"
plug_address: 0x13A200406B0263
timer_days: "1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31"
timer_interval: "8:00 to 12:00, 12:30 to 21:00"

Running the Script

Run the Script. Go to the Device Explorer, expand the "smart_plug" and "timer" devices. The "out" terminal of the Interval Timer and the "1" and "1S" terminals of the Smart Plug should be at the same state. The Interval Timer state should agree with the days and interval values you specified.

Catalina Computing, LLC.

Copyright © Catalina Computing, LLC. (2013-2018)

Page last updated: Mon Dec 2 00:03:05 2013 (UTC)