10static constexpr uint32_t DIRECTION_CHANGE_TIMEOUT_ID = 1;
17 if (restore.has_value()) {
25#ifdef USE_BINARY_SENSOR
46 traits.set_supports_stop(
true);
47 traits.set_supports_position(
true);
48 traits.set_supports_toggle(
true);
54 LOG_COVER(
"",
"Endstop Cover",
this);
55 ESP_LOGCONFIG(TAG,
" Open Duration: %.1fs", this->
open_duration_ / 1e3f);
56#ifdef USE_BINARY_SENSOR
61 ESP_LOGCONFIG(TAG,
" Close Duration: %.1fs", this->
close_duration_ / 1e3f);
62#ifdef USE_BINARY_SENSOR
68 ESP_LOGCONFIG(TAG,
" Has builtin endstop: YES");
71 ESP_LOGCONFIG(TAG,
" Infer endstop from movement: YES");
74 ESP_LOGCONFIG(TAG,
" Max Duration: %.1fs", this->
max_duration_ / 1e3f);
82#ifdef USE_FEEDBACK_COVER_OVERSHOOT
87#ifdef USE_BINARY_SENSOR
94#ifdef USE_BINARY_SENSOR
101 ESP_LOGD(TAG,
"'%s' - Open feedback '%s'.", LOG_STR_ARG(this->
get_log_name()),
102 state ? LOG_STR_LITERAL(
"STARTED") : LOG_STR_LITERAL(
"ENDED"));
115 ESP_LOGD(TAG,
"'%s' - Close feedback '%s'.", LOG_STR_ARG(this->
get_log_name()),
116 state ? LOG_STR_LITERAL(
"STARTED") : LOG_STR_LITERAL(
"ENDED"));
148 this->
position = open_endstop ? COVER_OPEN : COVER_CLOSED;
154 ESP_LOGD(TAG,
"'%s' - %s endstop reached. Took %.1fs.", LOG_STR_ARG(this->
get_log_name()),
155 open_endstop ? LOG_STR_LITERAL(
"Open") : LOG_STR_LITERAL(
"Close"), dur);
182#ifdef USE_BINARY_SENSOR
194#ifdef USE_BINARY_SENSOR
201 ESP_LOGD(TAG,
"'%s' - Close obstacle detected.", LOG_STR_ARG(this->
get_log_name()));
218 ESP_LOGD(TAG,
"'%s' - Open obstacle detected.", LOG_STR_ARG(this->
get_log_name()));
246#ifdef USE_FEEDBACK_COVER_OVERSHOOT
254 ESP_LOGD(TAG,
"'%s' - Overshoot duration reached. Stopping cover.", LOG_STR_ARG(this->
get_log_name()));
262 ESP_LOGD(TAG,
"'%s' - Max duration reached. Stopping cover.", LOG_STR_ARG(this->
get_log_name()));
278 if (
call.get_stop()) {
294 auto pos_opt =
call.get_position();
295 if (!pos_opt.has_value())
305#ifdef USE_BINARY_SENSOR
310#ifdef USE_BINARY_SENSOR
356#ifdef USE_BINARY_SENSOR
360#ifdef USE_FEEDBACK_COVER_OVERSHOOT
372#ifdef USE_BINARY_SENSOR
379#ifdef USE_BINARY_SENSOR
389#ifdef USE_BINARY_SENSOR
392 if (obstacle !=
nullptr && obstacle->state) {
393 ESP_LOGD(TAG,
"'%s' - %s obstacle detected. Action not started.", LOG_STR_ARG(this->
get_log_name()),
404 ESP_LOGD(TAG,
"'%s' - Reversing direction.", LOG_STR_ARG(this->
get_log_name()));
410 ESP_LOGD(TAG,
"'%s' - Firing '%s' trigger.", LOG_STR_ARG(this->
get_log_name()),
413 : LOG_STR_LITERAL(
"STOP"));
436 min_pos = COVER_CLOSED;
438#ifdef USE_BINARY_SENSOR
450#ifdef USE_BINARY_SENSOR
457 max_pos = COVER_OPEN;
468 effective_start = accel_end_time;
472 this->
position += dir * (now - effective_start) / (action_dur - this->acceleration_wait_time_);
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
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.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void add_on_state_callback(F &&callback)
void stop_action()
Stop any action connected to this trigger.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
Base class for all binary_sensor-type classes.
bool state
The current state of this binary sensor. Also used as the backing storage for StatefulEntityBase.
const optional< bool > & get_toggle() const
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
optional< CoverRestoreState > restore_state_()
void publish_state(bool save=true)
Publish the current state of the cover.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
cover::CoverTraits get_traits() override
cover::CoverOperation current_trigger_operation_
Trigger * prev_command_trigger_
binary_sensor::BinarySensor * open_endstop_
void start_direction_(cover::CoverOperation dir)
uint32_t update_interval_
void set_open_obstacle_sensor(binary_sensor::BinarySensor *open_obstacle)
void set_open_sensor(binary_sensor::BinarySensor *open_feedback)
void set_current_operation_(cover::CoverOperation operation, bool is_triggered)
binary_sensor::BinarySensor * close_endstop_
void set_close_endstop(binary_sensor::BinarySensor *close_endstop)
void stop_prev_trigger_()
optional< uint32_t > direction_change_waittime_
binary_sensor::BinarySensor * close_obstacle_
void set_close_obstacle_sensor(binary_sensor::BinarySensor *close_obstacle)
uint32_t start_overshoot_time_
void control(const cover::CoverCall &call) override
binary_sensor::BinarySensor * open_feedback_
bool is_at_target_() const
bool has_built_in_endstop_
void dump_config() override
uint32_t acceleration_wait_time_
void recompute_position_()
void endstop_reached_(bool open_endstop)
void set_open_endstop(binary_sensor::BinarySensor *open_endstop)
cover::CoverOperation last_operation_
binary_sensor::BinarySensor * open_obstacle_
uint32_t last_recompute_time_
binary_sensor::BinarySensor * close_feedback_
uint32_t last_publish_time_
uint32_t overshoot_duration_
void set_close_sensor(binary_sensor::BinarySensor *close_feedback)
ESPHOME_LOG_TAG(TAG, "cover")
CoverOperation
Enum encoding the current operation of a cover.
@ COVER_OPERATION_OPENING
The cover is currently opening.
@ COVER_OPERATION_CLOSING
The cover is currently closing.
@ COVER_OPERATION_IDLE
The cover is currently idle (not moving)
Application App
Global storage of Application pointer - only one Application can exist.