ESPHome 2026.2.1
Loading...
Searching...
No Matches
sprinkler.cpp
Go to the documentation of this file.
1#include "automation.h"
2#include "sprinkler.h"
3
6#include "esphome/core/log.h"
8#include <cinttypes>
9#include <utility>
10
11namespace esphome::sprinkler {
12
13static const char *const TAG = "sprinkler";
14
16 float value;
17 if (!this->restore_value_) {
18 value = this->initial_value_;
19 } else {
21 if (!this->pref_.load(&value)) {
22 if (!std::isnan(this->initial_value_)) {
23 value = this->initial_value_;
24 } else {
25 value = this->traits.get_min_value();
26 }
27 }
28 }
29 this->publish_state(value);
30}
31
33 this->set_trigger_.trigger(value);
34
35 this->publish_state(value);
36
37 if (this->restore_value_)
38 this->pref_.save(&value);
39}
40
41void SprinklerControllerNumber::dump_config() { LOG_NUMBER("", "Sprinkler Controller Number", this); }
42
44
46 // Loop is only enabled when f_ has a value (see setup())
47 auto s = (*this->f_)();
48 if (s.has_value()) {
49 this->publish_state(*s);
50 }
51}
52
54 if (this->prev_trigger_ != nullptr) {
56 }
57
58 if (state) {
59 this->prev_trigger_ = &this->turn_on_trigger_;
61 } else {
62 this->prev_trigger_ = &this->turn_off_trigger_;
64 }
65
66 this->publish_state(state);
67}
68
69void SprinklerControllerSwitch::set_state_lambda(std::function<optional<bool>()> &&f) { this->f_ = f; }
71
74 // Disable loop if no state lambda is set - nothing to poll
75 if (!this->f_.has_value()) {
76 this->disable_loop();
77 }
78}
79
80void SprinklerControllerSwitch::dump_config() { LOG_SWITCH("", "Sprinkler Switch", this); }
81
84 : controller_(controller), valve_(valve) {}
85
87 uint32_t now = App.get_loop_component_start_time();
88 if (now >= this->start_millis_) { // dummy check
89 switch (this->state_) {
90 case STARTING:
91 if (now > (this->start_millis_ + this->start_delay_)) {
92 this->run_(); // start_delay_ has been exceeded, so ensure both valves are on and update the state
93 }
94 break;
95
96 case ACTIVE:
97 if (now > (this->start_millis_ + this->start_delay_ + this->run_duration_)) {
98 this->stop(); // start_delay_ + run_duration_ has been exceeded, start shutting down
99 }
100 break;
101
102 case STOPPING:
103 if (now > (this->stop_millis_ + this->stop_delay_)) {
104 this->kill_(); // stop_delay_has been exceeded, ensure all valves are off
105 }
106 break;
107
108 default:
109 break;
110 }
111 } else { // perhaps millis() rolled over...or something else is horribly wrong!
112 this->stop(); // bail out (TODO: handle this highly unlikely situation better...)
113 }
114}
115
117 if (controller != nullptr) {
118 this->controller_ = controller;
119 }
120}
121
123 if (valve != nullptr) {
124 if (this->state_ != IDLE) { // Only kill if not already idle
125 this->kill_(); // ensure everything is off before we let go!
126 }
127 this->state_ = IDLE; // reset state
128 this->run_duration_ = 0; // reset to ensure the valve isn't started without updating it
129 this->start_millis_ = 0; // reset because (new) valve has not been started yet
130 this->stop_millis_ = 0; // reset because (new) valve has not been started yet
131 this->valve_ = valve; // finally, set the pointer to the new valve
132 }
133}
134
135void SprinklerValveOperator::set_run_duration(uint32_t run_duration) {
136 if (run_duration) {
137 this->run_duration_ = run_duration * 1000;
138 }
139}
140
141void SprinklerValveOperator::set_start_delay(uint32_t start_delay, bool start_delay_is_valve_delay) {
142 this->start_delay_is_valve_delay_ = start_delay_is_valve_delay;
143 this->start_delay_ = start_delay * 1000; // because 1000 milliseconds is one second
144}
145
146void SprinklerValveOperator::set_stop_delay(uint32_t stop_delay, bool stop_delay_is_valve_delay) {
147 this->stop_delay_is_valve_delay_ = stop_delay_is_valve_delay;
148 this->stop_delay_ = stop_delay * 1000; // because 1000 milliseconds is one second
149}
150
152 if (!this->run_duration_) { // can't start if zero run duration
153 return;
154 }
155 if (this->start_delay_ && (this->pump_switch() != nullptr)) {
156 this->state_ = STARTING; // STARTING state requires both a pump and a start_delay_
157 if (this->start_delay_is_valve_delay_) {
158 this->pump_on_();
159 } else if (!this->pump_switch()->state) { // if the pump is already on, wait to switch on the valve
160 this->valve_on_(); // to ensure consistent run time
161 }
162 } else {
163 this->run_(); // there is no start_delay_, so just start the pump and valve
164 }
165 this->stop_millis_ = 0;
166 this->start_millis_ = millis(); // save the time the start request was made
167}
168
170 if ((this->state_ == IDLE) || (this->state_ == STOPPING)) { // can't stop if already stopped or stopping
171 return;
172 }
173 if (this->stop_delay_ && (this->pump_switch() != nullptr)) {
174 this->state_ = STOPPING; // STOPPING state requires both a pump and a stop_delay_
175 if (this->stop_delay_is_valve_delay_) {
176 this->pump_off_();
177 } else {
178 this->valve_off_();
179 }
180 if (this->pump_switch()->state) { // if the pump is still on at this point, it may be in use...
181 this->valve_off_(); // ...so just switch the valve off now to ensure consistent run time
182 }
183 } else {
184 this->kill_(); // there is no stop_delay_, so just stop the pump and valve
185 }
186 this->stop_millis_ = millis(); // save the time the stop request was made
187}
188
189uint32_t SprinklerValveOperator::run_duration() { return this->run_duration_ / 1000; }
190
192 if (this->start_millis_ == 0) {
193 return this->run_duration(); // hasn't been started yet
194 }
195
196 if (this->stop_millis_) {
197 if (this->stop_millis_ - this->start_millis_ >= this->start_delay_ + this->run_duration_) {
198 return 0; // valve was active for more than its configured duration, so we are done
199 } else {
200 // we're stopped; return time remaining
201 return (this->run_duration_ - (this->stop_millis_ - this->start_millis_)) / 1000;
202 }
203 }
204
205 auto completed_millis = this->start_millis_ + this->start_delay_ + this->run_duration_;
206 if (completed_millis > millis()) {
207 return (completed_millis - millis()) / 1000; // running now
208 }
209 return 0; // run completed
210}
211
213
215 if ((this->controller_ == nullptr) || (this->valve_ == nullptr)) {
216 return nullptr;
217 }
218 if (this->valve_->pump_switch_index.has_value()) {
220 }
221 return nullptr;
222}
223
225 auto *pump = this->pump_switch();
226 if ((this->valve_ == nullptr) || (pump == nullptr)) { // safety first!
227 return;
228 }
229 if (this->controller_ == nullptr) { // safety first!
230 pump->turn_off(); // if no controller was set, just switch off the pump
231 } else { // ...otherwise, do it "safely"
232 auto state = this->state_; // this is silly, but...
233 this->state_ = BYPASS; // ...exclude me from the pump-in-use check that set_pump_state() does
234 this->controller_->set_pump_state(pump, false);
235 this->state_ = state;
236 }
237}
238
240 auto *pump = this->pump_switch();
241 if ((this->valve_ == nullptr) || (pump == nullptr)) { // safety first!
242 return;
243 }
244 if (this->controller_ == nullptr) { // safety first!
245 pump->turn_on(); // if no controller was set, just switch on the pump
246 } else { // ...otherwise, do it "safely"
247 auto state = this->state_; // this is silly, but...
248 this->state_ = BYPASS; // ...exclude me from the pump-in-use check that set_pump_state() does
249 this->controller_->set_pump_state(pump, true);
250 this->state_ = state;
251 }
252}
253
255 if ((this->valve_ == nullptr) || (this->valve_->valve_switch == nullptr)) { // safety first!
256 return;
257 }
258 if (this->valve_->valve_switch->state) {
259 this->valve_->valve_switch->turn_off();
260 }
261}
262
264 if ((this->valve_ == nullptr) || (this->valve_->valve_switch == nullptr)) { // safety first!
265 return;
266 }
267 if (!this->valve_->valve_switch->state) {
268 this->valve_->valve_switch->turn_on();
269 }
270}
271
273 this->state_ = IDLE;
274 this->valve_off_();
275 this->pump_off_();
276}
277
279 this->state_ = ACTIVE;
280 this->valve_on_();
281 this->pump_on_();
282}
283
285SprinklerValveRunRequest::SprinklerValveRunRequest(size_t valve_number, uint32_t run_duration,
286 SprinklerValveOperator *valve_op)
287 : valve_number_(valve_number), run_duration_(run_duration), valve_op_(valve_op) {}
288
290bool SprinklerValveRunRequest::has_valve_operator() { return !(this->valve_op_ == nullptr); }
291
293
295
296void SprinklerValveRunRequest::set_valve(size_t valve_number) {
297 this->valve_number_ = valve_number;
298 this->run_duration_ = 0;
299 this->valve_op_ = nullptr;
300 this->has_valve_ = true;
301}
302
304 if (valve_op != nullptr) {
305 this->valve_op_ = valve_op;
306 }
307}
308
310 this->has_valve_ = false;
311 this->origin_ = USER;
312 this->run_duration_ = 0;
313 this->valve_op_ = nullptr;
314}
315
317
319
321 if (this->has_valve_) {
322 return this->valve_number_;
323 }
324 return nullopt;
325}
326
328
330
332Sprinkler::Sprinkler(const char *name) : name_(name) {
333 // The `name` is stored for dump_config logging
334 this->timer_.init(2);
335 // Timer names only need to be unique within this component instance
336 this->timer_.push_back({"sm", false, 0, 0, std::bind(&Sprinkler::sm_timer_callback_, this)});
337 this->timer_.push_back({"vs", false, 0, 0, std::bind(&Sprinkler::valve_selection_callback_, this)});
338}
339
341 this->all_valves_off_(true);
342 // Start with loop disabled - nothing to do when idle
343 this->disable_loop();
344}
345
347 for (auto &vo : this->valve_op_) {
348 vo.loop();
349 }
350 if (this->prev_req_.has_request()) {
351 if (this->prev_req_.has_valve_operator() && this->prev_req_.valve_operator()->state() == IDLE) {
352 this->prev_req_.reset();
353 }
354 } else if (this->state_ == IDLE) {
355 // Nothing more to do - disable loop until next activation
356 this->disable_loop();
357 }
358}
359
361 auto new_valve_number = this->number_of_valves();
362 this->valve_.resize(new_valve_number + 1);
363 SprinklerValve *new_valve = &this->valve_[new_valve_number];
364
365 new_valve->controller_switch = valve_sw;
366 new_valve->controller_switch->set_state_lambda([this, new_valve_number]() -> optional<bool> {
367 auto *valve = this->valve_switch(new_valve_number);
368 auto *pump = this->valve_pump_switch(new_valve_number);
369 if (valve == nullptr) {
370 return false;
371 }
372 if (pump != nullptr) {
373 return valve->state && pump->state;
374 }
375 return valve->state;
376 });
377
378 new_valve->valve_turn_off_automation =
379 make_unique<Automation<>>(new_valve->controller_switch->get_turn_off_trigger());
380 new_valve->valve_shutdown_action = make_unique<sprinkler::ShutdownAction<>>(this);
381 new_valve->valve_turn_off_automation->add_actions({new_valve->valve_shutdown_action.get()});
382
383 new_valve->valve_turn_on_automation = make_unique<Automation<>>(new_valve->controller_switch->get_turn_on_trigger());
384 new_valve->valve_resumeorstart_action = make_unique<sprinkler::StartSingleValveAction<>>(this);
385 new_valve->valve_resumeorstart_action->set_valve_to_start(new_valve_number);
386 new_valve->valve_turn_on_automation->add_actions({new_valve->valve_resumeorstart_action.get()});
387
388 if (enable_sw != nullptr) {
389 new_valve->enable_switch = enable_sw;
390 }
391}
392
393void Sprinkler::add_controller(Sprinkler *other_controller) { this->other_controllers_.push_back(other_controller); }
394
396 this->controller_sw_ = controller_switch;
397 controller_switch->set_state_lambda([this]() -> optional<bool> {
398 for (size_t valve_number = 0; valve_number < this->number_of_valves(); valve_number++) {
399 if (this->valve_[valve_number].controller_switch->state) {
400 return true;
401 }
402 }
403 return this->active_req_.has_request();
404 });
405
406 this->sprinkler_turn_off_automation_ = make_unique<Automation<>>(controller_switch->get_turn_off_trigger());
407 this->sprinkler_shutdown_action_ = make_unique<sprinkler::ShutdownAction<>>(this);
409
410 this->sprinkler_turn_on_automation_ = make_unique<Automation<>>(controller_switch->get_turn_on_trigger());
411 this->sprinkler_resumeorstart_action_ = make_unique<sprinkler::ResumeOrStartAction<>>(this);
413}
414
416 this->auto_adv_sw_ = auto_adv_switch;
417}
418
420 this->queue_enable_sw_ = queue_enable_switch;
421}
422
424 this->reverse_sw_ = reverse_switch;
425}
426
428 this->standby_sw_ = standby_switch;
429
430 this->sprinkler_standby_turn_on_automation_ = make_unique<Automation<>>(standby_switch->get_turn_on_trigger());
431 this->sprinkler_standby_shutdown_action_ = make_unique<sprinkler::ShutdownAction<>>(this);
433}
434
436 this->multiplier_number_ = multiplier_number;
437}
438
440 this->repeat_number_ = repeat_number;
441}
442
443void Sprinkler::configure_valve_switch(size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration) {
444 if (this->is_a_valid_valve(valve_number)) {
445 this->valve_[valve_number].valve_switch = valve_switch;
446 this->valve_[valve_number].run_duration = run_duration;
447 }
448}
449
450void Sprinkler::configure_valve_pump_switch(size_t valve_number, switch_::Switch *pump_switch) {
451 if (this->is_a_valid_valve(valve_number)) {
452 for (size_t i = 0; i < this->pump_.size(); i++) { // check each existing registered pump
453 if (this->pump_[i] == pump_switch) { // if the "new" pump matches one we already have...
454 this->valve_[valve_number].pump_switch_index = i; // ...save its index in the pump vector...
455 return; // ...and we are done
456 }
457 } // if we end up here, no pumps matched, so add a new one
458 this->pump_.push_back(pump_switch);
459 this->valve_[valve_number].pump_switch_index = this->pump_.size() - 1; // save the index to the new pump
460 }
461}
462
464 SprinklerControllerNumber *run_duration_number) {
465 if (this->is_a_valid_valve(valve_number)) {
466 this->valve_[valve_number].run_duration_number = run_duration_number;
467 }
468}
469
471 if (!divider.has_value()) {
472 return;
473 }
474 if (divider.value() > 0) {
475 this->set_multiplier(1.0 / divider.value());
476 this->set_repeat(divider.value() - 1);
477 } else if (divider.value() == 0) {
478 this->set_multiplier(1.0);
479 this->set_repeat(0);
480 }
481}
482
484 if ((!multiplier.has_value()) || (multiplier.value() < 0)) {
485 return;
486 }
487 this->multiplier_ = multiplier.value();
488 if (this->multiplier_number_ == nullptr) {
489 return;
490 }
491 if (this->multiplier_number_->state == multiplier.value()) {
492 return;
493 }
494 auto call = this->multiplier_number_->make_call();
495 call.set_value(multiplier.value());
496 call.perform();
497}
498
500 this->next_prev_ignore_disabled_ = ignore_disabled;
501}
502
503void Sprinkler::set_pump_start_delay(uint32_t start_delay) {
504 this->start_delay_is_valve_delay_ = false;
505 this->start_delay_ = start_delay;
506}
507
508void Sprinkler::set_pump_stop_delay(uint32_t stop_delay) {
509 this->stop_delay_is_valve_delay_ = false;
510 this->stop_delay_ = stop_delay;
511}
512
513void Sprinkler::set_valve_start_delay(uint32_t start_delay) {
514 this->start_delay_is_valve_delay_ = true;
515 this->start_delay_ = start_delay;
516}
517
518void Sprinkler::set_valve_stop_delay(uint32_t stop_delay) {
519 this->stop_delay_is_valve_delay_ = true;
520 this->stop_delay_ = stop_delay;
521}
522
523void Sprinkler::set_pump_switch_off_during_valve_open_delay(bool pump_switch_off_during_valve_open_delay) {
524 this->pump_switch_off_during_valve_open_delay_ = pump_switch_off_during_valve_open_delay;
525}
526
527void Sprinkler::set_valve_open_delay(const uint32_t valve_open_delay) {
528 if (valve_open_delay > 0) {
529 this->valve_overlap_ = false;
530 this->switching_delay_ = valve_open_delay;
531 } else {
532 this->switching_delay_.reset();
533 }
534}
535
536void Sprinkler::set_valve_overlap(uint32_t valve_overlap) {
537 if (valve_overlap > 0) {
538 this->valve_overlap_ = true;
539 this->switching_delay_ = valve_overlap;
540 } else {
541 this->switching_delay_.reset();
542 }
543 this->pump_switch_off_during_valve_open_delay_ = false; // incompatible option
544}
545
546void Sprinkler::set_manual_selection_delay(uint32_t manual_selection_delay) {
547 if (manual_selection_delay > 0) {
548 this->manual_selection_delay_ = manual_selection_delay;
549 } else {
551 }
552}
553
554void Sprinkler::set_valve_run_duration(const optional<size_t> valve_number, const optional<uint32_t> run_duration) {
555 if (!valve_number.has_value() || !run_duration.has_value()) {
556 return;
557 }
558 if (!this->is_a_valid_valve(valve_number.value())) {
559 return;
560 }
561 this->valve_[valve_number.value()].run_duration = run_duration.value();
562 if (this->valve_[valve_number.value()].run_duration_number == nullptr) {
563 return;
564 }
565 if (this->valve_[valve_number.value()].run_duration_number->state == run_duration.value()) {
566 return;
567 }
568 auto call = this->valve_[valve_number.value()].run_duration_number->make_call();
569 if (this->valve_[valve_number.value()].run_duration_number->traits.get_unit_of_measurement_ref() == MIN_STR) {
570 call.set_value(run_duration.value() / 60.0);
571 } else {
572 call.set_value(run_duration.value());
573 }
574 call.perform();
575}
576
577void Sprinkler::set_auto_advance(const bool auto_advance) {
578 if (this->auto_adv_sw_ == nullptr) {
579 return;
580 }
581 if (this->auto_adv_sw_->state == auto_advance) {
582 return;
583 }
584 if (auto_advance) {
585 this->auto_adv_sw_->turn_on();
586 } else {
587 this->auto_adv_sw_->turn_off();
588 }
589}
590
592 this->target_repeats_ = repeat;
593 if (this->repeat_number_ == nullptr) {
594 return;
595 }
596 if (this->repeat_number_->state == repeat.value()) {
597 return;
598 }
599 auto call = this->repeat_number_->make_call();
600 call.set_value(repeat.value_or(0));
601 call.perform();
602}
603
604void Sprinkler::set_queue_enable(bool queue_enable) {
605 if (this->queue_enable_sw_ == nullptr) {
606 return;
607 }
608 if (this->queue_enable_sw_->state == queue_enable) {
609 return;
610 }
611 if (queue_enable) {
612 this->queue_enable_sw_->turn_on();
613 } else {
614 this->queue_enable_sw_->turn_off();
615 }
616}
617
618void Sprinkler::set_reverse(const bool reverse) {
619 if (this->reverse_sw_ == nullptr) {
620 return;
621 }
622 if (this->reverse_sw_->state == reverse) {
623 return;
624 }
625 if (reverse) {
626 this->reverse_sw_->turn_on();
627 } else {
628 this->reverse_sw_->turn_off();
629 }
630}
631
632void Sprinkler::set_standby(const bool standby) {
633 if (this->standby_sw_ == nullptr) {
634 return;
635 }
636 if (this->standby_sw_->state == standby) {
637 return;
638 }
639 if (standby) {
640 this->standby_sw_->turn_on();
641 } else {
642 this->standby_sw_->turn_off();
643 }
644}
645
646uint32_t Sprinkler::valve_run_duration(const size_t valve_number) {
647 if (!this->is_a_valid_valve(valve_number)) {
648 return 0;
649 }
650 if (this->valve_[valve_number].run_duration_number != nullptr) {
651 if (this->valve_[valve_number].run_duration_number->traits.get_unit_of_measurement_ref() == MIN_STR) {
652 return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state * 60));
653 } else {
654 return static_cast<uint32_t>(roundf(this->valve_[valve_number].run_duration_number->state));
655 }
656 }
657 return this->valve_[valve_number].run_duration;
658}
659
660uint32_t Sprinkler::valve_run_duration_adjusted(const size_t valve_number) {
661 uint32_t run_duration = 0;
662
663 if (this->is_a_valid_valve(valve_number)) {
664 run_duration = this->valve_run_duration(valve_number);
665 }
666 run_duration = static_cast<uint32_t>(roundf(run_duration * this->multiplier()));
667 // run_duration must not be less than any of these
668 if ((run_duration < this->start_delay_) || (run_duration < this->stop_delay_) ||
669 (run_duration < this->switching_delay_.value_or(0) * 2)) {
670 return std::max(this->switching_delay_.value_or(0) * 2, std::max(this->start_delay_, this->stop_delay_));
671 }
672 return run_duration;
673}
674
676 if (this->auto_adv_sw_ != nullptr) {
677 return this->auto_adv_sw_->state;
678 }
679 return true;
680}
681
683 if (this->multiplier_number_ != nullptr) {
684 return this->multiplier_number_->state;
685 }
686 return this->multiplier_;
687}
688
690 if (this->repeat_number_ != nullptr) {
691 return static_cast<uint32_t>(roundf(this->repeat_number_->state));
692 }
693 return this->target_repeats_;
694}
695
697 // if there is an active valve and auto-advance is enabled, we may be repeating, so return the count
698 if (this->active_req_.has_request() && this->auto_advance()) {
699 return this->repeat_count_;
700 }
701 return nullopt;
702}
703
705 if (this->queue_enable_sw_ != nullptr) {
706 return this->queue_enable_sw_->state;
707 }
708 return true;
709}
710
712 if (this->reverse_sw_ != nullptr) {
713 return this->reverse_sw_->state;
714 }
715 return false;
716}
717
719 if (this->standby_sw_ != nullptr) {
720 return this->standby_sw_->state;
721 }
722 return false;
723}
724
726 if (this->standby()) {
727 this->log_standby_warning_(LOG_STR("start_from_queue"));
728 return;
729 }
730 if (this->multiplier() == 0) {
731 this->log_multiplier_zero_warning_(LOG_STR("start_from_queue"));
732 return;
733 }
734 if (this->queued_valves_.empty()) {
735 return; // if there is nothing in the queue, don't do anything
736 }
737 if (this->queue_enabled() && this->active_valve().has_value()) {
738 return; // if there is already a valve running from the queue, do nothing
739 }
740
741 this->set_auto_advance(false);
742 this->set_queue_enable(true);
743
744 this->reset_cycle_states_(); // just in case auto-advance is switched on later
745 this->repeat_count_ = 0;
746 this->fsm_kick_(); // will automagically pick up from the queue (it has priority)
747}
748
750 if (this->standby()) {
751 this->log_standby_warning_(LOG_STR("start_full_cycle"));
752 return;
753 }
754 if (this->multiplier() == 0) {
755 this->log_multiplier_zero_warning_(LOG_STR("start_full_cycle"));
756 return;
757 }
758 if (this->auto_advance() && this->active_valve().has_value()) {
759 return; // if auto-advance is already enabled and there is already a valve running, do nothing
760 }
761
762 this->set_queue_enable(false);
763
764 this->prep_full_cycle_();
765 this->repeat_count_ = 0;
766 // if there is no active valve already, start the first valve in the cycle
767 if (!this->active_req_.has_request()) {
768 this->fsm_kick_();
769 }
770}
771
773 if (this->standby()) {
774 this->log_standby_warning_(LOG_STR("start_single_valve"));
775 return;
776 }
777 if (this->multiplier() == 0) {
778 this->log_multiplier_zero_warning_(LOG_STR("start_single_valve"));
779 return;
780 }
781 if (!valve_number.has_value() || (valve_number == this->active_valve())) {
782 return;
783 }
784
785 this->set_auto_advance(false);
786 this->set_queue_enable(false);
787
788 this->reset_cycle_states_(); // just in case auto-advance is switched on later
789 this->repeat_count_ = 0;
790 this->fsm_request_(valve_number.value(), run_duration.value_or(0));
791}
792
794 if (valve_number.has_value()) {
795 if (this->is_a_valid_valve(valve_number.value()) && (this->queued_valves_.size() < this->max_queue_size_)) {
796 SprinklerQueueItem item{valve_number.value(), run_duration.value()};
797 this->queued_valves_.insert(this->queued_valves_.begin(), item);
798 ESP_LOGD(TAG, "Valve %zu placed into queue with run duration of %" PRIu32 " seconds", valve_number.value_or(0),
799 run_duration.value_or(0));
800 }
801 }
802}
803
805 this->queued_valves_.clear();
806 ESP_LOGD(TAG, "Queue cleared");
807}
808
810 if (this->standby()) {
811 this->log_standby_warning_(LOG_STR("next_valve"));
812 return;
813 }
814
815 if (this->state_ == IDLE) {
816 this->reset_cycle_states_(); // just in case auto-advance is switched on later
817 }
818
819 this->manual_valve_ = this->next_valve_number_(
820 this->manual_valve_.value_or(this->active_req_.valve_as_opt().value_or(this->number_of_valves() - 1)),
821 !this->next_prev_ignore_disabled_, true);
822
823 if (!this->manual_valve_.has_value()) {
824 ESP_LOGD(TAG, "next_valve was called but no valve could be started; perhaps next_prev_ignore_disabled allows only "
825 "enabled valves and no valves are enabled?");
826 return;
827 }
828
832 } else {
833 this->fsm_request_(this->manual_valve_.value());
834 }
835}
836
838 if (this->standby()) {
839 this->log_standby_warning_(LOG_STR("previous_valve"));
840 return;
841 }
842
843 if (this->state_ == IDLE) {
844 this->reset_cycle_states_(); // just in case auto-advance is switched on later
845 }
846
847 this->manual_valve_ =
848 this->previous_valve_number_(this->manual_valve_.value_or(this->active_req_.valve_as_opt().value_or(0)),
849 !this->next_prev_ignore_disabled_, true);
850
851 if (!this->manual_valve_.has_value()) {
852 ESP_LOGD(TAG, "previous_valve was called but no valve could be started; perhaps next_prev_ignore_disabled allows "
853 "only enabled valves and no valves are enabled?");
854 return;
855 }
856
860 } else {
861 this->fsm_request_(this->manual_valve_.value());
862 }
863}
864
865void Sprinkler::shutdown(bool clear_queue) {
867 this->active_req_.reset();
868 this->manual_valve_.reset();
869 this->next_req_.reset();
870 for (auto &vo : this->valve_op_) {
871 vo.stop();
872 }
874 if (clear_queue) {
875 this->clear_queued_valves();
876 this->repeat_count_ = 0;
877 }
878}
879
881 if (this->paused_valve_.has_value() || !this->active_req_.has_request()) {
882 return; // we can't pause if we're already paused or if there is no active valve
883 }
884 this->paused_valve_ = this->active_valve();
886 this->shutdown(false);
887 ESP_LOGD(TAG, "Paused valve %zu with %" PRIu32 " seconds remaining", this->paused_valve_.value_or(0),
888 this->resume_duration_.value_or(0));
889}
890
892 if (this->standby()) {
893 this->log_standby_warning_(LOG_STR("resume"));
894 return;
895 }
896
897 if (this->paused_valve_.has_value() && (this->resume_duration_.has_value())) {
898 // Resume only if valve has not been completed yet
899 if (!this->valve_cycle_complete_(this->paused_valve_.value())) {
900 ESP_LOGD(TAG, "Resuming valve %zu with %" PRIu32 " seconds remaining", this->paused_valve_.value_or(0),
901 this->resume_duration_.value_or(0));
902 this->fsm_request_(this->paused_valve_.value(), this->resume_duration_.value());
903 }
904 this->reset_resume();
905 } else {
906 ESP_LOGD(TAG, "No valve to resume!");
907 }
908}
909
911 if (this->paused_valve_.has_value() && (this->resume_duration_.has_value())) {
912 this->resume();
913 } else {
914 this->start_full_cycle();
915 }
916}
917
919 this->paused_valve_.reset();
920 this->resume_duration_.reset();
921}
922
923const char *Sprinkler::valve_name(const size_t valve_number) {
924 if (this->is_a_valid_valve(valve_number)) {
925 return this->valve_[valve_number].controller_switch->get_name().c_str();
926 }
927 return nullptr;
928}
929
936
938 if (!this->valve_overlap_ && this->prev_req_.has_request() && this->prev_req_.has_valve_operator() &&
939 (this->prev_req_.valve_operator()->state() == STARTING || this->prev_req_.valve_operator()->state() == ACTIVE)) {
940 return this->prev_req_.valve_as_opt();
941 }
942 return this->active_req_.valve_as_opt();
943}
944
946
948 if (!this->queued_valves_.empty()) {
949 return this->queued_valves_.back().valve_number;
950 }
951 return nullopt;
952}
953
955
956size_t Sprinkler::number_of_valves() { return this->valve_.size(); }
957
958bool Sprinkler::is_a_valid_valve(const size_t valve_number) { return (valve_number < this->number_of_valves()); }
959
961 if (pump_switch == nullptr) {
962 return false; // we can't do anything if there's nothing to check
963 }
964 // a pump must be considered "in use" if a (distribution) valve it supplies is active. this means:
965 // - at least one SprinklerValveOperator:
966 // - has a valve loaded that depends on this pump
967 // - is in a state that depends on the pump: (ACTIVE and _possibly_ STARTING/STOPPING)
968 // - if NO SprinklerValveOperator is active but there is a run request pending (active_req_.has_request()) and the
969 // controller state is STARTING, valve open delay is configured but NOT pump_switch_off_during_valve_open_delay_
970 for (auto &vo : this->valve_op_) { // first, check if any SprinklerValveOperator has a valve dependent on this pump
971 if ((vo.state() != BYPASS) && (vo.pump_switch() != nullptr)) {
972 // the SprinklerValveOperator is configured with a pump; now check if it is the pump of interest
973 if (vo.pump_switch() == pump_switch) {
974 // now if the SprinklerValveOperator has a pump and it is either ACTIVE, is STARTING with a valve delay or
975 // is STOPPING with a valve delay, its pump can be considered "in use", so just return indicating this now
976 if ((vo.state() == ACTIVE) ||
977 ((vo.state() == STARTING) && this->start_delay_ && this->start_delay_is_valve_delay_) ||
978 ((vo.state() == STOPPING) && this->stop_delay_ && this->stop_delay_is_valve_delay_)) {
979 return true;
980 }
981 }
982 }
983 } // if we end up here, no SprinklerValveOperator was in a "give-away" state indicating that the pump is in use...
985 this->active_req_.has_request() && (this->state_ != STOPPING)) {
986 // ...the controller is configured to keep the pump on during a valve open delay, so just return
987 // whether or not the next valve shares the same pump
988 auto *valve_pump = this->valve_pump_switch(this->active_req_.valve());
989 if (valve_pump == nullptr) {
990 return false; // valve has no pump, so this pump isn't in use by it
991 }
992 return pump_switch == valve_pump;
993 }
994 return false;
995}
996
998 if (pump_switch == nullptr) {
999 return; // we can't do anything if there's nothing to check
1000 }
1001
1002 bool hold_pump_on = false;
1003
1004 for (auto &controller : this->other_controllers_) { // check if the pump is in use by another controller
1005 if (controller != this) { // dummy check
1006 if (controller->pump_in_use(pump_switch)) {
1007 hold_pump_on = true; // if another controller says it's using this pump, keep it on
1008 }
1009 }
1010 }
1011 if (hold_pump_on) {
1012 ESP_LOGD(TAG, "Leaving pump on because another controller instance is using it");
1013 }
1014
1015 if (state) { // ...and now we can set the new state of the switch
1016 pump_switch->turn_on();
1017 } else if (!hold_pump_on && !this->pump_in_use(pump_switch)) {
1018 pump_switch->turn_off();
1019 }
1020}
1021
1023 uint32_t total_time_remaining = 0;
1024
1025 for (size_t valve = 0; valve < this->number_of_valves(); valve++) {
1026 total_time_remaining += this->valve_run_duration_adjusted(valve);
1027 }
1028
1029 if (this->valve_overlap_) {
1030 total_time_remaining -= this->switching_delay_.value_or(0) * (this->number_of_valves() - 1);
1031 } else {
1032 total_time_remaining += this->switching_delay_.value_or(0) * (this->number_of_valves() - 1);
1033 }
1034
1035 return total_time_remaining;
1036}
1037
1039 uint32_t total_time_remaining = 0;
1040 uint32_t valve_count = 0;
1041
1042 for (size_t valve = 0; valve < this->number_of_valves(); valve++) {
1043 if (this->valve_is_enabled_(valve)) {
1044 total_time_remaining += this->valve_run_duration_adjusted(valve);
1045 valve_count++;
1046 }
1047 }
1048
1049 if (valve_count) {
1050 if (this->valve_overlap_) {
1051 total_time_remaining -= this->switching_delay_.value_or(0) * (valve_count - 1);
1052 } else {
1053 total_time_remaining += this->switching_delay_.value_or(0) * (valve_count - 1);
1054 }
1055 }
1056
1057 return total_time_remaining;
1058}
1059
1061 uint32_t total_time_remaining = 0;
1062 uint32_t enabled_valve_count = 0;
1063 uint32_t incomplete_valve_count = 0;
1064
1065 for (size_t valve = 0; valve < this->number_of_valves(); valve++) {
1066 if (this->valve_is_enabled_(valve)) {
1067 enabled_valve_count++;
1068 if (!this->valve_cycle_complete_(valve)) {
1069 if (!this->active_valve().has_value() || (valve != this->active_valve().value())) {
1070 total_time_remaining += this->valve_run_duration_adjusted(valve);
1071 incomplete_valve_count++;
1072 } else {
1073 // to get here, there must be an active valve and this valve must be equal to 'valve'
1074 if (this->active_req_.valve_operator() == nullptr) { // no SVO has been assigned yet so it hasn't started
1075 total_time_remaining += this->valve_run_duration_adjusted(valve);
1076 incomplete_valve_count++;
1077 }
1078 }
1079 }
1080 }
1081 }
1082
1083 if (incomplete_valve_count >= enabled_valve_count) {
1084 incomplete_valve_count--;
1085 }
1086 if (incomplete_valve_count) {
1087 if (this->valve_overlap_) {
1088 total_time_remaining -= this->switching_delay_.value_or(0) * incomplete_valve_count;
1089 } else {
1090 total_time_remaining += this->switching_delay_.value_or(0) * incomplete_valve_count;
1091 }
1092 }
1093
1094 return total_time_remaining;
1095}
1096
1098 uint32_t total_time_remaining = 0;
1099 uint32_t valve_count = 0;
1100
1101 for (auto &valve : this->queued_valves_) {
1102 if (valve.run_duration) {
1103 total_time_remaining += valve.run_duration;
1104 } else {
1105 total_time_remaining += this->valve_run_duration_adjusted(valve.valve_number);
1106 }
1107 valve_count++;
1108 }
1109
1110 if (valve_count) {
1111 if (this->valve_overlap_) {
1112 total_time_remaining -= this->switching_delay_.value_or(0) * (valve_count - 1);
1113 } else {
1114 total_time_remaining += this->switching_delay_.value_or(0) * (valve_count - 1);
1115 }
1116 }
1117
1118 return total_time_remaining;
1119}
1120
1122 if (this->active_req_.has_request()) { // first try to return the value based on active_req_...
1123 if (this->active_req_.valve_operator() != nullptr) {
1124 return this->active_req_.valve_operator()->time_remaining();
1125 }
1126 }
1127 if (this->prev_req_.has_request()) { // try to return the value based on prev_req_...
1128 if (this->prev_req_.valve_operator() != nullptr) {
1129 return this->prev_req_.valve_operator()->time_remaining();
1130 }
1131 }
1132 return nullopt;
1133}
1134
1136 if (!this->time_remaining_active_valve().has_value() && this->state_ == IDLE) {
1137 return nullopt;
1138 }
1139
1140 auto total_time_remaining = this->time_remaining_active_valve().value_or(0);
1141 if (this->auto_advance()) {
1142 total_time_remaining += this->total_cycle_time_enabled_incomplete_valves();
1143 if (this->repeat().value_or(0) > 0) {
1144 total_time_remaining +=
1145 (this->total_cycle_time_enabled_valves() * (this->repeat().value_or(0) - this->repeat_count().value_or(0)));
1146 }
1147 }
1148
1149 if (this->queue_enabled()) {
1150 total_time_remaining += this->total_queue_time();
1151 }
1152 return total_time_remaining;
1153}
1154
1156 if (this->state_ != IDLE) {
1157 return true;
1158 }
1159
1160 for (auto &controller : this->other_controllers_) {
1161 if (controller != this) { // dummy check
1162 if (controller->controller_state() != IDLE) {
1163 return true;
1164 }
1165 }
1166 }
1167 return false;
1168}
1169
1171 if (this->is_a_valid_valve(valve_number)) {
1172 return this->valve_[valve_number].controller_switch;
1173 }
1174 return nullptr;
1175}
1176
1178 if (this->is_a_valid_valve(valve_number)) {
1179 return this->valve_[valve_number].enable_switch;
1180 }
1181 return nullptr;
1182}
1183
1184switch_::Switch *Sprinkler::valve_switch(const size_t valve_number) {
1185 if (this->is_a_valid_valve(valve_number)) {
1186 return this->valve_[valve_number].valve_switch;
1187 }
1188 return nullptr;
1189}
1190
1192 if (this->is_a_valid_valve(valve_number) && this->valve_[valve_number].pump_switch_index.has_value()) {
1193 return this->pump_[this->valve_[valve_number].pump_switch_index.value()];
1194 }
1195 return nullptr;
1196}
1197
1199 if (pump_index < this->pump_.size()) {
1200 return this->pump_[pump_index];
1201 }
1202 return nullptr;
1203}
1204
1205bool Sprinkler::valve_is_enabled_(const size_t valve_number) {
1206 if (this->is_a_valid_valve(valve_number)) {
1207 if (this->valve_[valve_number].enable_switch != nullptr) {
1208 return this->valve_[valve_number].enable_switch->state;
1209 } else {
1210 return true;
1211 }
1212 }
1213 return false;
1214}
1215
1216void Sprinkler::mark_valve_cycle_complete_(const size_t valve_number) {
1217 if (this->is_a_valid_valve(valve_number)) {
1218 ESP_LOGD(TAG, "Marking valve %u complete", valve_number);
1219 this->valve_[valve_number].valve_cycle_complete = true;
1220 }
1221}
1222
1223bool Sprinkler::valve_cycle_complete_(const size_t valve_number) {
1224 if (this->is_a_valid_valve(valve_number)) {
1225 return this->valve_[valve_number].valve_cycle_complete;
1226 }
1227 return false;
1228}
1229
1230optional<size_t> Sprinkler::next_valve_number_(const optional<size_t> first_valve, const bool include_disabled,
1231 const bool include_complete) {
1232 auto valve = first_valve.value_or(0);
1233 size_t start = first_valve.has_value() ? 1 : 0;
1234
1235 if (!this->is_a_valid_valve(valve)) {
1236 valve = 0;
1237 }
1238
1239 for (size_t offset = start; offset < this->number_of_valves(); offset++) {
1240 auto valve_of_interest = valve + offset;
1241 if (!this->is_a_valid_valve(valve_of_interest)) {
1242 valve_of_interest -= this->number_of_valves();
1243 }
1244
1245 if ((this->valve_is_enabled_(valve_of_interest) || include_disabled) &&
1246 (!this->valve_cycle_complete_(valve_of_interest) || include_complete)) {
1247 return valve_of_interest;
1248 }
1249 }
1250 return nullopt;
1251}
1252
1253optional<size_t> Sprinkler::previous_valve_number_(const optional<size_t> first_valve, const bool include_disabled,
1254 const bool include_complete) {
1255 auto valve = first_valve.value_or(this->number_of_valves() - 1);
1256 size_t start = first_valve.has_value() ? 1 : 0;
1257
1258 if (!this->is_a_valid_valve(valve)) {
1259 valve = this->number_of_valves() - 1;
1260 }
1261
1262 for (size_t offset = start; offset < this->number_of_valves(); offset++) {
1263 auto valve_of_interest = valve - offset;
1264 if (!this->is_a_valid_valve(valve_of_interest)) {
1265 valve_of_interest += this->number_of_valves();
1266 }
1267
1268 if ((this->valve_is_enabled_(valve_of_interest) || include_disabled) &&
1269 (!this->valve_cycle_complete_(valve_of_interest) || include_complete)) {
1270 return valve_of_interest;
1271 }
1272 }
1273 return nullopt;
1274}
1275
1277 if (this->reverse()) {
1278 return this->previous_valve_number_(first_valve, false, false);
1279 }
1280 return this->next_valve_number_(first_valve, false, false);
1281}
1282
1284 if (this->active_req_.has_request()) {
1285 this->prev_req_ = this->active_req_;
1286 } else {
1287 this->prev_req_.reset();
1288 }
1289
1290 if (this->next_req_.has_request()) {
1291 if (!this->next_req_.run_duration()) { // ensure the run duration is set correctly for consumption later on
1293 }
1294 return; // there is already a request pending
1295 } else if (this->queue_enabled() && !this->queued_valves_.empty()) {
1296 this->next_req_.set_valve(this->queued_valves_.back().valve_number);
1298 if (this->queued_valves_.back().run_duration) {
1299 this->next_req_.set_run_duration(this->queued_valves_.back().run_duration);
1300 this->queued_valves_.pop_back();
1301 } else if (this->multiplier()) {
1302 this->next_req_.set_run_duration(this->valve_run_duration_adjusted(this->queued_valves_.back().valve_number));
1303 this->queued_valves_.pop_back();
1304 } else {
1305 this->next_req_.reset();
1306 }
1307 } else if (this->auto_advance() && this->multiplier()) {
1308 if (this->next_valve_number_in_cycle_(first_valve).has_value()) {
1309 // if there is another valve to run as a part of a cycle, load that
1310 this->next_req_.set_valve(this->next_valve_number_in_cycle_(first_valve).value_or(0));
1313 this->valve_run_duration_adjusted(this->next_valve_number_in_cycle_(first_valve).value_or(0)));
1314 } else if ((this->repeat_count_++ < this->repeat().value_or(0))) {
1315 ESP_LOGD(TAG, "Repeating - starting cycle %" PRIu32 " of %" PRIu32, this->repeat_count_ + 1,
1316 this->repeat().value_or(0) + 1);
1317 // if there are repeats remaining and no more valves were left in the cycle, start a new cycle
1318 this->prep_full_cycle_();
1319 if (this->next_valve_number_in_cycle_().has_value()) { // this should always succeed here, but just in case...
1320 this->next_req_.set_valve(this->next_valve_number_in_cycle_().value_or(0));
1323 this->valve_run_duration_adjusted(this->next_valve_number_in_cycle_().value_or(0)));
1324 }
1325 }
1326 }
1327}
1328
1330 for (size_t valve_number = 0; valve_number < this->number_of_valves(); valve_number++) {
1331 if (this->valve_is_enabled_(valve_number))
1332 return true;
1333 }
1334 return false;
1335}
1336
1338 if (!req->has_request()) {
1339 return; // we can't do anything if the request contains nothing
1340 }
1341 if (!this->is_a_valid_valve(req->valve())) {
1342 return; // we can't do anything if the valve number isn't valid
1343 }
1344 // Enable loop to monitor valve operator states
1345 this->enable_loop();
1346 for (auto &vo : this->valve_op_) { // find the first available SprinklerValveOperator, load it and start it up
1347 if (vo.state() == IDLE) {
1348 auto run_duration = req->run_duration() ? req->run_duration() : this->valve_run_duration_adjusted(req->valve());
1349 ESP_LOGD(TAG, "%s is starting valve %zu for %" PRIu32 " seconds, cycle %" PRIu32 " of %" PRIu32,
1350 LOG_STR_ARG(this->req_as_str_(req->request_is_from())), req->valve(), run_duration,
1351 this->repeat_count_ + 1, this->repeat().value_or(0) + 1);
1352 req->set_valve_operator(&vo);
1353 vo.set_controller(this);
1354 vo.set_valve(&this->valve_[req->valve()]);
1355 vo.set_run_duration(run_duration);
1356 vo.set_start_delay(this->start_delay_, this->start_delay_is_valve_delay_);
1357 vo.set_stop_delay(this->stop_delay_, this->stop_delay_is_valve_delay_);
1358 vo.start();
1359 return;
1360 }
1361 }
1362}
1363
1364void Sprinkler::all_valves_off_(const bool include_pump) {
1365 for (size_t valve_index = 0; valve_index < this->number_of_valves(); valve_index++) {
1366 auto *valve_sw = this->valve_[valve_index].valve_switch;
1367 if ((valve_sw != nullptr) && valve_sw->state) {
1368 valve_sw->turn_off();
1369 }
1370 if (include_pump) {
1371 this->set_pump_state(this->valve_pump_switch(valve_index), false);
1372 }
1373 }
1374 ESP_LOGD(TAG, "All valves stopped%s", include_pump ? ", including pumps" : "");
1375}
1376
1378 this->set_auto_advance(true);
1379
1380 if (!this->any_valve_is_enabled_()) {
1381 for (auto &valve : this->valve_) {
1382 if (valve.enable_switch != nullptr) {
1383 if (!valve.enable_switch->state) {
1384 valve.enable_switch->turn_on();
1385 }
1386 }
1387 }
1388 }
1389 this->reset_cycle_states_();
1390}
1391
1393 for (auto &valve : this->valve_) {
1394 valve.valve_cycle_complete = false;
1395 }
1396}
1397
1398void Sprinkler::fsm_request_(size_t requested_valve, uint32_t requested_run_duration) {
1399 this->next_req_.set_valve(requested_valve);
1400 this->next_req_.set_run_duration(requested_run_duration);
1401 // if state is IDLE or ACTIVE, call fsm_transition_() to start it immediately;
1402 // otherwise, fsm_transition() will pick up next_req_ at the next appropriate transition
1403 this->fsm_kick_();
1404}
1405
1407 if ((this->state_ == IDLE) || (this->state_ == ACTIVE)) {
1408 this->fsm_transition_();
1409 }
1410}
1411
1413 ESP_LOGVV(TAG, "fsm_transition_ called; state is %s", LOG_STR_ARG(this->state_as_str_(this->state_)));
1414 switch (this->state_) {
1415 case IDLE: // the system was off -> start it up
1416 // advances to ACTIVE
1418 break;
1419
1420 case ACTIVE:
1421 // advances to STOPPING or ACTIVE (again)
1423 break;
1424
1425 case STARTING: {
1426 // follows valve open delay interval
1427 uint32_t timer_duration = this->active_req_.run_duration();
1428 if (timer_duration > this->switching_delay_.value_or(0)) {
1429 timer_duration -= this->switching_delay_.value_or(0);
1430 }
1431 this->set_timer_duration_(sprinkler::TIMER_SM, timer_duration);
1433 this->start_valve_(&this->active_req_);
1434 this->state_ = ACTIVE;
1435 if (this->next_req_.has_request()) {
1436 // another valve has been requested, so restart the timer so we pick it up quickly
1439 }
1440 break;
1441 }
1442
1443 case STOPPING:
1444 // stop_delay_ has elapsed so just shut everything off
1445 this->active_req_.reset();
1446 this->manual_valve_.reset();
1447 this->all_valves_off_(true);
1448 this->state_ = IDLE;
1449 break;
1450
1451 default:
1452 break;
1453 }
1454 if (this->next_req_.has_request() && (this->state_ == IDLE)) {
1455 // another valve has been requested, so restart the timer so we pick it up quickly
1458 }
1459 ESP_LOGVV(TAG, "fsm_transition_ complete; new state is %s", LOG_STR_ARG(this->state_as_str_(this->state_)));
1460}
1461
1464
1465 if (this->next_req_.has_request()) { // there is a valve to run...
1466 this->active_req_.set_valve(this->next_req_.valve());
1469 this->next_req_.reset();
1470
1471 uint32_t timer_duration = this->active_req_.run_duration();
1472 if (timer_duration > this->switching_delay_.value_or(0)) {
1473 timer_duration -= this->switching_delay_.value_or(0);
1474 }
1475 this->set_timer_duration_(sprinkler::TIMER_SM, timer_duration);
1477 this->start_valve_(&this->active_req_);
1478 this->state_ = ACTIVE;
1479 }
1480}
1481
1483 if (!this->active_req_.has_request()) { // dummy check...
1485 return;
1486 }
1487
1488 if (!this->timer_active_(sprinkler::TIMER_SM)) { // only flag the valve as "complete" if the timer finished
1489 if ((this->active_req_.request_is_from() == CYCLE) || (this->active_req_.request_is_from() == USER)) {
1491 }
1492 } else {
1493 ESP_LOGD(TAG, "Valve cycle interrupted - NOT flagging valve as complete and stopping current valve");
1494 for (auto &vo : this->valve_op_) {
1495 vo.stop();
1496 }
1497 }
1498
1500
1501 if (this->next_req_.has_request()) { // there is another valve to run...
1502 auto *active_pump = this->valve_pump_switch(this->active_req_.valve());
1503 auto *next_pump = this->valve_pump_switch(this->next_req_.valve());
1504 bool same_pump = (active_pump != nullptr) && (next_pump != nullptr) && (active_pump == next_pump);
1505
1506 this->active_req_.set_valve(this->next_req_.valve());
1509 this->next_req_.reset();
1510
1511 // this->state_ = ACTIVE; // state isn't changing
1512 if (this->valve_overlap_ || !this->switching_delay_.has_value()) {
1513 uint32_t timer_duration = this->active_req_.run_duration();
1514 if (timer_duration > this->switching_delay_.value_or(0)) {
1515 timer_duration -= this->switching_delay_.value_or(0);
1516 }
1517 this->set_timer_duration_(sprinkler::TIMER_SM, timer_duration);
1519 this->start_valve_(&this->active_req_);
1520 } else {
1521 this->set_timer_duration_(
1523 this->switching_delay_.value() * 2 +
1524 (this->pump_switch_off_during_valve_open_delay_ && same_pump ? this->stop_delay_ : 0));
1526 this->state_ = STARTING;
1527 }
1528 } else { // there is NOT another valve to run...
1530 }
1531}
1532
1539
1540void Sprinkler::log_standby_warning_(const LogString *method_name) {
1541 ESP_LOGW(TAG, "%s called but standby is enabled; no action taken", LOG_STR_ARG(method_name));
1542}
1543
1544void Sprinkler::log_multiplier_zero_warning_(const LogString *method_name) {
1545 ESP_LOGW(TAG, "%s called but multiplier is set to zero; no action taken", LOG_STR_ARG(method_name));
1546}
1547
1548// Request origin strings indexed by SprinklerValveRunRequestOrigin enum (0-2): USER, CYCLE, QUEUE
1549PROGMEM_STRING_TABLE(SprinklerRequestOriginStrings, "USER", "CYCLE", "QUEUE", "UNKNOWN");
1550
1552 return SprinklerRequestOriginStrings::get_log_str(static_cast<uint8_t>(origin),
1553 SprinklerRequestOriginStrings::LAST_INDEX);
1554}
1555
1556// Sprinkler state strings indexed by SprinklerState enum (0-4): IDLE, STARTING, ACTIVE, STOPPING, BYPASS
1557PROGMEM_STRING_TABLE(SprinklerStateStrings, "IDLE", "STARTING", "ACTIVE", "STOPPING", "BYPASS", "UNKNOWN");
1558
1560 return SprinklerStateStrings::get_log_str(static_cast<uint8_t>(state), SprinklerStateStrings::LAST_INDEX);
1561}
1562
1564 if (this->timer_duration_(timer_index) > 0) {
1565 this->set_timeout(this->timer_[timer_index].name, this->timer_duration_(timer_index),
1566 this->timer_cbf_(timer_index));
1567 this->timer_[timer_index].start_time = millis();
1568 this->timer_[timer_index].active = true;
1569 }
1570 ESP_LOGVV(TAG, "Timer %zu started for %" PRIu32 " sec", static_cast<size_t>(timer_index),
1571 this->timer_duration_(timer_index) / 1000);
1572}
1573
1575 this->timer_[timer_index].active = false;
1576 return this->cancel_timeout(this->timer_[timer_index].name);
1577}
1578
1579bool Sprinkler::timer_active_(const SprinklerTimerIndex timer_index) { return this->timer_[timer_index].active; }
1580
1581void Sprinkler::set_timer_duration_(const SprinklerTimerIndex timer_index, const uint32_t time) {
1582 this->timer_[timer_index].time = 1000 * time;
1583}
1584
1585uint32_t Sprinkler::timer_duration_(const SprinklerTimerIndex timer_index) { return this->timer_[timer_index].time; }
1586
1587std::function<void()> Sprinkler::timer_cbf_(const SprinklerTimerIndex timer_index) {
1588 return this->timer_[timer_index].func;
1589}
1590
1592 this->timer_[sprinkler::TIMER_VALVE_SELECTION].active = false;
1593 ESP_LOGVV(TAG, "Valve selection timer expired");
1594 if (this->manual_valve_.has_value()) {
1595 this->fsm_request_(this->manual_valve_.value());
1596 this->manual_valve_.reset();
1597 }
1598}
1599
1601 this->timer_[sprinkler::TIMER_SM].active = false;
1602 ESP_LOGVV(TAG, "State machine timer expired");
1603 this->fsm_transition_();
1604}
1605
1607 ESP_LOGCONFIG(TAG, "Sprinkler Controller -- %s", this->name_);
1608 if (this->manual_selection_delay_.has_value()) {
1609 ESP_LOGCONFIG(TAG, " Manual Selection Delay: %" PRIu32 " seconds", this->manual_selection_delay_.value_or(0));
1610 }
1611 if (this->repeat().has_value()) {
1612 ESP_LOGCONFIG(TAG, " Repeat Cycles: %" PRIu32 " times", this->repeat().value_or(0));
1613 }
1614 if (this->start_delay_) {
1615 if (this->start_delay_is_valve_delay_) {
1616 ESP_LOGCONFIG(TAG, " Pump Start Valve Delay: %" PRIu32 " seconds", this->start_delay_);
1617 } else {
1618 ESP_LOGCONFIG(TAG, " Pump Start Pump Delay: %" PRIu32 " seconds", this->start_delay_);
1619 }
1620 }
1621 if (this->stop_delay_) {
1622 if (this->stop_delay_is_valve_delay_) {
1623 ESP_LOGCONFIG(TAG, " Pump Stop Valve Delay: %" PRIu32 " seconds", this->stop_delay_);
1624 } else {
1625 ESP_LOGCONFIG(TAG, " Pump Stop Pump Delay: %" PRIu32 " seconds", this->stop_delay_);
1626 }
1627 }
1628 if (this->switching_delay_.has_value()) {
1629 if (this->valve_overlap_) {
1630 ESP_LOGCONFIG(TAG, " Valve Overlap: %" PRIu32 " seconds", this->switching_delay_.value_or(0));
1631 } else {
1632 ESP_LOGCONFIG(TAG,
1633 " Valve Open Delay: %" PRIu32 " seconds\n"
1634 " Pump Switch Off During Valve Open Delay: %s",
1636 }
1637 }
1638 for (size_t valve_number = 0; valve_number < this->number_of_valves(); valve_number++) {
1639 ESP_LOGCONFIG(TAG,
1640 " Valve %zu:\n"
1641 " Name: %s\n"
1642 " Run Duration: %" PRIu32 " seconds",
1643 valve_number, this->valve_name(valve_number), this->valve_run_duration(valve_number));
1644 }
1645 if (!this->pump_.empty()) {
1646 ESP_LOGCONFIG(TAG, " Total number of pumps: %zu", this->pump_.size());
1647 }
1648 if (!this->valve_.empty()) {
1649 ESP_LOGCONFIG(TAG, " Total number of valves: %zu", this->valve_.size());
1650 }
1651}
1652
1653} // namespace esphome::sprinkler
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.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition component.h:429
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
Definition component.h:451
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> && f
Definition component.h:373
bool save(const T *src)
Definition preferences.h:21
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
void trigger(const Ts &...x)
Inform the parent automation that the event has triggered.
Definition automation.h:279
void stop_action()
Stop any action connected to this trigger.
Definition automation.h:287
NumberCall & set_value(float value)
NumberCall make_call()
Definition number.h:35
void publish_state(float state)
Definition number.cpp:22
NumberTraits traits
Definition number.h:39
bool has_value() const
Definition optional.h:92
value_type value_or(U const &v) const
Definition optional.h:98
value_type const & value() const
Definition optional.h:94
void set_state_lambda(std::function< optional< bool >()> &&f)
Definition sprinkler.cpp:69
optional< std::function< optional< bool >()> > f_
Definition sprinkler.h:109
void set_controller_standby_switch(SprinklerControllerSwitch *standby_switch)
void add_controller(Sprinkler *other_controller)
add another controller to the controller so it can check if pumps/main valves are in use
FixedVector< SprinklerTimer > timer_
Valve control timers - FixedVector enforces that this can never grow beyond init() size.
Definition sprinkler.h:558
void resume()
resumes a cycle that was suspended using pause()
void fsm_transition_to_shutdown_()
starts up the system from IDLE state
optional< size_t > previous_valve_number_(optional< size_t > first_valve=nullopt, bool include_disabled=true, bool include_complete=true)
returns the number of the previous valve in the vector or nullopt if no valves match criteria
bool is_a_valid_valve(size_t valve_number)
returns true if valve number is valid
bool reverse()
returns true if reverse is enabled
bool next_prev_ignore_disabled_
When set to true, the next and previous actions will skip disabled valves.
Definition sprinkler.h:491
void reset_resume()
resets resume state
SprinklerControllerNumber * repeat_number_
Definition sprinkler.h:572
bool valve_is_enabled_(size_t valve_number)
returns true if valve number is enabled
SprinklerState state_
Sprinkler controller state.
Definition sprinkler.h:510
void next_valve()
advances to the next valve (numerically)
void log_standby_warning_(const LogString *method_name)
log error message when a method is called but standby is enabled
uint32_t repeat_count_
Number of times the full cycle has been repeated.
Definition sprinkler.h:540
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.
std::vector< SprinklerValve > valve_
Sprinkler valve objects.
Definition sprinkler.h:552
void queue_valve(optional< size_t > valve_number, optional< uint32_t > run_duration)
adds a valve into the queue.
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
optional< uint32_t > resume_duration_
Set from time_remaining() when paused.
Definition sprinkler.h:531
void set_repeat(optional< uint32_t > repeat)
set the number of times to repeat a full cycle
float multiplier()
returns the current value of the multiplier
bool auto_advance()
returns true if auto_advance is enabled
uint32_t total_queue_time()
returns the amount of time in seconds required for all valves in the queue
void fsm_transition_from_shutdown_()
starts up the system from IDLE state
optional< uint32_t > repeat_count()
if a cycle is active, returns the number of times the controller has repeated the cycle....
void all_valves_off_(bool include_pump=false)
turns off/closes all valves, including pump if include_pump is true
SprinklerValveRunRequest prev_req_
The previous run request the controller processed.
Definition sprinkler.h:519
void start_valve_(SprinklerValveRunRequest *req)
loads an available SprinklerValveOperator (valve_op_) based on req and starts it (switches it on).
optional< uint32_t > repeat()
returns the number of times the controller is set to repeat cycles, if at all. check with 'has_value(...
void mark_valve_cycle_complete_(size_t valve_number)
marks a valve's cycle as complete
void set_pump_stop_delay(uint32_t stop_delay)
set how long the pump should stop after the valve (when the pump is starting)
void log_multiplier_zero_warning_(const LogString *method_name)
log error message when a method is called but multiplier is zero
optional< size_t > paused_valve()
returns the number of the valve that is paused, if any. check with 'has_value()'
void set_controller_reverse_switch(SprinklerControllerSwitch *reverse_switch)
uint32_t start_delay_
Pump start/stop delay intervals.
Definition sprinkler.h:504
const LogString * req_as_str_(SprinklerValveRunRequestOrigin origin)
return the specified SprinklerValveRunRequestOrigin as a string
void set_valve_overlap(uint32_t valve_overlap)
set how long the controller should wait after opening a valve before closing the previous valve
optional< SprinklerValveRunRequestOrigin > active_valve_request_is_from()
returns what invoked the valve that is currently active, if any. check with 'has_value()'
void set_reverse(bool reverse)
if reverse is true, controller will iterate through all enabled valves in reverse (descending) order
SprinklerControllerNumber * multiplier_number_
Number components we'll present to the front end.
Definition sprinkler.h:571
std::vector< SprinklerValveOperator > valve_op_
Sprinkler valve operator objects.
Definition sprinkler.h:555
SprinklerControllerSwitch * enable_switch(size_t valve_number)
returns a pointer to a valve's enable switch object
void start_full_cycle()
starts a full cycle of all enabled valves and enables auto_advance.
SprinklerControllerSwitch * controller_sw_
Definition sprinkler.h:565
void set_valve_stop_delay(uint32_t stop_delay)
set how long the valve should stop after the pump (when the pump is stopping)
void set_controller_queue_enable_switch(SprinklerControllerSwitch *queue_enable_switch)
void set_pump_state(switch_::Switch *pump_switch, bool state)
switches on/off a pump "safely" by checking that the new state will not conflict with another control...
optional< uint32_t > target_repeats_
Set the number of times to repeat a full cycle.
Definition sprinkler.h:528
void set_controller_main_switch(SprinklerControllerSwitch *controller_switch)
configure important controller switches
switch_::Switch * valve_switch(size_t valve_number)
returns a pointer to a valve's switch object
optional< uint32_t > time_remaining_current_operation()
returns the amount of time remaining in seconds for all valves remaining, including the active valve,...
const LogString * state_as_str_(SprinklerState state)
return the specified SprinklerState state as a string
SprinklerControllerSwitch * reverse_sw_
Definition sprinkler.h:567
optional< uint32_t > switching_delay_
Valve switching delay.
Definition sprinkler.h:537
void fsm_kick_()
kicks the state machine to advance, starting it if it is not already active
void shutdown(bool clear_queue=false)
turns off all valves, effectively shutting down the system.
SprinklerValveRunRequest active_req_
The valve run request that is currently active.
Definition sprinkler.h:513
bool any_controller_is_active()
returns true if this or any sprinkler controller this controller knows about is active
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
std::vector< switch_::Switch * > pump_
Sprinkler valve pump switches.
Definition sprinkler.h:549
bool start_delay_is_valve_delay_
Pump start/stop delay interval types.
Definition sprinkler.h:500
optional< size_t > manual_valve_
The number of the manually selected valve currently selected.
Definition sprinkler.h:522
bool pump_switch_off_during_valve_open_delay_
Pump should be off during valve_open_delay interval.
Definition sprinkler.h:494
bool cancel_timer_(SprinklerTimerIndex timer_index)
SprinklerControllerSwitch * queue_enable_sw_
Definition sprinkler.h:566
void start_timer_(SprinklerTimerIndex timer_index)
Start/cancel/get status of valve timers.
void previous_valve()
advances to the previous valve (numerically)
switch_::Switch * valve_pump_switch_by_pump_index(size_t pump_index)
returns a pointer to a valve's pump switch object
void set_auto_advance(bool auto_advance)
if auto_advance is true, controller will iterate through all enabled valves
void prep_full_cycle_()
prepares for a full cycle by verifying auto-advance is on as well as one or more valve enable switche...
uint32_t valve_run_duration_adjusted(size_t valve_number)
returns valve_number's run duration (in seconds) adjusted by multiplier_
std::unique_ptr< ShutdownAction<> > sprinkler_shutdown_action_
Definition sprinkler.h:574
std::unique_ptr< ResumeOrStartAction<> > sprinkler_resumeorstart_action_
Definition sprinkler.h:576
void clear_queued_valves()
clears/removes all valves from the queue
bool any_valve_is_enabled_()
returns true if any valve is enabled
size_t number_of_valves()
returns the number of valves the controller is configured with
void set_pump_start_delay(uint32_t start_delay)
set how long the pump should start after the valve (when the pump is starting)
void set_standby(bool standby)
if standby is true, controller will refuse to activate any valves
std::vector< SprinklerQueueItem > queued_valves_
Queue of valves to activate next, regardless of auto-advance.
Definition sprinkler.h:546
bool queue_enabled()
returns true if the queue is enabled to run
void resume_or_start_full_cycle()
if a cycle was suspended using pause(), resumes it. otherwise calls start_full_cycle()
std::unique_ptr< Automation<> > sprinkler_turn_on_automation_
Definition sprinkler.h:579
void valve_selection_callback_()
callback functions for timers
optional< size_t > next_valve_number_(optional< size_t > first_valve=nullopt, bool include_disabled=true, bool include_complete=true)
returns the number of the next valve in the vector or nullopt if no valves match criteria
uint32_t total_cycle_time_all_valves()
returns the amount of time in seconds required for all valves
std::unique_ptr< Automation<> > sprinkler_turn_off_automation_
Definition sprinkler.h:578
optional< uint32_t > time_remaining_active_valve()
returns the amount of time remaining in seconds for the active valve, if any
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.
std::function< void()> timer_cbf_(SprinklerTimerIndex timer_index)
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 th...
std::unique_ptr< ShutdownAction<> > sprinkler_standby_shutdown_action_
Definition sprinkler.h:575
optional< uint32_t > manual_selection_delay_
Manual switching delay.
Definition sprinkler.h:534
void set_controller_repeat_number(SprinklerControllerNumber *repeat_number)
void start_single_valve(optional< size_t > valve_number, optional< uint32_t > run_duration=nullopt)
activates a single valve and disables auto_advance.
uint32_t valve_run_duration(size_t valve_number)
returns valve_number's run duration in seconds
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.
void fsm_transition_()
advance controller state, advancing to target_valve if provided
void fsm_request_(size_t requested_valve, uint32_t requested_run_duration=0)
make a request of the state machine
optional< size_t > paused_valve_
The number of the valve to resume from (if paused)
Definition sprinkler.h:525
SprinklerValveRunRequest next_req_
The next run request for the controller to consume after active_req_ is complete.
Definition sprinkler.h:516
void configure_valve_run_duration_number(size_t valve_number, SprinklerControllerNumber *run_duration_number)
configure a valve's run duration number component
SprinklerControllerSwitch * auto_adv_sw_
Switches we'll present to the front end.
Definition sprinkler.h:564
void set_controller_multiplier_number(SprinklerControllerNumber *multiplier_number)
configure important controller number components
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...
uint32_t total_cycle_time_enabled_incomplete_valves()
returns the amount of time in seconds required for all enabled & incomplete valves,...
bool valve_overlap_
Sprinkler valve cycle should overlap.
Definition sprinkler.h:497
switch_::Switch * valve_pump_switch(size_t valve_number)
returns a pointer to a valve's pump switch object
void set_divider(optional< uint32_t > divider)
sets the multiplier value to '1 / divider' and sets repeat value to divider
std::unique_ptr< Automation<> > sprinkler_standby_turn_on_automation_
Definition sprinkler.h:580
void set_valve_start_delay(uint32_t start_delay)
set how long the valve should start after the pump (when the pump is stopping)
void pause()
same as shutdown(), but also stores active_valve() and time_remaining() allowing resume() to continue...
void set_next_prev_ignore_disabled_valves(bool ignore_disabled)
enable/disable skipping of disabled valves by the next and previous actions
optional< size_t > active_valve()
returns the number of the valve that is currently active, if any. check with 'has_value()'
void set_queue_enable(bool queue_enable)
if queue_enable is true, controller will iterate through valves in the queue
bool pump_in_use(switch_::Switch *pump_switch)
returns true if the pump the pointer points to is in use
bool timer_active_(SprinklerTimerIndex timer_index)
returns true if the specified timer is active/running
optional< size_t > queued_valve()
returns the number of the next valve in the queue, if any. check with 'has_value()'
std::vector< Sprinkler * > other_controllers_
Other Sprinkler instances we should be aware of (used to check if pumps are in use)
Definition sprinkler.h:561
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
void start_from_queue()
starts the controller from the first valve in the queue and disables auto_advance.
void configure_valve_pump_switch(size_t valve_number, switch_::Switch *pump_switch)
configure a valve's associated pump switch object
void reset_cycle_states_()
resets the cycle state for all valves
float multiplier_
Sprinkler valve run time multiplier value.
Definition sprinkler.h:543
SprinklerControllerSwitch * control_switch(size_t valve_number)
returns a pointer to a valve's control switch object
void set_multiplier(optional< float > multiplier)
value multiplied by configured run times – used to extend or shorten the cycle
void set_timer_duration_(SprinklerTimerIndex timer_index, uint32_t time)
time is converted to milliseconds (ms) for set_timeout()
void set_controller_auto_adv_switch(SprinklerControllerSwitch *auto_adv_switch)
void fsm_transition_from_valve_run_()
transitions from ACTIVE state to ACTIVE (as in, next valve) or to a SHUTDOWN or IDLE state
bool standby()
returns true if standby is enabled
uint32_t total_cycle_time_enabled_valves()
returns the amount of time in seconds required for all enabled valves
bool valve_cycle_complete_(size_t valve_number)
returns true if valve's cycle is flagged as complete
optional< size_t > manual_valve()
returns the number of the valve that is manually selected, if any.
void add_valve(SprinklerControllerSwitch *valve_sw, SprinklerControllerSwitch *enable_sw=nullptr)
add a valve to the controller
SprinklerControllerSwitch * standby_sw_
Definition sprinkler.h:568
uint32_t timer_duration_(SprinklerTimerIndex timer_index)
returns time in milliseconds (ms)
void set_valve(SprinklerValve *valve)
void set_run_duration(uint32_t run_duration)
void set_start_delay(uint32_t start_delay, bool start_delay_is_valve_delay)
void set_controller(Sprinkler *controller)
void set_stop_delay(uint32_t stop_delay, bool stop_delay_is_valve_delay)
SprinklerValveRunRequestOrigin origin_
Definition sprinkler.h:173
SprinklerValveRunRequestOrigin request_is_from()
void set_request_from(SprinklerValveRunRequestOrigin origin)
SprinklerValveOperator * valve_operator()
void set_run_duration(uint32_t run_duration)
void set_valve_operator(SprinklerValveOperator *valve_op)
Base class for all switches.
Definition switch.h:39
void turn_on()
Turn this switch on.
Definition switch.cpp:21
void turn_off()
Turn this switch off.
Definition switch.cpp:25
bool state
The current reported state of the binary sensor.
Definition switch.h:56
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:57
optional< bool > get_initial_state_with_restore_mode()
Returns the initial state of the switch, after applying restore mode rules.
Definition switch.cpp:43
bool state
Definition fan.h:2
const float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
Definition component.cpp:83
const char *const TAG
Definition spi.cpp:7
constexpr const char * MIN_STR
Definition sprinkler.h:14
PROGMEM_STRING_TABLE(SprinklerRequestOriginStrings, "USER", "CYCLE", "QUEUE", "UNKNOWN")
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:25
Application App
Global storage of Application pointer - only one Application can exist.
const nullopt_t nullopt((nullopt_t::init()))
std::unique_ptr< StartSingleValveAction<> > valve_resumeorstart_action
Definition sprinkler.h:68
std::unique_ptr< Automation<> > valve_turn_off_automation
Definition sprinkler.h:69
SprinklerControllerSwitch * enable_switch
Definition sprinkler.h:62
std::unique_ptr< ShutdownAction<> > valve_shutdown_action
Definition sprinkler.h:67
SprinklerControllerSwitch * controller_switch
Definition sprinkler.h:61
std::unique_ptr< Automation<> > valve_turn_on_automation
Definition sprinkler.h:70
optional< size_t > pump_switch_index
Definition sprinkler.h:65