-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefault-template.yaml
189 lines (170 loc) · 4.13 KB
/
default-template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
esphome:
name: $device_name
esp32:
board: esp32-s2-saola-1
variant: esp32s2
framework:
type: esp-idf
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: "Fallback Hotspot"
password: !secret fallback_password
# Set up the minimum and maximum values for calculating moisture %
globals:
- id: minimumRawValue
type: float
restore_value: no
initial_value: $minimum_raw_value
- id: maximumRawValue
type: float
restore_value: no
initial_value: $maximum_raw_value
- id: temperatureOffset
type: float
restore_value: no
initial_value: $temperature_offset
i2c:
sda: 08
scl: 10
scan: false
sensor:
- platform: adc
pin: 7
attenuation: 12dB
raw: true
id: "vbatt"
name: "Battery Voltage"
update_interval: $battery_update_interval
disabled_by_default: true
device_class: "voltage"
state_class: "measurement"
icon: "mdi:battery-outline"
accuracy_decimals: 2
entity_category: "diagnostic"
on_value:
then:
- component.update: pbatt
# derive battery percentage 3300mV=0%, 3950mV=100%
- platform: template
lambda: |-
float x = id(vbatt).state;
if (x < 3300) {
x = 3300;
}
if (x > 3950) {
x = 3950;
}
float y = (x - 3300) / 650 * 100;
return y;
name: "Battery Percentage"
id: "pbatt"
update_interval: never
unit_of_measurement: "%"
device_class: "battery"
state_class: "measurement"
icon: "mdi:battery"
accuracy_decimals: 0
- platform: adc
pin: 9
raw: true
id: rMoisture
name: "Raw Moisture reading"
update_interval: never
unit_of_measurement: raw
disabled_by_default: true
state_class: "measurement"
icon: "mdi:water-alert"
entity_category: "diagnostic"
#derive moisture level 3800=100% 6800=0%
- platform: template
name: "Moisture Level (Instant)"
id: "iMoisture"
unit_of_measurement: "%"
update_interval: never
state_class: "measurement"
disabled_by_default: true
icon: "mdi:water-percent"
accuracy_decimals: 0
lambda: |-
float x = id(rMoisture).state;
if (x < id(minimumRawValue)) {
x = id(minimumRawValue);
}
if (x > id(maximumRawValue)) {
x = id(maximumRawValue);
}
float z = id(maximumRawValue) - id(minimumRawValue);
float y = 100-((x - id(minimumRawValue)) / z * 100);
return y;
# average over 5 readings to smooth
- platform: template
name: "Moisture Level"
id: "aMoisture"
unit_of_measurement: "%"
update_interval: never
state_class: "Measurement"
icon: "mdi:water-percent"
accuracy_decimals: 0
lambda: |-
return id(iMoisture).state;
filters:
- quantile:
window_size: 5
send_every: 5
send_first_at: 5
quantile: 0.9
- platform: tmp102
id: "rTemperature"
address: 0x48
update_interval: $temperature_update_interval
entity_category: diagnostic
name: "Raw Temperature"
disabled_by_default: true
on_value:
then:
- component.update: aTemperature
- platform: template
name: "Temperature"
id: "aTemperature"
unit_of_measurement: "°C"
update_interval: never
state_class: "Measurement"
icon: "mdi:water-percent"
accuracy_decimals: 1
lambda: |-
return id(rTemperature).state + id(temperatureOffset);
output:
- platform: ledc
pin: 17
frequency: 1500000Hz
id: moisture_gen
interval:
- interval: $moisture_update_interval
then:
- output.turn_on: moisture_gen
- output.set_level:
id: moisture_gen
level: 34%
- delay: 500ms
- component.update: rMoisture
- component.update: iMoisture
- component.update: aMoisture
- output.turn_off: moisture_gen
deep_sleep:
run_duration:
default: $run_duration
sleep_duration: $sleep_duration
wakeup_pin: 2