Skip to main content

Asynchronous Python TCP Client for FlicHub

Get events from the FlicHub when a Flic/Twist Button is clicked and send them to home-assistant-flichub.

To be able to use this client you need to enable the Flic Hub SDK described on this page.

Create a new module and name it pyflichub-tcpclient (or any name) and paste the code found in tcpserver.js in the editor and press play. Check the box "Restart after crash or reboot."

This will open a TCP Server on port 8124 (configurable by changing PORT)

Usage

import asyncio
from pyflichub.client import FlicHubTcpClient
from pyflichub.button import FlicButton
from pyflichub.event import Event

def event_callback(button: FlicButton, event: Event):
    print(f"Received event: {event.event}")
    if button:
        print(f"Button: {button.name} ({button.bdaddr})")

    if event.event == 'button':
        print(f"Action: {event.action}")

def command_callback(cmd):
    print(f"Received command: {cmd.command}")

async def main():
    loop = asyncio.get_event_loop()
    client = FlicHubTcpClient(
        ip='192.168.1.100',
        port=8124,
        loop=loop,
        event_callback=event_callback,
        command_callback=command_callback
    )

    await client.async_connect()

    # Retrieve all buttons
    buttons = await client.get_buttons()
    print(f"Found {len(buttons)} buttons.")

    # Keep the connection alive
    while True:
        await asyncio.sleep(1)

if __name__ == '__main__':
    asyncio.run(main())

Emitted Events

The following events are explicitly dispatched to the event_callback provided during initialization:

  • button: Fired when a button interaction occurs (e.g. click, double-click, hold). Provides the action type in event.action ('down', 'up', 'single', 'double', 'hold', 'idle').
  • buttonAdded: Fired when a new button is paired to the hub. The library will automatically try to fetch its details in the background. The button argument to the callback may be None initially.
  • buttonDeleted: Fired when a button is unpaired/deleted.
  • buttonConnected: Fired when a button makes a physical connection to the hub.
  • buttonDisconnected: Fired when the connection to the button drops.
  • buttonReady: Fired when the button connection has been fully verified and is ready for use.
  • actionMessage: Fired when a Flic Hub Studio message action is executed (configured as a trigger in the Flic app).
  • virtualDeviceUpdate: Fired when a Flic Twist rotates to control a virtual device. Contains values in event.values (like brightness, volume, etc.).

Handling Twist Jitter/Sensitivity

When working with virtual device outputs mapping to Flic Twist, you may find the outputs to be twitchy or experience jitter. To resolve this, you can utilize the provided RateDetentController utility. This allows variable-speed adjusters with features like sticky neutral and debounce to smooth out inputs.

from pyflichub.twist_controller import RateDetentController

# Inside your application...
def on_volume_change(new_volume_pct):
    print(f"Setting volume to: {new_volume_pct}%")

# Create a controller once for the button
volume_controller = RateDetentController(
    cfg={"minOutPct": 0, "maxOutPct": 100},
    on_change_callback=on_volume_change
)

def event_callback(button: FlicButton, event: Event):
    if event.event == 'virtualDeviceUpdate':
        # Push raw values through the controller
        # Make sure you only pass value updates matching the button and device
        volume_controller.update_raw(event.values['volume'] * 100)

Disclaimer

This python library was not made by Flic. It is not official, not developed, and not supported by Flic.

Metadata

Release files for pyflichub-tcpclient 0.1.20

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

Source distribution (sdist)

Source distribution for pyflichub-tcpclient 0.1.20
File Size Uploaded Provenance Actions
pyflichub_tcpclient-0.1.20.tar.gz 24.6 kB Without provenance Details for pyflichub_tcpclient-0.1.20.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyflichub-tcpclient 0.1.20
File Interpreter ABI Platform Actions
pyflichub_tcpclient-0.1.20-py3-none-any.whl Python 3 none any Details for pyflichub_tcpclient-0.1.20-py3-none-any.whl

Total release size: 37.7 kB

Release files / pyflichub_tcpclient-0.1.20.tar.gz

Download URL pyflichub_tcpclient-0.1.20.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
518993546bce68039ae510493d07c88d15c667c5f9bbbe378d1dddcb8226c13a
BLAKE2b-256 checksum
How to use checksums
3d1ff4c2c3c343973b1a09ae2c819153a198070f7de5852983173f19d1679aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / pyflichub_tcpclient-0.1.20-py3-none-any.whl

Download URL pyflichub_tcpclient-0.1.20-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59afe690d83afad39153f156810cbdf83bfaa3a9608b3219c4be931be8f9ef4c
BLAKE2b-256 checksum
How to use checksums
1d3a2ea5ecfe6104ed6f3cfb27348c4eb43f17c61f9a6bd0cfe577861f1e26e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for pyflichub-tcpclient 0.1.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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