ESPHome  2022.11.3
Public Member Functions | Protected Member Functions | Protected Attributes
esphome::sprinkler::Sprinkler Class Reference

#include <sprinkler.h>

Inheritance diagram for esphome::sprinkler::Sprinkler:
esphome::Component esphome::EntityBase

Public Member Functions

 Sprinkler ()
 
 Sprinkler (const std::string &name)
 
void setup () override
 
void loop () override
 
void dump_config () override
 
void add_valve (SprinklerControllerSwitch *valve_sw, SprinklerControllerSwitch *enable_sw=nullptr)
 add a valve to the controller More...
 
void add_controller (Sprinkler *other_controller)
 add another controller to the controller so it can check if pumps/main valves are in use More...
 
void set_controller_main_switch (SprinklerControllerSwitch *controller_switch)
 configure important controller switches More...
 
void set_controller_auto_adv_switch (SprinklerControllerSwitch *auto_adv_switch)
 
void set_controller_queue_enable_switch (SprinklerControllerSwitch *queue_enable_switch)
 
void set_controller_reverse_switch (SprinklerControllerSwitch *reverse_switch)
 
void configure_valve_switch (size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration)
 configure a valve's switch object and run duration. run_duration is time in seconds. More...
 
void configure_valve_switch_pulsed (size_t valve_number, switch_::Switch *valve_switch_off, switch_::Switch *valve_switch_on, uint32_t pulse_duration, uint32_t run_duration)
 
void configure_valve_pump_switch (size_t valve_number, switch_::Switch *pump_switch)
 configure a valve's associated pump switch object More...
 
void configure_valve_pump_switch_pulsed (size_t valve_number, switch_::Switch *pump_switch_off, switch_::Switch *pump_switch_on, uint32_t pulse_duration)
 
void set_multiplier (optional< float > multiplier)
 value multiplied by configured run times – used to extend or shorten the cycle More...
 
void set_pump_start_delay (uint32_t start_delay)
 set how long the pump should start after the valve (when the pump is starting) More...
 
void set_pump_stop_delay (uint32_t stop_delay)
 set how long the pump should stop after the valve (when the pump is starting) More...
 
void set_valve_start_delay (uint32_t start_delay)
 set how long the valve should start after the pump (when the pump is stopping) More...
 
void set_valve_stop_delay (uint32_t stop_delay)
 set how long the valve should stop after the pump (when the pump is stopping) More...
 
void set_pump_switch_off_during_valve_open_delay (bool pump_switch_off_during_valve_open_delay)
 if pump_switch_off_during_valve_open_delay is true, the controller will switch off the pump during the valve_open_delay interval More...
 
void set_valve_open_delay (uint32_t valve_open_delay)
 set how long the controller should wait to open/switch on the valve after it becomes active More...
 
void set_valve_overlap (uint32_t valve_overlap)
 set how long the controller should wait after opening a valve before closing the previous valve More...
 
void set_manual_selection_delay (uint32_t manual_selection_delay)
 set how long the controller should wait to activate a valve after next_valve() or previous_valve() is called More...
 
void set_valve_run_duration (optional< size_t > valve_number, optional< uint32_t > run_duration)
 set how long the valve should remain on/open. run_duration is time in seconds More...
 
void set_auto_advance (bool auto_advance)
 if auto_advance is true, controller will iterate through all enabled valves More...
 
void set_repeat (optional< uint32_t > repeat)
 set the number of times to repeat a full cycle More...
 
void set_queue_enable (bool queue_enable)
 if queue_enable is true, controller will iterate through valves in the queue More...
 
void set_reverse (bool reverse)
 if reverse is true, controller will iterate through all enabled valves in reverse (descending) order More...
 
uint32_t valve_run_duration (size_t valve_number)
 returns valve_number's run duration in seconds More...
 
uint32_t valve_run_duration_adjusted (size_t valve_number)
 returns valve_number's run duration (in seconds) adjusted by multiplier_ More...
 
bool auto_advance ()
 returns true if auto_advance is enabled More...
 
float multiplier ()
 returns the current value of the multiplier More...
 
optional< uint32_t > repeat ()
 returns the number of times the controller is set to repeat cycles, if at all. check with 'has_value()' More...
 
optional< uint32_t > repeat_count ()
 if a cycle is active, returns the number of times the controller has repeated the cycle. check with 'has_value()' More...
 
bool queue_enabled ()
 returns true if the queue is enabled to run More...
 
bool reverse ()
 returns true if reverse is enabled More...
 
void start_from_queue ()
 starts the controller from the first valve in the queue and disables auto_advance. More...
 
void start_full_cycle ()
 starts a full cycle of all enabled valves and enables auto_advance. More...
 
void start_single_valve (optional< size_t > valve_number)
 activates a single valve and disables auto_advance. More...
 
void queue_valve (optional< size_t > valve_number, optional< uint32_t > run_duration)
 adds a valve into the queue. More...
 
void clear_queued_valves ()
 clears/removes all valves from the queue More...
 
void next_valve ()
 advances to the next valve (numerically) More...
 
void previous_valve ()
 advances to the previous valve (numerically) More...
 
void shutdown (bool clear_queue=false)
 turns off all valves, effectively shutting down the system. More...
 
void pause ()
 same as shutdown(), but also stores active_valve() and time_remaining() allowing resume() to continue the cycle More...
 
void resume ()
 resumes a cycle that was suspended using pause() More...
 
void resume_or_start_full_cycle ()
 if a cycle was suspended using pause(), resumes it. otherwise calls start_full_cycle() More...
 
void reset_resume ()
 resets resume state More...
 
const char * valve_name (size_t valve_number)
 returns a pointer to a valve's name string object; returns nullptr if valve_number is invalid More...
 
