From 943dc524ea32b90998b7427ac400145552e7fe4a Mon Sep 17 00:00:00 2001 From: thirug010 <30732819+thirug010@users.noreply.github.com> Date: Thu, 11 Jul 2019 22:28:08 -0500 Subject: [PATCH 1/3] Update Code for Issue #6066- Dimmer Value not equal to Rx Dim State # Change Summary 1. Added Option to select Dimmer Range (1-100 and 1-255) through SetOption66 (default is 1-100 for legacy device support 2. Updated Dimmer code to set range based on the option66 100 / 225 --- sonoff/_changelog.ino | 3 +++ sonoff/settings.h | 4 ++-- sonoff/xdrv_16_tuyadimmer.ino | 22 +++++++++++++++++----- tools/decode-config.py | 6 ++++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 81d9f850b..84e14f132 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,4 +1,7 @@ /*********************************************************************************************\ + * 6.6.0.2 20190711 + * SetOption66 - Enable or Disable Dimmer range 255 slider control + * * 6.6.0.1 20190708 * Fix Domoticz battery level set to 100 if define USE_ADC_VCC is not used (#6033) * Change defines USE_TX20_WIND_SENSOR and USE_RC_SWITCH in my_user_config.h to disable to lower iram usage enabling latest core compilation (#6060, #6062) diff --git a/sonoff/settings.h b/sonoff/settings.h index 0fa7f5d48..8b593f9ec 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -78,8 +78,8 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages uint32_t no_power_feedback : 1; // bit 13 (v6.5.0.9) - SetOption63 - Don't scan relay power state at restart uint32_t use_underscore : 1; // bit 14 (v6.5.0.12) - SetOption64 - Enable "_" instead of "-" as sensor index separator - uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Dimmer slider control - uint32_t spare16 : 1; + uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Dimmer slider control + uint32_t tuya_dimmer_range_255 : 1; // bit 16 (v6.6.0.2) - SetOption66 - Enable or Disable Dimmer range 255 slider control uint32_t spare17 : 1; uint32_t spare18 : 1; uint32_t spare19 : 1; diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index 7f26e035c..f2328cc83 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -146,14 +146,20 @@ void LightSerialDuty(uint8_t duty) if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself if (Settings.flag3.tuya_show_dimmer == 0) { - - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); - + if(Settings.flag3.tuya_dimmer_range_255 == 0) + { + duty = round(duty * (100. / 255.)); + } + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty); } } else { tuya_ignore_dim = false; // reset flag if (Settings.flag3.tuya_show_dimmer == 0) { + if(Settings.flag3.tuya_dimmer_range_255 == 0) + { + duty = round(duty * (100. / 255.)); + } AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set } } @@ -211,8 +217,14 @@ void TuyaPacketProcess(void) AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; } - - tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); + if(Settings.flag3.tuya_dimmer_range_255 == 0) + { + tuya_new_dim = round(tuya_buffer[13]); + } + else + { + tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); + } if ((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { tuya_ignore_dim = true; diff --git a/tools/decode-config.py b/tools/decode-config.py index 0fe3e274c..aad3b4c74 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -923,7 +923,13 @@ Setting_6_5_0_15['flag3'][0].update ({ 'tuya_show_dimmer': (' Date: Fri, 12 Jul 2019 12:18:25 +0200 Subject: [PATCH 2/3] Update _changelog.ino --- sonoff/_changelog.ino | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 84e14f132..210331159 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,13 +1,11 @@ /*********************************************************************************************\ - * 6.6.0.2 20190711 - * SetOption66 - Enable or Disable Dimmer range 255 slider control - * * 6.6.0.1 20190708 * Fix Domoticz battery level set to 100 if define USE_ADC_VCC is not used (#6033) * Change defines USE_TX20_WIND_SENSOR and USE_RC_SWITCH in my_user_config.h to disable to lower iram usage enabling latest core compilation (#6060, #6062) * Add blend RGB leds with White leds for better whites (#5895, #5704) * Add command SetOption41 0..8 to control number of Tuya switches (#6039) * Add command SetOption42 0..255 to set overtemperature (Celsius only) threshold resulting in power off all on energy monitoring devices. Default setting is 90 (#6036) + * Add command SetOption66 0/1 to enable or disable Tuya dimmer range 255 slider control * Add command Time to disable NTP and set UTC time as Epoch value if above 1451602800 (=20160101). Time 0 re-enables NTP (#5279) * Add AZ7798 automatic setting of clock display (#6034) * Add Epoch and UptimeSec to JSON messages (#6068) From 1f895854c2b32f91689e656c68dcfc77d0b863bf Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 12 Jul 2019 12:20:44 +0200 Subject: [PATCH 3/3] Update decode-config.py --- tools/decode-config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/decode-config.py b/tools/decode-config.py index aad3b4c74..3dfd1b500 100755 --- a/tools/decode-config.py +++ b/tools/decode-config.py @@ -923,13 +923,13 @@ Setting_6_5_0_15['flag3'][0].update ({ 'tuya_show_dimmer': ('