-
Notifications
You must be signed in to change notification settings - Fork 0
/
espnode4.yaml
261 lines (227 loc) · 5.49 KB
/
espnode4.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#
# Altitude-Azimuth tracker
#
substitutions:
nodename: espnode4
# Enter the latitude and longitude of your location here
my_latitude: "44.2333°"
my_longitude: "-76.4810°"
my_timezone: "America/Toronto"
# pin assignments
display_sda: GPIO27
display_scl: GPIO26
servo_azimuth: GPIO19
servo_altitude: GPIO21
esphome:
name: $nodename
friendly_name: $nodename
esp32:
board: nodemcu-32s
framework:
type: arduino
# Enable logging
logger:
# level: error
level: warn
# Enable startup debug info
debug:
# Enable Home Assistant API
# Required if using homeassistant time server
api:
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
id: wifi_id
on_connect:
# the green LED indicates that the node is connected to the WiFI SSID
# and the Sun is above the horizon
- light.turn_on: green_led
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: $nodename
password: !secret wifi_password
captive_portal:
binary_sensor:
- platform: status
name: Status
button:
- platform: restart
name: Restart
- platform: shutdown
name: shutdown
# Track the sun for my location
sun:
latitude: ${my_latitude}
longitude: ${my_longitude}
on_sunrise:
- then:
- logger.log: Sunrise!
on_sunset:
- then:
- logger.log: Sunset!
- number.set:
id: number_azimuth
value: 180
- number.set:
id: number_altitude
value: 0
# At least one time source is required
time:
- platform: homeassistant
id: ha_time
number:
# Define a number template to control servo 1
# servo 1 is azimuth: 0 to 360: map to -1 to +1
- platform: template
name: Azimuth Number
id: number_azimuth
optimistic: True
mode: slider
min_value: 0
initial_value: 180
max_value: 360
step: 0.1
set_action:
then:
- servo.write:
id: servo_azimuth
level: !lambda 'return ((x / 360.0)* 2.0) - 1.0;'
# Define a number template to control servo 2
# servo 2 is altitude: 0 to 90: map to 0 to -1
- platform: template
name: Altitude Number
id: number_altitude
optimistic: true
mode: slider
min_value: 0
initial_value: 0
max_value: 90
step: 0.1
set_action:
then:
- servo.write:
id: servo_altitude
level: !lambda 'return -x / 90.0;'
sensor:
- platform: sun
name: Sun Altitude
id: sun_altitude
type: elevation
- platform: sun
name: Sun Azimuth
id: sun_azimuth
type: azimuth
- platform: internal_temperature
name: CPU Temperature
update_interval: 5min
i2c:
# define an I2C bus for the SSD1306 display
- id: bus_b
sda: ${display_sda}
scl: ${display_scl}
scan: True
frequency: 400kHz
output:
# Servo output 1
- platform: ledc
pin: ${servo_azimuth}
id: ledc_1
channel: 0
frequency: 50 Hz
# Servo output 2
- platform: ledc
pin: ${servo_altitude}
id: ledc_2
channel: 1
frequency: 50 Hz
servo:
# servo 1
- id: servo_azimuth
output: ledc_1
auto_detach_time: 1s
transition_length: 8s
# servo 2
- id: servo_altitude
output: ledc_2
auto_detach_time: 1s
transition_length: 8s
text_sensor:
- platform: wifi_info
ip_address:
name: IP Address
- platform: sun
name: Sun Next Sunrise
id: sunrise_text
type: sunrise
format: "%I:%M %p"
- platform: sun
name: Sun Next Sunset
id: sunset_text
type: sunset
format: "%I:%M %p"
font:
# some fonts for the display
- file: 'fonts/arial.ttf'
id: font1
size: 20
- file: 'fonts/materialdesignicons-webfont.ttf'
id: icons
size: 44
glyphs: [
"", # sun
"", # sun-compass
"", # sun-angle-outline
"", # sunrise
"" # weather-sunset
]
display:
- platform: ssd1306_i2c
model: "SSD1306 128x64"
reset_pin: GPIO25 # an unused pin
address: 0x3C
id: my_display
flip_x: True
flip_y: True
pages:
- id: page1
lambda: |-
it.print(90, 5, id(icons), "");
it.print(15, 24, id(font1), "Sunrise");
it.printf(5, 44, id(font1), "%s", id(sunrise_text).state.c_str());
- id: page2
lambda: |-
it.print(90, 0, id(icons), "");
it.print(10, 24, id(font1), "Altitude");
it.printf(10, 44, id(font1), "%.0f°", id(sun_altitude).state);
- id: page3
lambda: |-
it.print(90, 0, id(icons), "");
it.print(10, 24, id(font1), "Azimuth");
it.printf(10, 44, id(font1), "%.0f°", id(sun_azimuth).state);
- id: page4
lambda: |-
it.print(90, 5, id(icons), "");
it.print(15, 24, id(font1), "Sunset");
it.printf(5, 44, id(font1), "%s", id(sunset_text).state.c_str());
interval:
# update the display page every 15 seconds
- interval: 15s
then:
- display.page.show_next: my_display
- component.update: my_display
# update the servo motors every 5 minutes
- interval: 300s
then:
- if:
condition:
- sun.is_above_horizon:
then:
# - logger.log: Sun is above horizon!
- number.set:
id: number_azimuth
value: !lambda 'return id(sun_azimuth).state ;'
- number.set:
id: number_altitude
value: !lambda 'return id(sun_altitude).state ;'