optional< size_t > active_valve ()
 returns the number of the valve that is currently active, if any. check with 'has_value()' More...
 
optional< size_t > paused_valve ()
 returns the number of the valve that is paused, if any. check with 'has_value()' More...
 
optional< size_t > queued_valve ()
 returns the number of the next valve in the queue, if any. check with 'has_value()' More...
 
optional< size_t > manual_valve ()
 returns the number of the valve that is manually selected, if any. More...
 
size_t number_of_valves ()
 returns the number of valves the controller is configured with More...
 
bool is_a_valid_valve (size_t valve_number)
 returns true if valve number is valid More...
 
bool pump_in_use (SprinklerSwitch *pump_switch)
 returns true if the pump the pointer points to is in use More...
 
void set_pump_state (SprinklerSwitch *pump_switch, bool state)
 switches on/off a pump "safely" by checking that the new state will not conflict with another controller More...
 
optional< uint32_t > time_remaining ()
 returns the amount of time remaining in seconds for the active valve, if any. check with 'has_value()' More...
 
SprinklerControllerSwitchcontrol_switch (size_t valve_number)
 returns a pointer to a valve's control switch object More...
 
SprinklerControllerSwitchenable_switch (size_t valve_number)
 returns a pointer to a valve's enable switch object More...
 
SprinklerSwitchvalve_switch (size_t valve_number)
 returns a pointer to a valve's switch object More...
 
SprinklerSwitchvalve_pump_switch (size_t valve_number)
 returns a pointer to a valve's pump switch object More...
 
SprinklerSwitchvalve_pump_switch_by_pump_index (size_t pump_index)
 returns a pointer to a valve's pump switch object More...
 
- Public Member Functions inherited from esphome::Component
virtual float get_setup_priority () const
 priority of setup(). More...
 
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
virtual float get_loop_priority () const
 priority of loop(). More...
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
uint32_t get_component_state () const
 
virtual void mark_failed ()
 Mark this component as failed. More...
 
bool is_failed ()
 
virtual bool can_proceed ()
 
bool status_has_warning ()
 
bool status_has_error ()
 
void status_set_warning ()
 
void status_set_error ()
 
void status_clear_warning ()
 
void status_clear_error ()
 
void status_momentary_warning (const std::string &name, uint32_t length=5000)
 
void status_momentary_error (const std::string &name, uint32_t length=5000)
 
bool has_overridden_loop () const
 
void set_component_source (const char *source)
 Set where this component was loaded from for some debug messages. More...
 
const char * get_component_source () const
 Get the integration where this component was declared as a string. More...
 
- Public Member Functions inherited from esphome::EntityBase
 EntityBase ()
 
 EntityBase (std::string name)
 
const std::string & get_name () const
 
void set_name (const std::string &name)
 
const std::string & get_object_id ()
 
uint32_t get_object_id_hash ()
 
bool is_internal () const
 
void set_internal (bool internal)
 
bool is_disabled_by_default () const
 
void set_disabled_by_default (bool disabled_by_default)
 
EntityCategory get_entity_category () const
 
void set_entity_category (EntityCategory entity_category)
 
const std::string & get_icon () const
 
void set_icon (const std::string &name)
 

Protected Member Functions

uint32_t hash_base () override
 
bool valve_is_enabled_ (size_t valve_number)
 returns true if valve number is enabled More...
 
void mark_valve_cycle_complete_ (size_t valve_number)
 marks a valve's cycle as complete More...
 
bool valve_cycle_complete_ (size_t valve_number)
 returns true if valve's cycle is flagged as complete More...
 
size_t next_valve_number_ (size_t first_valve)
 returns the number of the next/previous valve in the vector More...
 
size_t previous_valve_number_ (size_t first_valve)
 
optional< size_t > next_valve_number_in_cycle_ (optional< size_t > first_valve=nullopt)
 returns the number of the next valve that should be activated in a full cycle. More...
 
void load_next_valve_run_request_ (optional< size_t > first_valve=nullopt)
 loads next_req_ with the next valve that should be activated, including its run duration. More...
 
optional< size_t > next_enabled_incomplete_valve_number_ (optional< size_t > first_valve)
 returns the number of the next/previous valve that should be activated. More...
 
optional< size_t > previous_enabled_incomplete_valve_number_ (optional< size_t > first_valve)
 
bool any_valve_is_enabled_ ()
 returns true if any valve is enabled More...
 
void start_valve_ (SprinklerValveRunRequest *req)
 loads an available SprinklerValveOperator (valve_op_) based on req and starts it (switches it on). More...
 
void all_valves_off_ (bool include_pump=false)
 turns off/closes all valves, including pump if include_pump is true More...
 
void prep_full_cycle_ ()
 prepares for a full cycle by verifying auto-advance is on as well as one or more valve enable switches. More...
 
void reset_cycle_states_ ()
 resets the cycle state for all valves More...
 
void fsm_request_ (size_t requested_valve, uint32_t requested_run_duration=0)
 make a request of the state machine More...
 
void fsm_kick_ ()
 kicks the state machine to advance, starting it if it is not already active More...
 
void fsm_transition_ ()
 advance controller state, advancing to target_valve if provided More...
 
void fsm_transition_from_shutdown_ ()
 starts up the system from IDLE state More...
 
void fsm_transition_from_valve_run_ ()
 transitions from ACTIVE state to ACTIVE (as in, next valve) or to a SHUTDOWN or IDLE state More...
 
void fsm_transition_to_shutdown_ ()
 starts up the system from IDLE state More...
 
std::string state_as_str_ (SprinklerState state)
 return the current FSM state as a string More...
 
void start_timer_ (SprinklerTimerIndex timer_index)
 Start/cancel/get status of valve timers. More...
 
bool cancel_timer_ (SprinklerTimerIndex timer_index)
 
