From f632dc9c54b1abc1fb1001b3f9b0f9cd733c0c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 29 May 2023 15:14:30 +0200 Subject: [PATCH 1/3] Somfy: add initial sun awnings support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- Somfy.cpp | 14 ++++++++++++++ Somfy.h | 3 ++- data/index.html | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Somfy.cpp b/Somfy.cpp index 0397ea2..79251db 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -147,6 +147,12 @@ void somfy_frame_t::decodeFrame(byte* frame) { case 140: this->cmd = somfy_commands::Prog; break; + case 141: + this->cmd = somfy_commands::SunFlag; + break; + case 142: + this->cmd = somfy_commands::Flag; + break; } } this->rollingCode = decoded[3] + (decoded[2] << 8); @@ -280,6 +286,12 @@ void somfy_frame_t::encodeFrame(byte *frame) { case somfy_commands::Prog: frame[0] = 140; break; + case somfy_commands::SunFlag: + frame[0] = 141; + break; + case somfy_commands::Flag: + frame[0] = 142; + break; } } else { @@ -1420,6 +1432,8 @@ bool SomfyShade::fromJSON(JsonObject &obj) { this->shadeType = shade_types::drapery; else if(strncmp(obj["shadeType"].as(), "blind", 5) == 0) this->shadeType = shade_types::blind; + else if(strncmp(obj["shadeType"].as(), "awning", 7) == 0) + this->shadeType = shade_types::awning; } else { this->shadeType = static_cast(obj["shadeType"].as()); diff --git a/Somfy.h b/Somfy.h index 07455f9..def21cc 100644 --- a/Somfy.h +++ b/Somfy.h @@ -36,7 +36,8 @@ enum class somfy_commands : byte { enum class shade_types : byte { roller = 0x00, blind = 0x01, - drapery = 0x02 + drapery = 0x02, + awning = 0x03, }; enum class tilt_types : byte { none = 0x00, diff --git a/data/index.html b/data/index.html index df71abf..30be104 100644 --- a/data/index.html +++ b/data/index.html @@ -240,6 +240,7 @@ + From 8ed53469922e0d3aee3ccf7c973627d7be3aea8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 29 May 2023 16:02:26 +0200 Subject: [PATCH 2/3] Somfy: add Sun status command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- Somfy.cpp | 7 ++++++- Somfy.h | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Somfy.cpp b/Somfy.cpp index 79251db..c3430d0 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -91,6 +91,8 @@ String translateSomfyCommand(const somfy_commands cmd) { return "Step Up"; case somfy_commands::StepDown: return "Step Down"; + case somfy_commands::Status: + return "Status"; default: return "Unknown(" + String((uint8_t)cmd) + ")"; } @@ -173,9 +175,12 @@ void somfy_frame_t::decodeFrame(byte* frame) { case somfy_commands::SunFlag: case somfy_commands::Flag: break; + case somfy_commands::Status: + this->rollingCode = 0; + this->sun = !!(decoded[3] & STATUS_SUN); + break; case somfy_commands::UnknownC: case somfy_commands::UnknownD: - case somfy_commands::UnknownE: case somfy_commands::RTWProto: this->valid = false; break; diff --git a/Somfy.h b/Somfy.h index def21cc..a6d77ee 100644 --- a/Somfy.h +++ b/Somfy.h @@ -28,7 +28,7 @@ enum class somfy_commands : byte { StepDown = 0xB, UnknownC = 0xC, UnknownD = 0xD, - UnknownE = 0xE, // This command byte has been witnessed in the wild but cannot tell if it is from Somfy. No rolling code is sent with this and it is 56-bits. + Status = 0xE, RTWProto = 0xF, // RTW Protocol // Command extensions for 80 bit frames StepUp = 0x8B @@ -52,6 +52,12 @@ somfy_commands translateSomfyCommand(const String& string); #define MAX_RX_BUFFER 3 #define MAX_TX_BUFFER 3 +#if !defined(BIT) +#define BIT(x) (1 << (x)) +#endif /* BIT */ + +#define STATUS_SUN BIT(1) + typedef enum { waiting_synchro = 0, receiving_data = 1, @@ -110,6 +116,7 @@ typedef struct somfy_frame_t { uint32_t await = 0; uint8_t bitLength = 56; uint16_t pulseCount = 0; + bool sun = false; void print(); void encodeFrame(byte *frame); void decodeFrame(byte* frame); From 17102a1a7d954eee370ab510c839531572babd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 29 May 2023 18:33:43 +0200 Subject: [PATCH 3/3] Somfy: improve status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- Somfy.cpp | 2 +- Somfy.h | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Somfy.cpp b/Somfy.cpp index c3430d0..e59a6eb 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -177,7 +177,7 @@ void somfy_frame_t::decodeFrame(byte* frame) { break; case somfy_commands::Status: this->rollingCode = 0; - this->sun = !!(decoded[3] & STATUS_SUN); + this->status = decoded[3]; break; case somfy_commands::UnknownC: case somfy_commands::UnknownD: diff --git a/Somfy.h b/Somfy.h index a6d77ee..e64a565 100644 --- a/Somfy.h +++ b/Somfy.h @@ -52,12 +52,6 @@ somfy_commands translateSomfyCommand(const String& string); #define MAX_RX_BUFFER 3 #define MAX_TX_BUFFER 3 -#if !defined(BIT) -#define BIT(x) (1 << (x)) -#endif /* BIT */ - -#define STATUS_SUN BIT(1) - typedef enum { waiting_synchro = 0, receiving_data = 1, @@ -100,6 +94,11 @@ typedef struct somfy_tx_queue_t { bool pop(somfy_tx_t *tx); bool push(uint32_t await, somfy_commands cmd, uint8_t repeats); }; + +typedef enum { + no_sun = 0, + sun = 2 +} somfy_status_t; typedef struct somfy_frame_t { bool valid = false; bool processed = false; @@ -116,7 +115,7 @@ typedef struct somfy_frame_t { uint32_t await = 0; uint8_t bitLength = 56; uint16_t pulseCount = 0; - bool sun = false; + somfy_status_t status = no_sun; void print(); void encodeFrame(byte *frame); void decodeFrame(byte* frame);