forked from johannyren/PowerDisplayESPHome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power-display-esp32-s2mini.yaml
255 lines (217 loc) · 6.41 KB
/
power-display-esp32-s2mini.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
substitutions:
device_name: fuga-power-display
friendly_name: fuga-power-display
esphome:
name: ${device_name}
friendly_name: ${friendly_name}
libraries:
- Preferences
includes:
- power_display.h
# Save values before shutting down
on_shutdown:
then:
lambda: |-
SaveValuesToNVM ();
return;
esp32:
board: lolin_s2_mini
variant: ESP32S2
framework:
type: arduino
psram:
# Enable logging
logger:
logs:
component: ERROR
# Enable Home Assistant API
ota:
password: "${esphome_ota_password}"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: '.iot.xxx.local'
use_address: fuga-power-display.iot.xxx.local
reboot_timeout: 60s
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Energy Fallback Hotspot"
password: "bVAzLbYaBCW0"
captive_portal:
api:
encryption:
key: "InsertOwnKeyHere"
time:
- platform: homeassistant
id: homeassistant_time
font:
# gfonts://family[@weight]
- file: "gfonts://Mukta@700"
id: large_text
size: 38
glyphs:
['&', '@', '!', ',', '.', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
'1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z','å', 'ä', 'ö', '/']
# gfonts://family[@weight]
- file: "gfonts://Roboto@400"
id: energy_text
size: 18
# gfonts://family[@weight]
- file: "gfonts://Roboto@400"
id: price_text
size: 22
# gfonts://family[@weight]
- file: "gfonts://Source+Sans+Pro@400"
id: small_text
size: 10
color:
- id: my_grey
red: 30%
green: 30%
blue: 30%
white: 50%
# #800000
# 128,0,0
- id: COLOR_CSS_MAROON
red: 0.5020
green: 0.0000
blue: 0.0000
white: 0.0000
# #ff0000
# 255,0,0
- id: COLOR_CSS_RED
red: 1.0000
green: 0.0000
blue: 0.0000
white: 0.0000
# #ffa500
# 255,165,0
- id: COLOR_CSS_ORANGE
red: 1.0000
green: 0.6471
blue: 0.0000
white: 0.0000
# #adff2f
# 173,255,47
- id: COLOR_CSS_GREENYELLOW
red: 0.6784
green: 1.0000
blue: 0.1843
white: 0.0000
# #008000
# 0,128,0
- id: COLOR_CSS_GREEN
red: 0.0000
green: 0.5020
blue: 0.0000
white: 0.0000
# #006400
# 0,100,0
- id: COLOR_CSS_DARKGREEN
red: 0.0000
green: 0.3922
blue: 0.0000
white: 0.0000
# #f5f5f5
# 245,245,245
- id: COLOR_CSS_WHITESMOKE
red: 0.9608
green: 0.9608
blue: 0.9608
white: 0.0000
# "Icons made by Freepik from www.flaticon.com"
image:
- file: "solar_energy32.png"
id: solar_power
type: RGB24
#resize: 32x32
- file: "electrical_tower32.png"
id: grid_power
type: RGB24
#resize: 32x32
# Define sensors in HomeAssistant that we use for display
sensor:
# Current import (unit is W - if you meter is using kW then it needs conversion)
- platform: homeassistant
id: import_el
entity_id: sensor.k382lx7_current_power_in
# Utility meter template in HomeAssistant. See example below (goes into configuration.yaml in HA.)
- platform: homeassistant
id: consumption_today
entity_id: sensor.kamstrup_daily_kwh
# // From Energi Data Service
- platform: homeassistant
id: price_now
entity_id: sensor.energi_data_service
attribute: current_price
# Electricity prices from Energi Data Service. You will need to set up a template sensor to get this
# template:
# - sensor:
# - name: energy_max_price
# unique_id: energy_max_price
# state: "{{ states.sensor.energi_data_service.attributes.today_max.price }}"
- platform: homeassistant
id: eds_max
entity_id: sensor.energy_max_price
# Daily cost of consumption - you will need to set up a helper to provide this information (requires the energy dashboard to be fully working).
# I have a sensor set up on "sensor cost" which has the id "sensor.<id of your electricity meter)_cost" with a daily reset cycle
- platform: homeassistant
id: daily_charge
entity_id: sensor.dailyelectricitycost
text_sensor:
- platform: homeassistant # Energi Data Service
id: eds_today
entity_id: sensor.energi_data_service
attribute: today
- platform: homeassistant # Energi Data Service
id: eds_tomorrow
entity_id: sensor.energi_data_service
attribute: tomorrow
spi:
clk_pin: GPIO12 #SCL
mosi_pin: GPIO11 #SDA
display:
- platform: st7789v
model: Custom
height: 320
width: 240
offset_height: 0
offset_width: 0
eightbitcolor: true
cs_pin: GPIO17
dc_pin: GPIO21
reset_pin: GPIO14
rotation: 0
update_interval: 60s
lambda: |-
ESP_LOGD("ed", " - Refreshing display...");
auto powerDisplay = new PowerDisplay();
// Unit is W - if your meter is reporting kW then it needs conversion (multiply value by 1000) - which is done here
powerDisplay->SetCurrentPower(((id(import_el).state)*1000)); // Use if not using any solar production
powerDisplay->SetCurrentPrice(id(price_now).state);
powerDisplay->SetTodayMaxPrice(id(eds_max).state);
powerDisplay->SetTodayDailyCharge(id(daily_charge).state);
powerDisplay->SetTodaysPrices(id(eds_today).state.c_str());
powerDisplay->SetTomorrowsPrices(id(eds_tomorrow).state.c_str());
powerDisplay->WriteDailyEnergy(id(consumption_today).state);
powerDisplay->DisplayIcons(&it, 10, 10 );
powerDisplay->WritePowerText(&it, 120, 40 );
powerDisplay->WriteDailyAmount(&it, 120, 75, id(COLOR_CSS_WHITESMOKE));
powerDisplay->CreateGraph(&it, 15, 115, 220, 100, my_grey);
powerDisplay->SetGraphScale(0, 24, 0 );
powerDisplay->SetGraphGrid(&it, 0, 2, 0, 1, my_grey);
powerDisplay->WriteTimeLine(&it, id(homeassistant_time).now().hour, id(homeassistant_time).now().minute, id(COLOR_CSS_WHITESMOKE));
powerDisplay->SetPrices("today");
powerDisplay->SetPrices("tomorrow");
powerDisplay->DrawPriceGraph(&it);
powerDisplay->WritePriceText(&it, 120, 297 );
# Save global values every 15 minute. This is to relatively quickly resume from a reboot and retain calculated values.
interval:
- interval: 900s
then:
- lambda: |-
SaveValuesToNVM();