bool timer_active_ (SprinklerTimerIndex timer_index)
 returns true if the specified timer is active/running More...
 
void set_timer_duration_ (SprinklerTimerIndex timer_index, uint32_t time)
 time is converted to milliseconds (ms) for set_timeout() More...
 
uint32_t timer_duration_ (SprinklerTimerIndex timer_index)
 returns time in milliseconds (ms) More...
 
std::function< void()> timer_cbf_ (SprinklerTimerIndex timer_index)
 
void valve_selection_callback_ ()
 callback functions for timers More...
 
void sm_timer_callback_ ()
 
void pump_stop_delay_callback_ ()
 
- Protected Member Functions inherited from esphome::Component
virtual void call_loop ()
 
virtual void call_setup ()
 
virtual void call_dump_config ()
 
void set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a unique name. More...
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const std::string &name)
 Cancel an interval function. More...
 
void set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult()> &&f, float backoff_increase_factor=1.0f)
 Set an retry function with a unique name. More...
 
void set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult()> &&f, float backoff_increase_factor=1.0f)
 
bool cancel_retry (const std::string &name)
 Cancel a retry function. More...
 
void set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a unique name. More...
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const std::string &name)
 Cancel a timeout function. More...
 
void defer (const std::string &name, std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call. More...
 
bool cancel_defer (const std::string &name)
 Cancel a defer callback using the specified name, name must not be empty. More...
 
- Protected Member Functions inherited from esphome::EntityBase
void calc_object_id_ ()
 

Protected Attributes

const uint8_t max_queue_size_ {100}
 Maximum allowed queue size. More...
 
bool pump_switch_off_during_valve_open_delay_ {false}
 Pump should be off during valve_open_delay interval. More...
 
bool valve_overlap_ {false}
 Sprinkler valve cycle should overlap. More...
 
bool start_delay_is_valve_delay_ {false}
 Pump start/stop delay interval types. More...
 
bool stop_delay_is_valve_delay_ {false}
 
uint32_t start_delay_ {0}
 Pump start/stop delay intervals. More...
 
uint32_t stop_delay_ {0}
 
SprinklerState state_ {IDLE}
 Sprinkler controller state. More...
 
SprinklerValveRunRequest active_req_
 The valve run request that is currently active. More...
 
optional< size_t > manual_valve_
 The number of the manually selected valve currently selected. More...
 
optional< size_t > paused_valve_
 The number of the valve to resume from (if paused) More...
 
SprinklerValveRunRequest next_req_
 The next run request for the controller to consume after active_req_ is complete. More...
 
optional< uint32_t > target_repeats_
 Set the number of times to repeat a full cycle. More...
 
optional< uint32_t > resume_duration_
 Set from time_remaining() when paused. More...
 
optional< uint32_t > manual_selection_delay_
 Manual switching delay. More...
 
optional< uint32_t > switching_delay_
 Valve switching delay. More...
 
uint32_t repeat_count_ {0}
 Number of times the full cycle has been repeated. More...
 
float multiplier_ {1.0}
 Sprinkler valve run time multiplier value. More...
 
std::vector< SprinklerQueueItemqueued_valves_
 Queue of valves to activate next, regardless of auto-advance. More...
 
std::vector< SprinklerSwitchpump_
 Sprinkler valve pump objects. More...
 
std::vector< SprinklerValvevalve_
 Sprinkler valve objects. More...
 
std::vector< SprinklerValveOperatorvalve_op_ {2}
 Sprinkler valve operator objects. More...
 
std::vector< SprinklerTimertimer_
 Valve control timers. More...
 
std::vector< Sprinkler * > other_controllers_
 Other Sprinkler instances we should be aware of (used to check if pumps are in use) More...
 
SprinklerControllerSwitchauto_adv_sw_ {nullptr}
 Switches we'll present to the front end. More...
 
SprinklerControllerSwitchcontroller_sw_ {nullptr}
 
SprinklerControllerSwitchqueue_enable_sw_ {nullptr}
 
SprinklerControllerSwitchreverse_sw_ {nullptr}
 
std::unique_ptr< ShutdownAction<> > sprinkler_shutdown_action_
 
std::unique_ptr< ResumeOrStartAction<> > sprinkler_resumeorstart_action_
 
std::unique_ptr< Automation<> > sprinkler_turn_off_automation_
 
std::unique_ptr< Automation<> > sprinkler_turn_on_automation_
 
- Protected Attributes inherited from esphome::Component
uint32_t component_state_ {0x0000}
 State of this component. More...
 
float setup_priority_override_ {NAN}
 
const char * component_source_ {nullptr}
 
- Protected Attributes inherited from esphome::EntityBase
std::string name_
 
std::string object_id_
 
std::string icon_
 
uint32_t object_id_hash_
 
bool internal_ {false}
 
bool disabled_by_default_ {false}
 
EntityCategory entity_category_ {ENTITY_CATEGORY_NONE}
 

Detailed Description

Definition at line 177 of file sprinkler.h.

Constructor & Destructor Documentation

◆ Sprinkler() [1/2]

esphome::sprinkler::Sprinkler::Sprinkler ( )

Definition at line 365 of file sprinkler.cpp.

◆ Sprinkler() [2/2]

esphome::sprinkler::Sprinkler::Sprinkler ( const std::string &  name)

Definition at line 366 of file sprinkler.cpp.

Member Function Documentation

◆ active_valve()

optional< size_t > esphome::sprinkler::Sprinkler::active_valve ( )

returns the number of the valve that is currently active, if any. check with 'has_value()'

Definition at line 798 of file sprinkler.cpp.

◆ add_controller()

void esphome::sprinkler::Sprinkler::add_controller ( Sprinkler other_controller)

add another controller to the controller so it can check if pumps/main valves are in use

Definition at line 412 of file sprinkler.cpp.

◆ add_valve()

void esphome::sprinkler::Sprinkler::add_valve ( SprinklerControllerSwitch valve_sw,
SprinklerControllerSwitch enable_sw = nullptr 
)

add a valve to the controller

Definition at line 382 of file sprinkler.cpp.

◆ all_valves_off_()

void esphome::sprinkler::Sprinkler::all_valves_off_ ( bool  include_pump = false)
protected

turns off/closes all valves, including pump if include_pump is true

Definition at line 1075 of file sprinkler.cpp.

◆ any_valve_is_enabled_()

bool esphome::sprinkler::Sprinkler::any_valve_is_enabled_ ( )
protected

returns true if any valve is enabled

Definition at line 1043 of file sprinkler.cpp.

◆ auto_advance()

bool esphome::sprinkler::Sprinkler::auto_advance ( )

returns true if auto_advance is enabled

Definition at line 611 of file sprinkler.cpp.

◆ cancel_timer_()

bool esphome::sprinkler::Sprinkler::cancel_timer_ ( SprinklerTimerIndex  timer_index)
protected

Definition at line 1266 of file sprinkler.cpp.

◆ clear_queued_valves()

void esphome::sprinkler::Sprinkler::clear_queued_valves ( )

clears/removes all valves from the queue

Definition at line 708 of file sprinkler.cpp.

◆ configure_valve_pump_switch()

void esphome::sprinkler::Sprinkler::configure_valve_pump_switch ( size_t  valve_number,
switch_::Switch pump_switch 
)

configure a valve's associated pump switch object

Definition at line 470 of file sprinkler.cpp.

◆ configure_valve_pump_switch_pulsed()

void esphome::sprinkler::Sprinkler::configure_valve_pump_switch_pulsed ( size_t  valve_number,
switch_::Switch pump_switch_off,
switch_::Switch pump_switch_on,
uint32_t  pulse_duration 
)

Definition at line 484 of file sprinkler.cpp.

◆ configure_valve_switch()

void esphome::sprinkler::Sprinkler::configure_valve_switch ( size_t  valve_number,
switch_::Switch valve_switch,
uint32_t  run_duration 
)

configure a valve's switch object and run duration. run_duration is time in seconds.

Definition at line 452 of file sprinkler.cpp.

◆ configure_valve_switch_pulsed()

void esphome::sprinkler::Sprinkler::configure_valve_switch_pulsed ( size_t  valve_number,
switch_::Switch valve_switch_off,
switch_::Switch valve_switch_on,
uint32_t  pulse_duration,
uint32_t  run_duration 
)

Definition at line 459 of file sprinkler.cpp.

◆ control_switch()

SprinklerControllerSwitch * esphome::sprinkler::Sprinkler::control_switch ( size_t  valve_number)

returns a pointer to a valve's control switch object

Definition at line 898 of file sprinkler.cpp.

◆ dump_config()

void esphome::sprinkler::Sprinkler::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 1298 of file sprinkler.cpp.

◆ enable_switch()

SprinklerControllerSwitch * esphome::sprinkler::Sprinkler::enable_switch ( size_t  valve_number)

returns a pointer to a valve's enable switch object

Definition at line 905 of file sprinkler.cpp.

◆ fsm_kick_()

void esphome::sprinkler::Sprinkler::fsm_kick_ ( )
protected

kicks the state machine to advance, starting it if it is not already active

Definition at line 1117 of file sprinkler.cpp.

◆ fsm_request_()

void esphome::sprinkler::Sprinkler::fsm_request_ ( size_t  requested_valve,
uint32_t  requested_run_duration = 0 
)
protected

make a request of the state machine

Definition at line 1109 of file sprinkler.cpp.

◆ fsm_transition_()

void esphome::sprinkler::Sprinkler::fsm_transition_ ( )
protected

advance controller state, advancing to target_valve if provided

Definition at line 1123 of file sprinkler.cpp.

◆ fsm_transition_from_shutdown_()

void esphome::sprinkler::Sprinkler::fsm_transition_from_shutdown_ ( )
protected

starts up the system from IDLE state

Definition at line 1170 of file sprinkler.cpp.

◆ fsm_transition_from_valve_run_()

void esphome::sprinkler::Sprinkler::fsm_transition_from_valve_run_ ( )
protected

transitions from ACTIVE state to ACTIVE (as in, next valve) or to a SHUTDOWN or IDLE state

Definition at line 1182 of file sprinkler.cpp.

◆ fsm_transition_to_shutdown_()

void esphome::sprinkler::Sprinkler::fsm_transition_to_shutdown_ ( )
protected

starts up the system from IDLE state

Definition at line 1226 of file sprinkler.cpp.

◆ hash_base()

uint32_t esphome::sprinkler::Sprinkler::hash_base ( )
overrideprotectedvirtual

Reimplemented from esphome::EntityBase.

Definition at line 933 of file sprinkler.cpp.

◆ is_a_valid_valve()

bool esphome::sprinkler::Sprinkler::is_a_valid_valve ( size_t  valve_number)

returns true if valve number is valid

Definition at line 812 of file sprinkler.cpp.

◆ load_next_valve_run_request_()

void esphome::sprinkler::Sprinkler::load_next_valve_run_request_ ( optional< size_t >  first_valve = nullopt)
protected

loads next_req_ with the next valve that should be activated, including its run duration.

if next_req_ already contains a request, nothing is done. after next_req_, queued valves have priority, followed by enabled valves if auto-advance is enabled. if no valve is next (for example, a full cycle is complete), next_req_ is reset via reset().

Definition at line 983 of file sprinkler.cpp.

◆ loop()

void esphome::sprinkler::Sprinkler::loop ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 370 of file sprinkler.cpp.

◆ manual_valve()

optional< size_t > esphome::sprinkler::Sprinkler::manual_valve ( )

returns the number of the valve that is manually selected, if any.

check with 'has_value()' this is set by next_valve() and previous_valve() when manual_selection_delay_ > 0

Definition at line 808 of file sprinkler.cpp.

◆ mark_valve_cycle_complete_()

void esphome::sprinkler::Sprinkler::mark_valve_cycle_complete_ ( size_t  valve_number)
protected

marks a valve's cycle as complete

Definition at line 946 of file sprinkler.cpp.

◆ multiplier()

float esphome::sprinkler::Sprinkler::multiplier ( )

returns the current value of the multiplier

Definition at line 618 of file sprinkler.cpp.

◆ next_enabled_incomplete_valve_number_()

optional< size_t > esphome::sprinkler::Sprinkler::next_enabled_incomplete_valve_number_ ( optional< size_t >  first_valve)
protected

returns the number of the next/previous valve that should be activated.

if no valve is next (cycle is complete), returns no value (check with 'has_value()')

Definition at line 1017 of file sprinkler.cpp.

◆ next_valve()

void esphome::sprinkler::Sprinkler::next_valve ( )

advances to the next valve (numerically)

Definition at line 713 of file sprinkler.cpp.

◆ next_valve_number_()

size_t esphome::sprinkler::Sprinkler::next_valve_number_ ( size_t  first_valve)
protected

returns the number of the next/previous valve in the vector

Definition at line 960 of file sprinkler.cpp.

◆ next_valve_number_in_cycle_()

optional< size_t > esphome::sprinkler::Sprinkler::next_valve_number_in_cycle_ ( optional< size_t >  first_valve = nullopt)
protected

returns the number of the next valve that should be activated in a full cycle.

if no valve is next (cycle is complete), returns no value (check with 'has_value()')

Definition at line 974 of file sprinkler.cpp.

◆ number_of_valves()

size_t esphome::sprinkler::Sprinkler::number_of_valves ( )

returns the number of valves the controller is configured with

Definition at line 810 of file sprinkler.cpp.

◆ pause()

void esphome::sprinkler::Sprinkler::pause ( )

same as shutdown(), but also stores active_valve() and time_remaining() allowing resume() to continue the cycle

Definition at line 756 of file sprinkler.cpp.

◆ paused_valve()

optional< size_t > esphome::sprinkler::Sprinkler::paused_valve ( )

returns the number of the valve that is paused, if any. check with 'has_value()'

Definition at line 799 of file sprinkler.cpp.

◆ prep_full_cycle_()

void esphome::sprinkler::Sprinkler::prep_full_cycle_ ( )
protected

prepares for a full cycle by verifying auto-advance is on as well as one or more valve enable switches.

Definition at line 1087 of file sprinkler.cpp.

◆ previous_enabled_incomplete_valve_number_()

optional< size_t > esphome::sprinkler::Sprinkler::previous_enabled_incomplete_valve_number_ ( optional< size_t >  first_valve)
protected

Definition at line 1030 of file sprinkler.cpp.

◆ previous_valve()

void esphome::sprinkler::Sprinkler::previous_valve ( )

advances to the previous valve (numerically)

Definition at line 727 of file sprinkler.cpp.

◆ previous_valve_number_()

size_t esphome::sprinkler::Sprinkler::previous_valve_number_ ( size_t  first_valve)
protected

Definition at line 967 of file sprinkler.cpp.

◆ pump_in_use()

bool esphome::sprinkler::Sprinkler::pump_in_use ( SprinklerSwitch pump_switch)

returns true if the pump the pointer points to is in use

Definition at line 816 of file sprinkler.cpp.

◆ pump_stop_delay_callback_()

void esphome::sprinkler::Sprinkler::pump_stop_delay_callback_ ( )
protected

◆ queue_enabled()

bool esphome::sprinkler::Sprinkler::queue_enabled ( )

returns true if the queue is enabled to run

Definition at line 632 of file sprinkler.cpp.

◆ queue_valve()

void esphome::sprinkler::Sprinkler::queue_valve ( optional< size_t >  valve_number,
optional< uint32_t >  run_duration 
)

adds a valve into the queue.

queued valves have priority over valves to be run as a part of a full cycle. NOTE: queued valves will always run, regardless of auto-advance and/or valve enable switches.

Definition at line 697 of file sprinkler.cpp.

◆ queued_valve()

optional< size_t > esphome::sprinkler::Sprinkler::queued_valve ( )

returns the number of the next valve in the queue, if any. check with 'has_value()'

Definition at line 801 of file sprinkler.cpp.

◆ repeat()

optional< uint32_t > esphome::sprinkler::Sprinkler::repeat ( )

returns the number of times the controller is set to repeat cycles, if at all. check with 'has_value()'

Definition at line 620 of file sprinkler.cpp.

◆ repeat_count()

optional< uint32_t > esphome::sprinkler::Sprinkler::repeat_count ( )

if a cycle is active, returns the number of times the controller has repeated the cycle. check with 'has_value()'

Definition at line 622 of file sprinkler.cpp.

◆ reset_cycle_states_()

void esphome::sprinkler::Sprinkler::reset_cycle_states_ ( )
protected

resets the cycle state for all valves

Definition at line 1103 of file sprinkler.cpp.

◆ reset_resume()

void esphome::sprinkler::Sprinkler::reset_resume ( )

resets resume state

Definition at line 786 of file sprinkler.cpp.

◆ resume()

void esphome::sprinkler::Sprinkler::resume ( )

resumes a cycle that was suspended using pause()

Definition at line 767 of file sprinkler.cpp.

◆ resume_or_start_full_cycle()

void esphome::sprinkler::Sprinkler::resume_or_start_full_cycle ( )

if a cycle was suspended using pause(), resumes it. otherwise calls start_full_cycle()

Definition at line 778 of file sprinkler.cpp.

◆ reverse()

bool esphome::sprinkler::Sprinkler::reverse ( )

returns true if reverse is enabled

Definition at line 639 of file sprinkler.cpp.

◆ set_auto_advance()

void esphome::sprinkler::Sprinkler::set_auto_advance ( bool  auto_advance)

if auto_advance is true, controller will iterate through all enabled valves

Definition at line 569 of file sprinkler.cpp.

◆ set_controller_auto_adv_switch()

void esphome::sprinkler::Sprinkler::set_controller_auto_adv_switch ( SprinklerControllerSwitch auto_adv_switch)

Definition at line 434 of file sprinkler.cpp.

◆ set_controller_main_switch()

void esphome::sprinkler::Sprinkler::set_controller_main_switch ( SprinklerControllerSwitch controller_switch)

configure important controller switches

Definition at line 414 of file sprinkler.cpp.

◆ set_controller_queue_enable_switch()

void esphome::sprinkler::Sprinkler::set_controller_queue_enable_switch ( SprinklerControllerSwitch queue_enable_switch)

Definition at line 440 of file sprinkler.cpp.

◆ set_controller_reverse_switch()

void esphome::sprinkler::Sprinkler::set_controller_reverse_switch ( SprinklerControllerSwitch reverse_switch)

Definition at line 446 of file sprinkler.cpp.

◆ set_manual_selection_delay()

void esphome::sprinkler::Sprinkler::set_manual_selection_delay ( uint32_t  manual_selection_delay)

set how long the controller should wait to activate a valve after next_valve() or previous_valve() is called

Definition at line 553 of file sprinkler.cpp.

◆ set_multiplier()

void esphome::sprinkler::Sprinkler::set_multiplier ( optional< float >  multiplier)

value multiplied by configured run times – used to extend or shorten the cycle

Definition at line 502 of file sprinkler.cpp.

◆ set_pump_start_delay()

void esphome::sprinkler::Sprinkler::set_pump_start_delay ( uint32_t  start_delay)

set how long the pump should start after the valve (when the pump is starting)

Definition at line 510 of file sprinkler.cpp.

◆ set_pump_state()

void esphome::sprinkler::Sprinkler::set_pump_state ( SprinklerSwitch pump_switch,
bool  state 
)

switches on/off a pump "safely" by checking that the new state will not conflict with another controller

Definition at line 852 of file sprinkler.cpp.

◆ set_pump_stop_delay()

void esphome::sprinkler::Sprinkler::set_pump_stop_delay ( uint32_t  stop_delay)

set how long the pump should stop after the valve (when the pump is starting)

Definition at line 515 of file sprinkler.cpp.

◆ set_pump_switch_off_during_valve_open_delay()

void esphome::sprinkler::Sprinkler::set_pump_switch_off_during_valve_open_delay ( bool  pump_switch_off_during_valve_open_delay)

if pump_switch_off_during_valve_open_delay is true, the controller will switch off the pump during the valve_open_delay interval

Definition at line 530 of file sprinkler.cpp.

◆ set_queue_enable()

void esphome::sprinkler::Sprinkler::set_queue_enable ( bool  queue_enable)

if queue_enable is true, controller will iterate through valves in the queue

Definition at line 577 of file sprinkler.cpp.

◆ set_repeat()

void esphome::sprinkler::Sprinkler::set_repeat ( optional< uint32_t >  repeat)

set the number of times to repeat a full cycle

Definition at line 575 of file sprinkler.cpp.

◆ set_reverse()

void esphome::sprinkler::Sprinkler::set_reverse ( bool  reverse)

if reverse is true, controller will iterate through all enabled valves in reverse (descending) order

Definition at line 583 of file sprinkler.cpp.

◆ set_timer_duration_()

void esphome::sprinkler::Sprinkler::set_timer_duration_ ( SprinklerTimerIndex  timer_index,
uint32_t  time 
)
protected

time is converted to milliseconds (ms) for set_timeout()

Definition at line 1273 of file sprinkler.cpp.

◆ set_valve_open_delay()

void esphome::sprinkler::Sprinkler::set_valve_open_delay ( uint32_t  valve_open_delay)

set how long the controller should wait to open/switch on the valve after it becomes active

Definition at line 534 of file sprinkler.cpp.

◆ set_valve_overlap()

void esphome::sprinkler::Sprinkler::set_valve_overlap ( uint32_t  valve_overlap)

set how long the controller should wait after opening a valve before closing the previous valve

Definition at line 543 of file sprinkler.cpp.

◆ set_valve_run_duration()

void esphome::sprinkler::Sprinkler::set_valve_run_duration ( optional< size_t >  valve_number,
optional< uint32_t >  run_duration 
)

set how long the valve should remain on/open. run_duration is time in seconds

Definition at line 561 of file sprinkler.cpp.

◆ set_valve_start_delay()

void esphome::sprinkler::Sprinkler::set_valve_start_delay ( uint32_t  start_delay)

set how long the valve should start after the pump (when the pump is stopping)

Definition at line 520 of file sprinkler.cpp.

◆ set_valve_stop_delay()

void esphome::sprinkler::Sprinkler::set_valve_stop_delay ( uint32_t  stop_delay)

set how long the valve should stop after the pump (when the pump is stopping)

Definition at line 525 of file sprinkler.cpp.

◆ setup()

void esphome::sprinkler::Sprinkler::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 368 of file sprinkler.cpp.

◆ shutdown()

void esphome::sprinkler::Sprinkler::shutdown ( bool  clear_queue = false)

turns off all valves, effectively shutting down the system.

Definition at line 741 of file sprinkler.cpp.

◆ sm_timer_callback_()

void esphome::sprinkler::Sprinkler::sm_timer_callback_ ( )
protected

Definition at line 1292 of file sprinkler.cpp.

◆ start_from_queue()

void esphome::sprinkler::Sprinkler::start_from_queue ( )

starts the controller from the first valve in the queue and disables auto_advance.

if the queue is empty, does nothing.

Definition at line 646 of file sprinkler.cpp.

◆ start_full_cycle()

void esphome::sprinkler::Sprinkler::start_full_cycle ( )

starts a full cycle of all enabled valves and enables auto_advance.

if no valves are enabled, all valves will be enabled.

Definition at line 665 of file sprinkler.cpp.

◆ start_single_valve()

void esphome::sprinkler::Sprinkler::start_single_valve ( optional< size_t >  valve_number)

activates a single valve and disables auto_advance.

Definition at line 681 of file sprinkler.cpp.

◆ start_timer_()

void esphome::sprinkler::Sprinkler::start_timer_ ( SprinklerTimerIndex  timer_index)
protected

Start/cancel/get status of valve timers.

Definition at line 1255 of file sprinkler.cpp.

◆ start_valve_()

void esphome::sprinkler::Sprinkler::start_valve_ ( SprinklerValveRunRequest req)
protected

loads an available SprinklerValveOperator (valve_op_) based on req and starts it (switches it on).

NOTE: if run_duration is zero, the valve's run_duration will be set based on the valve's configuration.

Definition at line 1051 of file sprinkler.cpp.

◆ state_as_str_()

std::string esphome::sprinkler::Sprinkler::state_as_str_ ( SprinklerState  state)
protected

return the current FSM state as a string

Definition at line 1233 of file sprinkler.cpp.

◆ time_remaining()

optional< uint32_t > esphome::sprinkler::Sprinkler::time_remaining ( )

returns the amount of time remaining in seconds for the active valve, if any. check with 'has_value()'

Definition at line 884 of file sprinkler.cpp.

◆ timer_active_()

bool esphome::sprinkler::Sprinkler::timer_active_ ( SprinklerTimerIndex  timer_index)
protected

returns true if the specified timer is active/running

Definition at line 1271 of file sprinkler.cpp.

◆ timer_cbf_()

std::function< void()> esphome::sprinkler::Sprinkler::timer_cbf_ ( SprinklerTimerIndex  timer_index)
protected

Definition at line 1279 of file sprinkler.cpp.

◆ timer_duration_()

uint32_t esphome::sprinkler::Sprinkler::timer_duration_ ( SprinklerTimerIndex  timer_index)
protected

returns time in milliseconds (ms)

Definition at line 1277 of file sprinkler.cpp.

◆ valve_cycle_complete_()

bool esphome::sprinkler::Sprinkler::valve_cycle_complete_ ( size_t  valve_number)
protected

returns true if valve's cycle is flagged as complete

Definition at line 953 of file sprinkler.cpp.

◆ valve_is_enabled_()

bool esphome::sprinkler::Sprinkler::valve_is_enabled_ ( size_t  valve_number)
protected

returns true if valve number is enabled

Definition at line 935 of file sprinkler.cpp.

◆ valve_name()

const char * esphome::sprinkler::Sprinkler::valve_name ( size_t  valve_number)

returns a pointer to a valve's name string object; returns nullptr if valve_number is invalid

Definition at line 791 of file sprinkler.cpp.

◆ valve_pump_switch()

SprinklerSwitch * esphome::sprinkler::Sprinkler::valve_pump_switch ( size_t  valve_number)

returns a pointer to a valve's pump switch object

Definition at line 919 of file sprinkler.cpp.

◆ valve_pump_switch_by_pump_index()

SprinklerSwitch * esphome::sprinkler::Sprinkler::valve_pump_switch_by_pump_index ( size_t  pump_index)

returns a pointer to a valve's pump switch object

Definition at line 926 of file sprinkler.cpp.

◆ valve_run_duration()

uint32_t esphome::sprinkler::Sprinkler::valve_run_duration ( size_t  valve_number)

returns valve_number's run duration in seconds

Definition at line 589 of file sprinkler.cpp.

◆ valve_run_duration_adjusted()

uint32_t esphome::sprinkler::Sprinkler::valve_run_duration_adjusted ( size_t  valve_number)

returns valve_number's run duration (in seconds) adjusted by multiplier_

Definition at line 596 of file sprinkler.cpp.

◆ valve_selection_callback_()

void esphome::sprinkler::Sprinkler::valve_selection_callback_ ( )
protected

callback functions for timers

Definition at line 1283 of file sprinkler.cpp.

◆ valve_switch()

SprinklerSwitch * esphome::sprinkler::Sprinkler::valve_switch ( size_t  valve_number)

returns a pointer to a valve's switch object

Definition at line 912 of file sprinkler.cpp.

Field Documentation

◆ active_req_

SprinklerValveRunRequest esphome::sprinkler::Sprinkler::active_req_
protected

The valve run request that is currently active.

Definition at line 465 of file sprinkler.h.

◆ auto_adv_sw_

SprinklerControllerSwitch* esphome::sprinkler::Sprinkler::auto_adv_sw_ {nullptr}
protected

Switches we'll present to the front end.

Definition at line 515 of file sprinkler.h.

◆ controller_sw_

SprinklerControllerSwitch* esphome::sprinkler::Sprinkler::controller_sw_ {nullptr}
protected

Definition at line 516 of file sprinkler.h.

◆ manual_selection_delay_

optional<uint32_t> esphome::sprinkler::Sprinkler::manual_selection_delay_
protected

Manual switching delay.

Definition at line 483 of file sprinkler.h.

◆ manual_valve_

optional<size_t> esphome::sprinkler::Sprinkler::manual_valve_
protected

The number of the manually selected valve currently selected.

Definition at line 468 of file sprinkler.h.

◆ max_queue_size_

const uint8_t esphome::sprinkler::Sprinkler::max_queue_size_ {100}
protected

Maximum allowed queue size.

Definition at line 445 of file sprinkler.h.

◆ multiplier_

float esphome::sprinkler::Sprinkler::multiplier_ {1.0}
protected

Sprinkler valve run time multiplier value.

Definition at line 492 of file sprinkler.h.

◆ next_req_

SprinklerValveRunRequest esphome::sprinkler::Sprinkler::next_req_
protected

The next run request for the controller to consume after active_req_ is complete.

Definition at line 474 of file sprinkler.h.

◆ other_controllers_

std::vector<Sprinkler *> esphome::sprinkler::Sprinkler::other_controllers_
protected

Other Sprinkler instances we should be aware of (used to check if pumps are in use)

Definition at line 512 of file sprinkler.h.

◆ paused_valve_

optional<size_t> esphome::sprinkler::Sprinkler::paused_valve_
protected

The number of the valve to resume from (if paused)

Definition at line 471 of file sprinkler.h.

◆ pump_

std::vector<SprinklerSwitch> esphome::sprinkler::Sprinkler::pump_
protected

Sprinkler valve pump objects.

Definition at line 498 of file sprinkler.h.

◆ pump_switch_off_during_valve_open_delay_

bool esphome::sprinkler::Sprinkler::pump_switch_off_during_valve_open_delay_ {false}
protected

Pump should be off during valve_open_delay interval.

Definition at line 448 of file sprinkler.h.

◆ queue_enable_sw_

SprinklerControllerSwitch* esphome::sprinkler::Sprinkler::queue_enable_sw_ {nullptr}
protected

Definition at line 517 of file sprinkler.h.

◆ queued_valves_

std::vector<SprinklerQueueItem> esphome::sprinkler::Sprinkler::queued_valves_
protected

Queue of valves to activate next, regardless of auto-advance.

Definition at line 495 of file sprinkler.h.

◆ repeat_count_

uint32_t esphome::sprinkler::Sprinkler::repeat_count_ {0}
protected

Number of times the full cycle has been repeated.

Definition at line 489 of file sprinkler.h.

◆ resume_duration_

optional<uint32_t> esphome::sprinkler::Sprinkler::resume_duration_
protected

Set from time_remaining() when paused.

Definition at line 480 of file sprinkler.h.

◆ reverse_sw_

SprinklerControllerSwitch* esphome::sprinkler::Sprinkler::reverse_sw_ {nullptr}
protected

Definition at line 518 of file sprinkler.h.

◆ sprinkler_resumeorstart_action_

std::unique_ptr<ResumeOrStartAction<> > esphome::sprinkler::Sprinkler::sprinkler_resumeorstart_action_
protected

Definition at line 521 of file sprinkler.h.

◆ sprinkler_shutdown_action_

std::unique_ptr<ShutdownAction<> > esphome::sprinkler::Sprinkler::sprinkler_shutdown_action_
protected

Definition at line 520 of file sprinkler.h.

◆ sprinkler_turn_off_automation_

std::unique_ptr<Automation<> > esphome::sprinkler::Sprinkler::sprinkler_turn_off_automation_
protected

Definition at line 523 of file sprinkler.h.

◆ sprinkler_turn_on_automation_

std::unique_ptr<Automation<> > esphome::sprinkler::Sprinkler::sprinkler_turn_on_automation_
protected

Definition at line 524 of file sprinkler.h.

◆ start_delay_

uint32_t esphome::sprinkler::Sprinkler::start_delay_ {0}
protected

Pump start/stop delay intervals.

Definition at line 458 of file sprinkler.h.

◆ start_delay_is_valve_delay_

bool esphome::sprinkler::Sprinkler::start_delay_is_valve_delay_ {false}
protected

Pump start/stop delay interval types.

Definition at line 454 of file sprinkler.h.

◆ state_

SprinklerState esphome::sprinkler::Sprinkler::state_ {IDLE}
protected

Sprinkler controller state.

Definition at line 462 of file sprinkler.h.

◆ stop_delay_

uint32_t esphome::sprinkler::Sprinkler::stop_delay_ {0}
protected

Definition at line 459 of file sprinkler.h.

◆ stop_delay_is_valve_delay_

bool esphome::sprinkler::Sprinkler::stop_delay_is_valve_delay_ {false}
protected

Definition at line 455 of file sprinkler.h.

◆ switching_delay_

optional<uint32_t> esphome::sprinkler::Sprinkler::switching_delay_
protected

Valve switching delay.

Definition at line 486 of file sprinkler.h.

◆ target_repeats_

optional<uint32_t> esphome::sprinkler::Sprinkler::target_repeats_
protected

Set the number of times to repeat a full cycle.

Definition at line 477 of file sprinkler.h.

◆ timer_

std::vector<SprinklerTimer> esphome::sprinkler::Sprinkler::timer_
protected
Initial value:
{
{this->name_ + "sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)},
{this->name_ + "vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)}}

Valve control timers.

Definition at line 507 of file sprinkler.h.

◆ valve_

std::vector<SprinklerValve> esphome::sprinkler::Sprinkler::valve_
protected

Sprinkler valve objects.

Definition at line 501 of file sprinkler.h.

◆ valve_op_

std::vector<SprinklerValveOperator> esphome::sprinkler::Sprinkler::valve_op_ {2}
protected

Sprinkler valve operator objects.

Definition at line 504 of file sprinkler.h.

◆ valve_overlap_

bool esphome::sprinkler::Sprinkler::valve_overlap_ {false}
protected

Sprinkler valve cycle should overlap.

Definition at line 451 of file sprinkler.h.


The documentation for this class was generated from the following files: