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
|
||||
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
|
||||
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;
|
||||
|
||||
#define SHT_DIV_ROUND(__A, __B) (((__A) + (__B)/2) / (__B))
|
||||
|
@ -946,7 +947,7 @@ void ShutterRelayChanged(void)
|
|||
|
||||
void ShutterReportPosition(bool always, uint32_t index)
|
||||
{
|
||||
Response_P(PSTR("{"));
|
||||
|
||||
uint32_t i = 0;
|
||||
uint32_t n = TasmotaGlobal.shutters_present;
|
||||
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)
|
||||
if (!always && !shutter_running) return;
|
||||
|
||||
Response_P(PSTR("{"));
|
||||
if( index != MAX_SHUTTERS_ESP32) {
|
||||
i = index;
|
||||
n = index+1;
|
||||
|
@ -1196,6 +1197,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos)
|
|||
Shutter[i].target_position = target_pos;
|
||||
Shutter[i].start_position = Shutter[i].real_position;
|
||||
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||
ShutterGlobal.sensor_data_reported = false;
|
||||
ShutterAllowPreStartProcedure(i);
|
||||
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
||||
|
||||
|
@ -2330,6 +2332,8 @@ bool Xdrv27(uint32_t function)
|
|||
}
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
if (!ShutterGlobal.sensor_data_reported) {
|
||||
ShutterGlobal.sensor_data_reported = true;
|
||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
ResponseAppend_P(",");
|
||||
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||
|
@ -2337,11 +2341,15 @@ bool Xdrv27(uint32_t function)
|
|||
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||
target = (ShutterSettings.shutter_options[i] & 1) ? 100 - target : target;
|
||||
ResponseAppend_P(JSON_SHUTTER_POS, i + 1, position, Shutter[i].direction, target, Shutter[i].tilt_real_pos );
|
||||
#ifdef USE_DOMOTICZ
|
||||
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;
|
||||
case FUNC_SET_POWER:
|
||||
|
|
|
@ -52,6 +52,7 @@ int32_t current_stop_way = 0;
|
|||
int32_t next_possible_stop_position = 0;
|
||||
int32_t current_real_position = 0;
|
||||
int32_t current_pwm_velocity = 0;
|
||||
bool sensor_data_reported = false;
|
||||
|
||||
const char HTTP_MSG_SLIDER_SHUTTER[] PROGMEM =
|
||||
"<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].start_position = Shutter[i].real_position;
|
||||
TasmotaGlobal.rules_flag.shutter_moving = 1;
|
||||
sensor_data_reported = false;
|
||||
ShutterAllowPreStartProcedure(i);
|
||||
Shutter[i].time = Shutter[i].last_reported_time = 0;
|
||||
|
||||
|
@ -1928,16 +1930,22 @@ bool Xdrv27(uint32_t function)
|
|||
}
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
if (!sensor_data_reported) {
|
||||
sensor_data_reported = true;
|
||||
for (uint8_t i = 0; i < TasmotaGlobal.shutters_present; i++) {
|
||||
uint8_t position = ShutterRealToPercentPosition(Shutter[i].real_position, i);
|
||||
uint8_t target = ShutterRealToPercentPosition(Shutter[i].target_position, i);
|
||||
ResponseAppend_P(",");
|
||||
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 );
|
||||
#ifdef USE_DOMOTICZ
|
||||
if ((0 == TasmotaGlobal.tele_period) && (0 == i)) {
|
||||
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;
|
||||
case FUNC_SET_POWER:
|
||||
|
|
Loading…
Reference in New Issue