2#if defined(USE_BINARY_SENSOR_CLICK_TRIGGER) || defined(USE_BINARY_SENSOR_MULTI_CLICK_TRIGGER)
9#ifdef USE_BINARY_SENSOR_MULTI_CLICK_TRIGGER
38 ESP_LOGV(TAG,
"Multi Click: Starting multi click action!");
47 ESP_LOGV(TAG,
"Multi Click: action not started because first level does not match!");
71 ESP_LOGV(TAG,
"B i=%u min=%" PRIu32, at_index, evt.
min_length);
75 ESP_LOGV(TAG,
"C i=%u min=%" PRIu32, at_index, evt.
min_length);
84 ESP_LOGV(TAG,
"Multi Click: Invalid length of press, starting cooldown of %" PRIu32
" ms", this->
invalid_cooldown_);
87 ESP_LOGV(TAG,
"Multi Click: Cooldown ended, matching is now enabled again.");
96 if (min_length == 0) {
101 this->
set_timeout(MULTICLICK_IS_VALID_ID, min_length, [
this]() {
102 ESP_LOGV(TAG,
"Multi Click: You can now %s the button.",
103 this->
parent_->
state ? LOG_STR_LITERAL(
"RELEASE") : LOG_STR_LITERAL(
"PRESS"));
108 this->
set_timeout(MULTICLICK_IS_NOT_VALID_ID, max_length, [
this]() {
109 ESP_LOGV(TAG,
"Multi Click: You waited too long to %s.",
110 this->
parent_->
state ? LOG_STR_LITERAL(
"RELEASE") : LOG_STR_LITERAL(
"PRESS"));
116 ESP_LOGV(TAG,
"Multi Click: Sequence explicitly cancelled.");
121 ESP_LOGV(TAG,
"Multi Click: Hooray, multi click is valid. Triggering!");
131#ifdef USE_BINARY_SENSOR_CLICK_TRIGGER
133 if (max_length == 0) {
134 return length >= min_length;
bool cancel_timeout(const char *name)
Cancel a timeout function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
bool state
The current state of this binary sensor. Also used as the backing storage for StatefulEntityBase.
const MultiClickTriggerEvent * timing_
void on_state_(bool state)
void schedule_is_not_valid_(uint32_t max_length)
uint32_t invalid_cooldown_
void schedule_is_valid_(uint32_t min_length)
void schedule_cooldown_()
constexpr uint32_t MULTICLICK_COOLDOWN_ID
constexpr uint32_t MULTICLICK_IS_NOT_VALID_ID
constexpr uint32_t MULTICLICK_IS_VALID_ID
bool match_interval(uint32_t min_length, uint32_t max_length, uint32_t length)
ESPHOME_LOG_TAG(TAG, "binary_sensor.automation")
constexpr uint32_t MULTICLICK_TRIGGER_ID