Wrapper around the Python serial module to control tosr0x USB relay boards.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore initial checkin May 2, 2013
LICENSE.txt Add license. May 29, 2015
MANIFEST.in Fix MANIFEST.in includes. Jun 2, 2015
README.md Add instructions for new relayCount kwarg to README. Jun 1, 2015
setup.py v0.5.2 Jun 2, 2015



A Python module for communicating with 'TOSR0x' relay controllers available at tinyosshop.com and other online retailers.

Supported Hardware


  • Detect TOSR0x USB and WiFi devices.
  • Set relay states.
  • Query relay states.
  • Query temperature (on supported models).


  • Python serial module (should be installed by default)


Use setup.py:

python setup.py install

If using Debian or a derivative (Ubuntu) additional USB permissions may be required:

Add the user to the 'dialout' group:

$ sudo usermod -G dialout -a <username>

Add a udev rules file to allow access to usb devices:

$ cat /etc/udev/rules.d/50-usb.rules
# allow access to usb devices for users in dialout group
SUBSYSTEM=="usb", MODE="0666", GROUP="dialout"


Call the handler function to return a list of tosr0x objects:

>import tosr0x
>th = tosr0x.handler()

Testing USB serial device on /dev/ttyUSB0
Testing USB serial device on /dev/ttyUSB1
Testing USB serial device on /dev/ttyUSB2
Testing USB serial device on /dev/ttyUSB3
TOSR0x device found on /dev/ttyUSB3

>myTosr0x = th[0]
>print myT0sr0x

<tosr0x.relayModule instance at 0xb68be46c>

By default the handler scans all USB ports for compatible tosr0x devices. You can also specify a range of ports to scan:

>th = tosr0x.handler(devicePath=['/dev/ttyUSB3'])

Testing USB serial device on /dev/ttyUSB3
TOSR0x device found on /dev/ttyUSB3

Usually all relays on the module are cycled at initialisation to determine the relay count. You can specify a relay count to prevent this:

>th = tosr0x.handler(devicePath=['/dev/ttyUSB3'], relayCount=4)

Testing USB serial device on /dev/ttyUSB3
TOSR0x device found on /dev/ttyUSB3

It is also possible to use the class directly without using the handler:

>import serial
>import tosr0x
>sd=serial.Serial('/dev/ttyUSB0', timeout=0.1)
>myTosr0x=tosr0x.relayModule(sd) #Num relays not specified in this example

>import tosr0x
>myTosr0x = tosr0x.relayModule( ('',2000), 2) #Module of 2 relays

Set relay states to either 0 or 1:



(Note: relay numbering starts at 1. Set the state of all relays by using relay number 0.)

Get relay positions, (returned as a dict {relay : state}):

{1: 1, 2: 0}

Get Ambient Temperaure n Celsius degree for modules supporting a temperature probe:



  • James Stewart (@amorphic) uses to tosr0x to implement an Environmental Controller in braubuddy, a temperature monitoring framework.
  • Alex Roche (@alexroche) is using tosr0x with WIFI option to control blinds through openremote controller running on a Raspberry Pi.