mirror of https://github.com/arendst/Tasmota.git
Optimized behavior to publish shutter data with sensor request (#22353)
* avoid shutter sensor data published ever * avoid shutter data report on sensor trigger
This commit is contained in:
parent
73897ef755
commit
fd37801d53
|
@ -195,6 +195,7 @@ struct SHUTTERGLOBAL {
|
||||||
bool callibration_run = false; // if true a callibration is running and additional measures are captured
|
bool callibration_run = false; // if true a callibration is running and additional measures are captured
|
||||||
uint8_t stopp_armed = 0; // Count each step power usage is below limit of 1 Watt
|
uint8_t stopp_armed = 0; // Count each step power usage is below limit of 1 Watt
|
||||||
uint16_t cycle_time = 0; // used for shuttersetup to get accurate timing
|
uint16_t cycle_time = 0; // used for shuttersetup to get accurate timing
|
||||||
|
bool sensor_data_reported = false; // ensure that shutter sensor data reported every sedond is only reported if shutter is moving and there is a change.
|
||||||
} ShutterGlobal;
|
} ShutterGlobal;
|
||||||
|
|
||||||
#define SHT_DIV_ROUND(__A, __B) (((__A) + (__B)/2) / (__B))
|
#define SHT_DIV_ROUND(__A, __B) (((__A) + (__B)/2) / (__B))
|
||||||
|
@ -946,7 +947,7 @@ void ShutterRelayChanged(void)
|
||||||
|
|
||||||
void ShutterReportPosition(bool always, uint32_t index)
|
void ShutterReportPosition(bool always, uint32_t index)
|
||||||
{
|
{
|
||||||
Response_P(PSTR("{"));
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
uint32_t n = TasmotaGlobal.shutters_present;
|
uint32_t n = TasmotaGlobal.shutters_present;
|
||||||
uint8_t shutter_running = 0;
|
uint8_t shutter_running = 0;
|
||||||
|
@ -958,7 +959,7 @@ void ShutterReportPosition(bool always, uint32_t index)
|
||||||
|
|
||||||
// Allow function exit if nothing to report (99.9% use case)
|
// Allow function exit if nothing to report (99.9% use case)
|
||||||
if (!always && !shutter_running) return;
|
if (!always && !shutter_running) return;
|
||||||
|
Response_P(PSTR("{"));
|
||||||
if( index != MAX_SHUTTERS_ESP32) {
|
if( index != MAX_SHUTTERS_ESP32) {
|
||||||
i = index;
|
i = index;
|
||||||
n = index+1;
|
n = index+1;
|
||||||
|
@ -976,7 +977,7 @@ void ShutterReportPosition(bool always, uint32_t index)
|
||||||
uint32_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
uint32_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||||
uint32_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
uint32_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||||
ResponseAppend_P(JSON_SHUTTER_POS, i + 1, (ShutterSettings.shutter_options[i] & 1) ? 100 - position : position, Shutter[i].direction,(ShutterSettings.shutter_options[i] & 1) ? 100 - target : target, Shutter[i].tilt_real_pos );
|
ResponseAppend_P(JSON_SHUTTER_POS, i + 1, (ShutterSettings.shutter_options[i] & 1) ? 100 - position : position, Shutter[i].direction,(ShutterSettings.shutter_options[i] & 1) ? 100 - target : target, Shutter[i].tilt_real_pos );
|
||||||
}
|
}
|
||||||
ResponseJsonEnd();
|
ResponseJsonEnd();
|
||||||
if (always || shutter_running) {
|
if (always || shutter_running) {
|
||||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); // RulesProcess() now re-entry protected
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_STAT, PSTR(D_PRFX_SHUTTER)); // RulesProcess() now re-entry protected
|
||||||
|
@ -1196,6 +1197,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos)
|
||||||
Shutter[i].target_position = target_pos;
|
Shutter[i].target_position = target_pos;
|
||||||
Shutter[i].start_position = Shutter[i].real_position;
|
Shutter[i].start_position = Shutter[i].real_position;
|
||||||
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||||
|
ShutterGlobal.sensor_data_reported = false;
|
||||||
ShutterAllowPreStartProcedure(i);
|
ShutterAllowPreStartProcedure(i);
|
||||||
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
||||||
|
|
||||||
|
@ -2330,18 +2332,24 @@ bool Xdrv27(uint32_t function)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
if (!ShutterGlobal.sensor_data_reported) {
|
||||||
ResponseAppend_P(",");
|
ShutterGlobal.sensor_data_reported = true;
|
||||||
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||||
position = (ShutterSettings.shutter_options[i] & 1) ? 100 - position : position;
|
ResponseAppend_P(",");
|
||||||
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||||
target = (ShutterSettings.shutter_options[i] & 1) ? 100 - target : target;
|
position = (ShutterSettings.shutter_options[i] & 1) ? 100 - position : position;
|
||||||
ResponseAppend_P(JSON_SHUTTER_POS, i + 1, position, Shutter[i].direction, target, Shutter[i].tilt_real_pos );
|
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||||
#ifdef USE_DOMOTICZ
|
target = (ShutterSettings.shutter_options[i] & 1) ? 100 - target : target;
|
||||||
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
ResponseAppend_P(JSON_SHUTTER_POS, i + 1, position, Shutter[i].direction, target, Shutter[i].tilt_real_pos );
|
||||||
DomoticzSensor(DZ_SHUTTER, position);
|
if (Shutter[i].direction != 0) {
|
||||||
|
ShutterGlobal.sensor_data_reported = false;
|
||||||
|
}
|
||||||
|
#ifdef USE_DOMOTICZ
|
||||||
|
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
||||||
|
DomoticzSensor(DZ_SHUTTER, position);
|
||||||
|
}
|
||||||
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_SET_POWER:
|
case FUNC_SET_POWER:
|
||||||
|
|
|
@ -52,6 +52,7 @@ int32_t current_stop_way = 0;
|
||||||
int32_t next_possible_stop_position = 0;
|
int32_t next_possible_stop_position = 0;
|
||||||
int32_t current_real_position = 0;
|
int32_t current_real_position = 0;
|
||||||
int32_t current_pwm_velocity = 0;
|
int32_t current_pwm_velocity = 0;
|
||||||
|
bool sensor_data_reported = false;
|
||||||
|
|
||||||
const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM =
|
const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM =
|
||||||
"<tr><td colspan=2>"
|
"<tr><td colspan=2>"
|
||||||
|
@ -772,6 +773,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos)
|
||||||
Shutter[i].target_position = target_pos;
|
Shutter[i].target_position = target_pos;
|
||||||
Shutter[i].start_position = Shutter[i].real_position;
|
Shutter[i].start_position = Shutter[i].real_position;
|
||||||
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||||
|
sensor_data_reported = false;
|
||||||
ShutterAllowPreStartProcedure(i);
|
ShutterAllowPreStartProcedure(i);
|
||||||
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
||||||
|
|
||||||
|
@ -1928,16 +1930,22 @@ bool Xdrv27(uint32_t function)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
if (!sensor_data_reported) {
|
||||||
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
sensor_data_reported = true;
|
||||||
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||||
ResponseAppend_P(",");
|
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||||
ResponseAppend_P(JSON_SHUTTER_POS, i+1, (Settings->shutter_options[i] & 1) ? 100 - position : position, Shutter[i].direction,(Settings->shutter_options[i] & 1) ? 100 - target : target, Shutter[i].tilt_real_pos );
|
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||||
#ifdef USE_DOMOTICZ
|
ResponseAppend_P(",");
|
||||||
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
ResponseAppend_P(JSON_SHUTTER_POS, i+1, (Settings->shutter_options[i] & 1) ? 100 - position : position, Shutter[i].direction,(Settings->shutter_options[i] & 1) ? 100 - target : target, Shutter[i].tilt_real_pos );
|
||||||
DomoticzSensor(DZ_SHUTTER, position);
|
if (Shutter[i].direction != 0) {
|
||||||
|
sensor_data_reported = false;
|
||||||
|
}
|
||||||
|
#ifdef USE_DOMOTICZ
|
||||||
|
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
||||||
|
DomoticzSensor(DZ_SHUTTER, (Settings->shutter_options[i] & 1) ? 100 - position : position);
|
||||||
|
}
|
||||||
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_SET_POWER:
|
case FUNC_SET_POWER:
|
||||||
|
|
Loading…
Reference in New Issue