Welcome to hut2’s documentation!


hut2.protocol module

class hut2.protocol.HUT2(user=b'admin', password=b'anel')[source]

ANEL HUT2 Driver

Power relay switch with 8 channels, and 8 channels general purpose IO.

  • Relay and IO indices start with 1.
  • Commands tend to keep the device busy for a while.
    Pace them, read back the status after a while and retry them.
  • Some commands sometimes return a status update. Since they are UDP,
    neither commands nor replies are guaranteed to arrive.
  • user – Device user name (bytes)
  • password – Device password (bytes)
classmethod connect(host, port=7500, local_addr=('', 7700), loop=None, **kwargs)[source]

Connect to a Anel HUT2 via UDP

  • host – IO or host name of the device
  • port – UDP port on the device. Default is 7500 (unprivileged) as opposed to 75 (privileged). Ensure this is set correctly in the web interface.
  • local_addr – Tuple of local address (or hostname) and UDP port. Default is (“”, 7500) (broadcast, unprivileged). The device default is to reply to port 75 (privileged). Ensure this is set correctly in the web interface.

HUT2 instance connected to the device


Called when the connection is lost or closed.

The argument is an exception object or None (the latter meaning a regular EOF is received or the connection was aborted or closed).


Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

datagram_received(data, addr)[source]

Called when some datagram is received.


Execute a command.

Parameters:(bytes) (cmd) – Command

Get a status update.

This is a coroutine that performs the status query and returns the result.

Returns:Status with the parsed fields

Set all IO lines.

Parameters:(int) (ios) – Bitmask of the IO state

Turn an IO off

Parameters:(int) (switch) – IO line index

Turn an IO on.

Parameters:(int) (io) – IO line index

Query device status and settings.

st_off(switch, delay)[source]

Turn a relay off after a delay

  • (int) (delay) – Relay index
  • (int) – Delay in seconds

Set all relays.

Parameters:switches – Bitmask of the relay settings

Turn a relay off

Parameters:(int) (switch) – Relay index

Turn a relay on

Parameters:(int) (switch) – Relay index

Return a new status message.

This returns a future.

Returns:Status with the parsed fields
class hut2.protocol.Status[source]

HUT2 Status message parser and representation

classmethod from_bytes(data, time=None)[source]

Parse status message and return a namedtuple of the fields

Indices and tables