-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesp8266-proof-of-concept.yaml
248 lines (214 loc) · 8.75 KB
/
esp8266-proof-of-concept.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
# ----------------------------------------------------------------------------------------------------
# Wifi configuration - This part depends on your hardware target
# ----------------------------------------------------------------------------------------------------
esphome:
name: esp8266
friendly_name: ESP8266
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 115200
level: INFO
logs:
component: ERROR
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret solar_router_ota_password
# Define wifi connection
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "SolarRouter"
password: !secret hotspot_password
captive_portal:
# Activate web interface
web_server:
port: 80
# ----------------------------------------------------------------------------------------------------
# Customisation
# ----------------------------------------------------------------------------------------------------
# This part of the script is designed to be use for customisation. It shouldn't be necessary to
# edit other part of the script to perform configuration.
substitutions:
# Power metter source ---------------------------------------------------------
# Define which power meter source should be used: ["fronius"]
# Note: today only 'fronius' is supported. Developper can add script for
# other meter devies.
power_meter_source: "fronius"
# Fronius configuration (if selected as power meter) --------------------------
# Define ip address of inverter
fronius_inverter_ip_address: "192.168.1.21"
# Fronius configuration -------------------------------------------------------
# Define GPIO pin connected to AC Dimmer for gate and zero crossing detection.
ac_dimmer_gate_pin: GPIO0
ac_dimmer_zero_crossing_pin: GPIO2
# ----------------------------------------------------------------------------------------------------
# End of customisation.
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# It shouldn't be necessary to modify the code bellow this comment.
# If you have to modify code bellow to make you installation work, please inform developpers.
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------
# User interaction
# ----------------------------------------------------------------------------------------------------
switch:
# Define is router is active or not
# When switch is ON, pooling timer will trigger every seconds
- platform: template
name: "Activate Solar Routing"
optimistic: true
restore_mode: RESTORE_DEFAULT_OFF
id: activate
number:
# Report or define triac opening value
# If solar routing is not enabled, this value define the level of triac opening
# If solar routing is enabled, this value is automatically updated and reflect the level
# of triac opening defined by the solar router
# Moving the slider will have an impact on the solar energy diverted and will
# immadiatelly be corrected by the solar router. It is advised to not use the slider
# when the router is activated.
- platform: template
name: "Triac Opening"
id: triac_opening
min_value: 0
max_value: 100
step: 1
unit_of_measurement: "%"
optimistic: True
mode: slider
# Define the reactivity of triac opening
- platform: template
name: "Reactivity"
id: reactivity
optimistic: True
restore_value: True
mode: box
min_value: 1
max_value: 100
initial_value: 10
unit_of_measurement: ""
step: 1
# Define the target level of grid exchange
# 0 : no exchange
# <0 : continue the send energy to the grid
# >0 : pull energy from the grid to better confort
- platform: template
name: "Target grid exchange"
id: target_grid_exchange
optimistic: True
restore_value: True
mode: box
min_value: -99999
max_value: 99999
initial_value: 0
unit_of_measurement: "W"
step: 1
# ----------------------------------------------------------------------------------------------------
# Sensor updated every 10s to give feedback in Home Assistant
# ----------------------------------------------------------------------------------------------------
sensor:
# Sensor showing the actual power consumption
- platform: template
name: "Real Power"
id: real_power
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s
# ----------------------------------------------------------------------------------------------------
# Use http request component (required for Fronius)
# ----------------------------------------------------------------------------------------------------
http_request:
useragent: esphome/device
timeout: 10s
esp8266_disable_ssl_support: True
id: http_request_data
verify_ssl: False
# ----------------------------------------------------------------------------------------------------
# Define scripts for power collection or energy regulation
# ----------------------------------------------------------------------------------------------------
script:
# Fronius script gather power reports from inverter and update globals (real_power)
# Information are provided as json. Power exchanged with the grid is names PowerReal_P_Sum
# When this value is positive, energy is taken from the grid.
# When this value is negative, energy is pushed to the grid.
- id: fronius
mode: single
then:
- http_request.get:
url: http://${fronius_inverter_ip_address}/solar_api/v1/GetMeterRealtimeData.cgi
capture_response: true
on_response:
then:
- lambda: |-
json::parse_json(body, [](JsonObject root) -> bool {
id(real_power).publish_state(root["Body"]["Data"]["0"]["PowerReal_P_Sum"].as< float >());
return true;
});
# Manage energy regulation
# Calculate the delta of percentage to apply to the triac opening status to go closer to the
# objective. Closer we are to the objective smaller are the steps. Reactivity parameter is
# doing a ponderation on this parameter to avoid resonance effects.
- id: energy_regulation
mode: single
then:
# Define the opening level of triac based on power measured and grid exchange target
# The value of triac is a precentage and is then limited to the range 0 100
- lambda: |-
double delta = -1*(id(real_power).state-id(target_grid_exchange).state)*id(reactivity).state/1000;
double triac_status = id(triac_opening).state + delta;
triac_status = std::max(0.0, std::min(100.0, triac_status));
id(triac_opening).publish_state(triac_status);
# Apply opening level on triac using light component
- light.turn_on:
id: dimmer_controller
brightness: !lambda |-
return id(triac_opening).state/100.0;
# ----------------------------------------------------------------------------------------------------
# Pooling data every seconds
# ----------------------------------------------------------------------------------------------------
# Component sntp is managing time.
# If activate switch is ON, power measurment and energy regulation are performed every secondes
time:
- platform: sntp
id: sntp_time
on_time:
# Trigger action every second
- seconds: /1
then:
- if:
condition:
switch.is_on: activate
then:
- script.execute: ${power_meter_source}
- script.execute: energy_regulation
# ----------------------------------------------------------------------------------------------------
# Triac control
# ----------------------------------------------------------------------------------------------------
# Control the triac through GPIO
output:
- platform: ac_dimmer
id: dimmer
gate_pin: ${ac_dimmer_gate_pin}
method: leading
zero_cross_pin:
number: ${ac_dimmer_zero_crossing_pin}
mode:
input: true
inverted: yes
# Manage triac opening with light component brightness
light:
- platform: monochromatic
id: dimmer_controller
output: dimmer
internal: True
default_transition_length: 50ms