From 2d94b7cc7c81129cdabd06087f4bbccc38f9d92e Mon Sep 17 00:00:00 2001 From: Joel Stein Date: Thu, 1 Nov 2018 00:13:46 +0100 Subject: [PATCH] tuya: Autoconfigure Dimmer ID when SetOption34 == 0, use 0 as default for TUYA_DIMMER_ID --- sonoff/my_user_config.h | 2 +- sonoff/sonoff_post.h | 2 +- sonoff/xdrv_16_tuyadimmer.ino | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) mode change 100755 => 100644 sonoff/sonoff_post.h diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h index 5b721af2a..3c946f7ad 100644 --- a/sonoff/my_user_config.h +++ b/sonoff/my_user_config.h @@ -354,7 +354,7 @@ //#define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop #define MP3_VOLUME 10 // Set the startup volume on init, the range can be 0..30(max) #define USE_TUYA_DIMMER // Add support for Tuya Serial Dimmer - #define TUYA_DIMMER_ID 3 // Default dimmer Id + #define TUYA_DIMMER_ID 0 // Default dimmer Id // Power monitoring sensors ----------------------- #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h old mode 100755 new mode 100644 index b6fea83a2..7498d40e9 --- a/sonoff/sonoff_post.h +++ b/sonoff/sonoff_post.h @@ -104,7 +104,7 @@ void KNX_CB_Action(message_t const &msg, void *arg); #define USE_MP3_PLAYER // Use of the DFPlayer Mini MP3 Player RB-DFR-562 commands: play, volume and stop #define MP3_VOLUME 10 // Set the startup volume on init, the range can be 0..30(max) #define USE_TUYA_DIMMER // Add support for Tuya Serial Dimmer - #define TUYA_DIMMER_ID 3 // Default dimmer Id + #define TUYA_DIMMER_ID 0 // Default dimmer Id #define USE_PZEM004T // Add support for PZEM004T Energy monitor (+2k code) #define USE_PZEM_AC // Add support for PZEM014,016 Energy monitor (+1k1 code) #define USE_PZEM_DC // Add support for PZEM003,017 Energy monitor (+1k1 code) diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index 91fe17581..896db72ed 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -20,7 +20,7 @@ #ifdef USE_TUYA_DIMMER #ifndef TUYA_DIMMER_ID -#define TUYA_DIMMER_ID 3 +#define TUYA_DIMMER_ID 0 #endif #define TUYA_BUFFER_SIZE 256 @@ -128,6 +128,12 @@ void TuyaPacketProcess() snprintf_P(log_data, sizeof(log_data), PSTR("TYA: Rcvd Dim State=%d"), tuya_buffer[13]); AddLog(LOG_LEVEL_DEBUG); + if (!Settings.param[P_TUYA_DIMMER_ID]) { + snprintf_P(log_data, sizeof(log_data), PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); + AddLog(LOG_LEVEL_DEBUG); + Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; + } + tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); if((power) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 2)) {