Skip to content

Fix RTW decoder off-by-one in command mapping (#664)#665

Open
mabt wants to merge 1 commit into
rstrouse:mainfrom
mabt:fix-rtw-decode-offset
Open

Fix RTW decoder off-by-one in command mapping (#664)#665
mabt wants to merge 1 commit into
rstrouse:mainfrom
mabt:fix-rtw-decode-offset

Conversation

@mabt

@mabt mabt commented Jun 5, 2026

Copy link
Copy Markdown

Fixes #664

Summary

The RTW protocol decoder remaps the command from the encKey byte. The current code uses encKey - 133 with condition encKey > 133, but the encoder values start at 133 (My), so:

  • 133 (My) doesn't even enter the RTW branch due to the strict > 133
  • 134 (Up) maps to cmd=1=My (wrong)
  • 136 (Down) maps to cmd=3=MyUp (wrong)

Fix

Change condition to >= 133 and offset to -132 (one-line fix in 2 chars).

After fix:

  • 133 → cmd=1=My ✓
  • 134 → cmd=2=Up ✓
  • 135 → cmd=3=MyUp ✓
  • 136 → cmd=4=Down ✓
  • 137 → cmd=5=MyDown ✓

Testing

Tested with ESP32-WROOM-32 + CC1101 V2.0 + 10 Mantion Italian motors (RTW 80-bit). Before the fix, pressing the wall remote incremented linkedRemote.lastRollingCode but shade.position / shade.target stayed unchanged. After the fix, pressing DOWN on the wall remote correctly sets target=100, direction=1, and the shade tracks position to 100 within ~20s.

Confirmed end-to-end: MQTT discovery to Home Assistant also receives the position update correctly, so the cover entity in HA syncs when wall remotes are used.

The RTW protocol decoder used `encKey - 133` to remap the command,
but the encoder uses encKey values starting at 133 (My), so the
correct offset is 132:

- My (encKey=133) → cmd 1 ✓ (previously: 0=Unknown0, unreachable since '> 133')
- Up (encKey=134) → cmd 2 ✓ (previously: 1=My)
- Down (encKey=136) → cmd 4 ✓ (previously: 3=MyUp)
- ...

Fixes: linked remote presses now correctly update shade position
on RTW motors (Mantion etc.).

Tested with ESP32-WROOM-32 + CC1101 V2.0 + 10x Mantion Italian
motors. Before: rolling code incremented but position stuck.
After: position updates correctly when wall remote is pressed.

Refs: rstrouse#664
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RTW protocol: linked remote presses decoded as wrong command (Up→My, Down→MyUp)

1 participant