From daf2ef2937e066b67b66f7b8f5aeefdef5a20b62 Mon Sep 17 00:00:00 2001 From: cjkas Date: Thu, 19 Mar 2026 08:13:55 +0100 Subject: [PATCH] 5 --- src/Somfy.cpp | 19 +++++++++++++++---- src/Somfy.h | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Somfy.cpp b/src/Somfy.cpp index 0b5eff1..946905d 100644 --- a/src/Somfy.cpp +++ b/src/Somfy.cpp @@ -1447,9 +1447,9 @@ void SomfyRoom::unpublish() { } void SomfyShade::publishState() { if(mqtt.connected()) { - this->publish("position", this->transformPosition(this->currentPos), true); - this->publish("direction", this->direction, true); - this->publish("target", this->transformPosition(this->target), true); + this->publish("position", (uint8_t)50, true); + this->publish("direction", (int8_t)0, true); + this->publish("target", (uint8_t)50, true); this->publish("lastRollingCode", this->lastRollingCode); this->publish("mypos", this->transformPosition(this->myPos), true); this->publish("myTiltPos", this->transformPosition(this->myTiltPos), true); @@ -1796,7 +1796,7 @@ bool SomfyGroup::publish(const char *topic, bool val, bool retain) { float SomfyShade::p_currentPos(float pos) { float old = this->currentPos; this->currentPos = pos; - if(floor(old) != floor(pos)) this->publish("position", this->transformPosition(static_cast(floor(this->currentPos)))); + if(floor(old) != floor(pos)) this->publish("position", (uint8_t)50); return old; } float SomfyShade::p_currentTiltPos(float pos) { @@ -2894,6 +2894,17 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz // This sendCommand function will always be called externally. sendCommand at the remote level // is expected to be called internally when the motor needs commanded. if(this->bitLength == 0) this->bitLength = somfy.transceiver.config.type; + // If same direction command sent while already moving, stop the state tracking. + // The real motor stops on its own when it receives the same direction again. + if((cmd == somfy_commands::Up && this->direction == -1) || + (cmd == somfy_commands::Down && this->direction == 1)) { + Serial.println("Same command as dir"); + SomfyRemote::sendCommand(cmd, repeat); + this->p_target(this->currentPos); + this->p_tiltTarget(this->currentTiltPos); + this->setMovement(0); + return; + } if(cmd == somfy_commands::Up) { if(this->tiltType == tilt_types::euromode) { // In euromode we need to long press for 2 seconds on the diff --git a/src/Somfy.h b/src/Somfy.h index b9e54a3..3c1aac5 100644 --- a/src/Somfy.h +++ b/src/Somfy.h @@ -31,9 +31,9 @@ enum class radio_proto : byte { // Ordinal byte 0-255 enum class somfy_commands : byte { Unknown0 = 0x0, My = 0x2,//DOWN - Up = 0x3, + Up = 0x1, MyUp = 0x4, //up - Down = 0x1, + Down = 0x3, MyDown = 0x5, UpDown = 0x6, MyUpDown = 0x7,