Skip to main content

TurnTouch Python library

This library provides support for the Turn Touch bluetooth smart home remote.

It is written in Python 3, originally for use with Home Assistant.

Usage

Install this library from PyPI:

pip install TurnTouch

Scanning for Turn Touch devices

Note: Scanning requires root privileges on Linux. To avoid this, skip to the next section and connect to the device without scanning.

import turntouch

# Example 1: Find all devices
devices = turntouch.scan()

# Example 2: Find just one device
device = turntouch.scan(only_one=True)[0]

# Example 3: Extend scan timeout to 60 seconds (default is 10)
devices = turntouch.scan(timeout=60)

turntouch.scan() returns a list of turntouch.TurnTouch objects. A connection is automatically opened to each device, so it is ready to use.

turntouch.TurnTouch is a subclass of bluepy.btle.Peripheral.

Interacting with a Turn Touch device

import turntouch

# Connect to a device by MAC address
tt = turntouch.TurnTouch('c0:ff:ee:c0:ff:ee')

# Read the device nickname and battery percentage
print("Name: {}\nBattery: {}".format(tt.name, tt.battery))

# Update the device nickname (max. 32 characters)
tt.name = 'Living Room Remote'

Listening for button presses

from turntouch import TurnTouch, DefaultActionHandler

class MyHandler(DefaultActionHandler):
    def action_north(self):
        print("Up button pressed.")
    def action_east_double_tap(self):
        print("Right button double-tapped.")
    def action_south_hold(self):
        print("Down button held.")

tt = TurnTouch('c0:ff:ee:c0:ff:ee')
tt.handler = MyHandler()
tt.listen_forever()

# One-liner alternative (same as listen_forever)
TurnTouch('c0:ff:ee:c0:ff:ee', handler=MyHandler(), listen=True)

See the Actions section for a full list of actions.

More advanced usage

Here's a more complex example, triggering some existing functions.

import turntouch

# Define a handler
class MyFancyHandler(turntouch.DefaultActionHandler):

    def __init__(some_object, other_function):
        """Use the __init__ method to pass references to parts of your code,
        such as objects, methods, or variables."""
        self.thing_1 = some_object
        self.other_func = other_function

    def action_any(action):
        """Special handler which is fired for ALL actions.
        `action` is an instance of turntouch.Action."""
        if action.name == "North":
            self.thing_1.some_method()
        elif action.name in ["South", "East", "West"]:
            self.thing_1.other_method()
        else:
            self.other_func()

    def action_south_hold():
        print("You can combine per-button handlers with action_any!")


# Instantiate the handler, passing some application data into it
my_handler = MyFancyHandler(some_object_from_my_application, a_function)

# Scan until we find a device
devices = []
while not devices:
    devices = turntouch.scan(only_one=True)
tt = devices[0]

# Assign the handler to your device.
tt.handler = my_handler

tt.listen_forever()

Listening for just one button press

If you don't want the listener to run forever, do this:

tt = TurnTouch('c0:ff:ee:c0:ff:ee', handler=SomeHandler)
tt.listen()  # Will return as soon as one action occurs.

Error handling

Connection failures will raise turntouch.TurnTouchException. You may want to catch and ignore this exception to retry connecting.

Actions

  • action_any
  • action_off
  • action_north
  • action_north_double_tap
  • action_north_hold
  • action_east
  • action_east_double_tap
  • action_east_hold
  • action_west
  • action_west_double_tap
  • action_west_hold
  • action_south
  • action_south_double_tap
  • action_south_hold
  • action_multi_north_east
  • action_multi_north_west
  • action_multi_north_south
  • action_multi_east_west
  • action_multi_east_south
  • action_multi_west_south
  • action_multi_north_east_west
  • action_multi_north_east_south
  • action_multi_north_west_south
  • action_multi_east_west_south
  • action_multi_north_east_west_south

Release files for TurnTouch 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for TurnTouch 0.4.3
File Size Uploaded
TurnTouch-0.4.3.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for TurnTouch 0.4.3
File Interpreter ABI Platform
TurnTouch-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / TurnTouch-0.4.3.tar.gz

Download URL TurnTouch-0.4.3.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
540ba6253cbe04b8bbac10663e1e9d80a043d823a8073de96637decffede59b1
BLAKE2b-256 checksum
How to use checksums
118c548fbe44abecd92f53ada6a00fba71488442a0996efee6219cdbc59d640a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / TurnTouch-0.4.3-py3-none-any.whl

Download URL TurnTouch-0.4.3-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1e56b2b917bdfbe46dc37ca64c15d822f6b7859d99d2cbcb67896b6e627696e
BLAKE2b-256 checksum
How to use checksums
26631fe833bf1a41280c529c4519587a8c6893f60e096372c0c8cafb8f340798
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.3 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4

2 release files

0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page