ESPHome 2026.6.0-dev
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 DfrobotSen0395ResetAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
12 public:
13 void play(const Ts &...x) { this->parent_->enqueue(make_unique<ResetSystemCommand>()); }
14};
15
16template<typename... Ts>
17class DfrobotSen0395SettingsAction : public Action<Ts...>, public Parented<DfrobotSen0395Component> {
18 public:
19 TEMPLATABLE_VALUE(int8_t, factory_reset)
20 TEMPLATABLE_VALUE(int8_t, start_after_power_on)
21 TEMPLATABLE_VALUE(int8_t, turn_on_led)
22 TEMPLATABLE_VALUE(int8_t, presence_via_uart)
23 TEMPLATABLE_VALUE(int8_t, sensitivity)
24 TEMPLATABLE_VALUE(float, delay_after_detect)
25 TEMPLATABLE_VALUE(float, delay_after_disappear)
26 TEMPLATABLE_VALUE(float, det_min1)
27 TEMPLATABLE_VALUE(float, det_max1)
28 TEMPLATABLE_VALUE(float, det_min2)
29 TEMPLATABLE_VALUE(float, det_max2)
30 TEMPLATABLE_VALUE(float, det_min3)
31 TEMPLATABLE_VALUE(float, det_max3)
32 TEMPLATABLE_VALUE(float, det_min4)
33 TEMPLATABLE_VALUE(float, det_max4)
34
35 void play(const Ts &...x) {
36 this->parent_->enqueue(make_unique<PowerCommand>(0));
37 if (this->factory_reset_.has_value() && this->factory_reset_.value(x...) == true) {
38 this->parent_->enqueue(make_unique<FactoryResetCommand>());
39 }
40 if (this->det_min1_.has_value() && this->det_max1_.has_value()) {
41 if (this->det_min1_.value() >= 0 && this->det_max1_.value() >= 0) {
42 this->parent_->enqueue(make_unique<DetRangeCfgCommand>(
43 this->det_min1_.value_or(-1), this->det_max1_.value_or(-1), this->det_min2_.value_or(-1),
44 this->det_max2_.value_or(-1), this->det_min3_.value_or(-1), this->det_max3_.value_or(-1),
45 this->det_min4_.value_or(-1), this->det_max4_.value_or(-1)));
46 }
47 }
48 if (this->delay_after_detect_.has_value() && this->delay_after_disappear_.has_value()) {
49 float detect = this->delay_after_detect_.value(x...);
50 float disappear = this->delay_after_disappear_.value(x...);
51 if (detect >= 0 && disappear >= 0) {
52 this->parent_->enqueue(make_unique<SetLatencyCommand>(detect, disappear));
53 }
54 }
55 if (this->start_after_power_on_.has_value()) {
56 int8_t val = this->start_after_power_on_.value(x...);
57 if (val >= 0) {
58 this->parent_->enqueue(make_unique<SensorCfgStartCommand>(val));
59 }
60 }
61 if (this->turn_on_led_.has_value()) {
62 int8_t val = this->turn_on_led_.value(x...);
63 if (val >= 0) {
64 this->parent_->enqueue(make_unique<LedModeCommand>(val));
65 }
66 }
67 if (this->presence_via_uart_.has_value()) {
68 int8_t val = this->presence_via_uart_.value(x...);
69 if (val >= 0) {
70 this->parent_->enqueue(make_unique<UartOutputCommand>(val));
71 }
72 }
73 if (this->sensitivity_.has_value()) {
74 int8_t val = this->sensitivity_.value(x...);
75 if (val >= 0) {
76 if (val > 9) {
77 val = 9;
78 }
79 this->parent_->enqueue(make_unique<SensitivityCommand>(val));
80 }
81 }
82 this->parent_->enqueue(make_unique<SaveCfgCommand>());
83 this->parent_->enqueue(make_unique<PowerCommand>(1));
84 }
85};
86
87} // 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:1861
TEMPLATABLE_VALUE(int8_t, factory_reset) TEMPLATABLE_VALUE(int8_t
if(written< 0)
Definition helpers.h:1047
uint16_t x
Definition tt21100.cpp:5