Skip to main content

Python library for local control of Somfy SDN shades

Project description

Somfy SDN protocol support

This library implements Somfy SDN protocol used to control Somfy RS-485 connected blinds and shades. It can also control Somfy SDN keypads, and it can be straightforwardly extended to support other types of SDN devices.

Using the library

The library supports both directly-connected RS-485 adapters (typically implemented as USB-serial adapters), and connections via Ethernet-to-Serial converters. The library properly implements the timing restrictions specified in the SDN Integration Guide, with full asyncio support.

To use the library, create a connection factory, a connector, and then exchange the messages:

from somfy import SocketConnectionFactory, SomfyConnector
ch = SocketConnectionFactory(host=host, port=port)
async with SomfyConnector(ch) as conn:
    await conn.exchange(...)
    await conn.exchange(...)
    await conn.exchange(...)

The channel (socket or serial) is physically opened in the context manager's __aenter__ and freed in the __aexit__, there is no support for reconnection. Alternatively, start and stop methods can be used to control the connection.

If the socket is closed or the serial device becomes unavailable, you need to close the SomfyConnector, and then create a new one. Alternatively, you can use automatically reconnecting ReconnectingSomfyConnector. It will automatically reconnect the channel if it's closed, but it will NOT retry any failed exchange calls.

SomfyConnector is stateless, but it launches a background task that drains the data from the SDN bus. You can optionally specify a sniffer_callback that will be called each time the "drainer" task recognizes a valid SDN message. The drainer task is paused during the message exchanges.

Tools

There are several tools provided both as an example and as simple SDN management tools.

decode.py

This is a simple decoder for SDN messages. The input must be binhex-formatted, you can use stdin or a file. The output can be in the form of text, json, and Python dicts.

$ echo "cef07f39c2ec808080ffff28c5088f\nf3f4ff80808039c2ec064d" | ./decode.py
ID: 31(POST_MOTOR_LIMITS) FROM: 08(TYPE_50DC_SERIES) 133DC6 TO: 00(TYPE_ALL) 7F7F7F ACK: False DATA: {'reserved': 0, 'limit': 15063}
ID: 0C(GET_MOTOR_POSITION) FROM: 00(TYPE_ALL) 7F7F7F TO: 00(TYPE_ALL) 133DC6 ACK: False DATA: {}

sdntool.py

This tool can be used to detect devices in the SDN network, and to control shades.

Detecting:

$ ./sdntool.py --tcp 192.168.20.32:1226 detect
133DC6	TYPE_50DC_SERIES

Getting information about a device:

$ ./sdntool.py --tcp 192.168.20.32:1226 info --addr 133DC6
Rotation direction	STANDARD
Limit (in pulses)	14930
Position pulses	1492
Position percent	10
Tilt percent	255
Tilt degrees	-1
Intermediate Position	-1

Commanding a device:

$ ./sdntool.py --tcp 192.168.20.32:1226 move --addr 133DC6 --percent 44
Position: 38% (pulses: 5717), IP=-1
Position: 42% (pulses: 6312), IP=-1
Position: 44% (pulses: 6538), IP=-1
Position: 44% (pulses: 6570), IP=-1
Position: 44% (pulses: 6570), IP=-1
Position: 44% (pulses: 6570), IP=-1
Position: 44% (pulses: 6570), IP=-1

sniffer.py

This tool can be used to passively listen on the RS-485 bus, it supports JSON, text, and dict output.

Information sources

Documentation

This library was started first based on information gleaned from reverse-engineering the protocol by observing the communication between Somfy-provided tools and Somfy shades. This information was used to make the https://github.com/Cyberax/ZunoSomfy project, to build a hardware device to control the shades. They worked relatively well, but ZWave has its own problems, so I decided to add support to HomeAssistant directly.

So this is how this library got developed. After a couple of days of research, I found that Somfy has published an integration guide that describes the SDN protocol. The document is publicly available, but it's copyrighted. You can find it by this number: DOC155888/002 ("Integration Guide"), at the time of the writing it is available at: https://service.somfy.com/downloads/bui_v4/sdn-integration-guide-rev.002.pdf

Somfy Tools

Somfy provides downloads for several tools at: https://www.somfypro.com/services-support/software

The tools of interest are Somfy Digital Network™ (SDN) Motor Configuration Software 5.1 and SDN Configuration Tool Version: 1.2.4.2. These tools can be used for straightforward protocol reverse-engineering (i.e. add a sniffer to the bus, perform an action inside the software and observe the result), and the SDN Configuration Tool additionally provides a helpful Analyze feature that shows decoded traces of the bus traffic.

Short protocol description

The protocol is a bit convoluted, but it's not complicated. The message frames are 11 to 32 bytes long, and are transmitted on the RS-485 bus at 4800bps, with an odd parity bit, 8 data bits and 1 start/stop bit. The minimum interval between messages transmitted by the master node is 25ms. The reply timeout for devices is 280ms.

The node addresses are 3 byte-long. The broadcast address ix FFFFFF, the MASTER node is typically 7F7F7F. A typical exchange starts with SET/GET_.... message sent by the MASTER node, to which the destination node (or nodes) reply with the appropriate POST_... messages.

The format of the message serialization is documented in somfy/messages.py. One thing to note, is that message bytes are bitwise-inverted prior to computing the checksum and sending them.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_somfy-1.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

python_somfy-1.1.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file python_somfy-1.1.0.tar.gz.

File metadata

  • Download URL: python_somfy-1.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for python_somfy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6088ad4721eaf53f7feff1da004cb02bb3b5d47901415665a449fff1e52e2215
MD5 0b90e0cae14bf42ca73a6dd12398ee29
BLAKE2b-256 bd9846ac876a42ef089463e2c0a5db4651ce20abd26c606fb2ba30b20b7b97b5

See more details on using hashes here.

File details

Details for the file python_somfy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_somfy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for python_somfy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61d79f81935649ceb05d47d505d1643a2194e0a44728b9ba16beaf34472b46d1
MD5 88051d51a6bd5780e8e377b685ffe63d
BLAKE2b-256 21d832ff65583b05bf6f566d464cb590afac4fba3b20abfe33897486bdef023e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page