ESPHome 2026.10.2
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
5
6#include "dfrobot_sen0395.h"
7
9
10template<typename... Ts>
11class DfrobotSen0395SettingsAction final : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
12 public:
13 TEMPLATABLE_VALUE(int8_t, factory_reset)
14 TEMPLATABLE_VALUE(int8_t, start_after_power_on)
15 TEMPLATABLE_VALUE(int8_t, turn_on_led)
16 TEMPLATABLE_VALUE(int8_t, presence_via_uart)
17 TEMPLATABLE_VALUE(int8_t, sensitivity)
18 TEMPLATABLE_VALUE(float, delay_after_detect)
19 TEMPLATABLE_VALUE(float, delay_after_disappear)
20 TEMPLATABLE_VALUE(float, det_min1)
21 TEMPLATABLE_VALUE(float, det_max1)
22 TEMPLATABLE_VALUE(float, det_min2)
23 TEMPLATABLE_VALUE(float, det_max2)
24 TEMPLATABLE_VALUE(float, det_min3)
25 TEMPLATABLE_VALUE(float, det_max3)
26 TEMPLATABLE_VALUE(float, det_min4)
27 TEMPLATABLE_VALUE(float, det_max4)
28
29 void play(const Ts &...x) {
30 this->parent_->enqueue(make_unique<PowerCommand>(0));
31 if (this->factory_reset_.has_value() && this->factory_reset_.value(x...) == true) {
32 this->parent_->enqueue(make_unique<FactoryResetCommand>());
33 }
34 if (this->det_min1_.has_value() && this->det_max1_.has_value()) {
35 if (this->det_min1_.value() >= 0 && this->det_max1_.value() >= 0) {
36 this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
37 this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
38 this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
39 this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
40 }
41 }
42 if (this->delay_after_detect_.has_value() && this->delay_after_disappear_.has_value()) {
43 float detect = this->delay_after_detect_.value(x...);
44 float disappear = this->delay_after_disappear_.value(x...);
45 if (detect >= 0 && disappear >= 0) {
46 this->parent_->enqueue(make_unique<SetLatencyCommand>(detect, disappear));
47 }
48 }
49 if (this->start_after_power_on_.has_value()) {
50 int8_t val = this->start_after_power_on_.value(x...);
51 if (val >= 0) {
52 this->parent_->enqueue(make_unique<SensorCfgStartCommand>(val));
53 }
54 }
55 if (this->turn_on_led_.has_value()) {
56 int8_t val = this->turn_on_led_.value(x...);
57 if (val >= 0) {
58 this->parent_->enqueue(make_unique<LedModeCommand>(val));
59 }
60 }
61 if (this->presence_via_uart_.has_value()) {
62 int8_t val = this->presence_via_uart_.value(x...);
63 if (val >= 0) {
64 this->parent_->enqueue(make_unique<UartOutputCommand>(val));
65 }
66 }
67 if (this->sensitivity_.has_value()) {
68 int8_t val = this->sensitivity_.value(x...);
69 if (val >= 0) {
70 if (val > 9) {
71 val = 9;
72 }
73 this->parent_->enqueue(make_unique<SensitivityCommand>(val));
74 }
75 }
76 this->parent_->enqueue(make_unique<SaveCfgCommand>());
77 this->parent_->enqueue(make_unique<PowerCommand>(1));
78 }
79};
80
81} // namespace esphome::dfrobot_sen0395
virtual void play(const Ts &...x)=0
Helper class to easily give an object a parent of type T.
Definition helpers.h:2004
TEMPLATABLE_VALUE(int8_t, factory_reset) TEMPLATABLE_VALUE(int8_t
if(written< 0)
Definition helpers.h:1195
uint16_t x
Definition tt21100.cpp:5