Making rolling-code blinds scriptable
Three Somfy RTS blinds that only listened to their own remote. Now a server opens them at sunrise and closes them at sunset. This page has everything you need to build the same thing, plus the bugs I hit along the way.
- Status
- Running on USB power
- Build time
- One day
- Parts
- About $29
- Next
- Battery firmware
How it works
Somfy RTS remotes talk on 433.42 MHz and use a rolling code, so every button press carries a counter that only goes up. A recording of one press won't work again. The blind has already seen that count.
The way around it is to pair a new remote. An RTS motor can remember several remotes, each with its own address and counter. So an ESP32 and a 433 MHz radio become one more remote, paired the normal way, and they keep their own counter.
The ESP32 runs ESPSomfy-RTS, an open-source firmware with a web page, an HTTP API and MQTT. A small Linux server works out the sun times each day and sends MQTT commands at the right minute.
What you need
| Part | Notes |
|---|---|
| ESP32 dev board | A plain ESP32 with USB. ESPSomfy also has builds for the S2, S3 and C3, but this guide's pins and file are for the plain ESP32. I used a 3-pack of USB-C boards for about $20, so there are spares to test on. |
| CC1101 module, 433 MHz | About $9. The 868 and 915 MHz versions look the same, so check that the board or its crystal says 433. |
| 8 female-to-female jumpers | Both boards have header pins, so no soldering is needed. |
| A working RTS remote | You need it to put each blind into pairing mode. Mine is a Telis 4 RTS. |
| Something always on | For the schedule: a Raspberry Pi or any Linux box. Optional. ESPSomfy has its own web page and buttons. |
A LoRa board like the Heltec V4 can't do this job. Its SX1262 radio can't send the simple on-off signal RTS uses, and its antenna is tuned for 915 MHz.
1. Wire the radio
These are ESPSomfy's default pins, except for GDO2. Read the warning below the table before you wire it.
| CC1101 | ESP32 |
|---|---|
| VCC | 3V3 (never 5V) |
| GND | GND |
| SCK | GPIO 18 |
| MOSI | GPIO 23 |
| MISO | GPIO 19 |
| CSN | GPIO 5 |
| GDO0 (TX) | GPIO 13 |
| GDO2 (RX) | GPIO 27 |
Don't put GDO2 on GPIO 12. GPIO 12 is a boot pin on the ESP32: if it's high at power-up, the chip runs its flash at 1.8 V and can't read it. The CC1101 holds that line high. My board booted fine until I saved the radio settings, then it rebooted over and over with invalid header: 0xffffffff. Moving that one wire to GPIO 27 fixed it.
2. Flash ESPSomfy-RTS
Download SomfyController.onboard.esp32.bin.zip from the ESPSomfy-RTS releases (I used v2.4.6) and unzip it. Plug in the board and flash the .bin at address 0:
pipx install esptool
esptool --port /dev/ttyUSB0 --baud 115200 write-flash 0x0 SomfyController.onboard.esp32.bin
Set the baud rate yourself. At the default speed, esptool couldn't start its loader on my board. 115200 and 230400 both worked.
A PSRAM error on the serial console at boot is harmless. These boards don't have PSRAM.
3. Wi-Fi and radio settings
- Join the board's hotspot,
ESPSomfyRTS, openhttp://192.168.4.1, and enter your Wi-Fi details. - Find the board's new address in your router's list of connected devices, and open it in a browser.
- In the Radio tab, set the pins from the table above, with RX on 27. Save. The log should say the radio was set up.
- Set TX power to the maximum, 12 dBm.
At 10 dBm, the pairing signal got through but up and down did nothing. The pairing signal repeats a lot, which is probably why it worked. At 12 dBm the blind moved. If it's still flaky, move the board closer or add a better 433 MHz antenna.
4. Pair each blind
- Add a shade in ESPSomfy. Each one gets its own remote address.
- Pick that blind's channel on your existing remote. Hold its PROG button until the blind jogs up and down. The motor is now listening for a new remote.
- In ESPSomfy, open that shade, choose Pair Shade, and press its Prog button once. When the blind jogs, confirm in the dialog that it moved.
- Test up and down from the web page. Then do the next blind.
Press Prog only once per blind. Prog toggles: if the blind already knows this remote, a second press removes it.
Without the JSON header, the board answers "No shade object supplied."
One blind always missed single commands, even from the original remote. Sending each command 8 times fixed it, and later I set all three to 8. Version 2.4.6 has no repeat setting in the web page, so I set it through the API:
# try it once
curl -X PUT http://BOARD/shadeCommand -H 'Content-Type: application/json' \
-d '{"shadeId":3,"command":"down","repeat":8}'
# make it stick: read the shade, change "repeats" to 8, save it back
curl "http://BOARD/shade?shadeId=3" > shade.json
# edit shade.json, then:
curl -X PUT http://BOARD/saveShade -H 'Content-Type: application/json' -d @shade.json
5. Open at sunrise, close at sunset
In ESPSomfy's MQTT settings, enter your broker's address, a user and password, and a root topic. I used ESPSomfy as the root, and the examples below assume that. To move a blind, publish to its direction/set topic: -1 is up, 1 is down.
mosquitto_pub -h BROKER -u sched -P "$PASS" -q 0 \
-t ESPSomfy/shades/1/direction/set -m 1
Never send these commands as retained messages. The board replays retained commands whenever it reconnects, so a blind would move by itself after a Wi-Fi drop.
The broker is Mosquitto. Anonymous access is off, an ACL keeps each user to the ESPSomfy/ topics, and it only listens on the home network and on localhost.
The scheduler is one Python file. A daily systemd timer plans the day, and each event gets its own one-time timer. I didn't use a sun-times library. It uses NOAA's general solar formulas (zenith 90.833°), which take about twenty lines. Each night at 12:05 am, and at boot, it plans the day. For example:
systemd-run --user --collect --unit blinds-open-all-20261021 \
--on-calendar "2026-10-21 07:30:00 EDT" blinds.py run open-all
The events live in a small JSON file, like this:
{
"open-all": {"at": "sunrise", "direction": "up", "shades": [1, 2, 3]},
"close-one": {"at": "sunset", "direction": "down", "shades": [1]}
}
Before an event runs, it checks two things:
- If the timer fires more than 30 minutes late (say the server was down), the event is skipped. Blinds opening at noon are worse than blinds that stay shut.
- If the board isn't online on MQTT, nothing is sent.
Either way, I get a text, so a missed event never goes unnoticed.
Part two: battery power
The board needs USB power today, and I don't want a cable running to a window. So I'm writing my own firmware that sleeps between events and runs for months on one battery. The server keeps the schedule and the board just wakes up, sends what's due, and goes back to sleep.
- RTS encoder, checked against Legion2/Somfy_Remote_Lib, pulse for pulse, on about 21,000 test cases
- CC1101 setup, sending through the ESP32's RMT peripheral
- Sleep and wake loop, with rolling codes saved before every send
- Measure sleep current on a spare board
- Bypass the board's regulator and take off the power LED (as shipped, the regulator and LED alone would drain the battery in a few weeks)
- Re-pair the three blinds to the new board
The code, tests and full design notes are on GitHub: punctuatedoxygen/blinds-fw. To run the tests, clone the repo and run make test. You need a C++ compiler and git: the test clones the reference library.
Log
- Confirmed the blinds are Somfy RTS. Found out the LoRa board can't drive them. Ordered an ESP32 3-pack and a CC1101.
- Wired the board and flashed ESPSomfy. Fixed the boot loop by moving GDO2 off GPIO 12.
- Paired all three blinds. Raised TX power to 12 dBm and set every blind to send each command 8 times.
- Schedule live. That evening, the first scheduled sunset close ran on its own.
- Battery firmware started. The RTS encoder matches the reference library on every test case. Published to GitHub.
Want something like this built for a device of yours? tanner@staus.dev