-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp8266-pv-battery-indicator.yaml
93 lines (82 loc) · 2.21 KB
/
esp8266-pv-battery-indicator.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
esphome:
name: esp8266-pv-battery-indicator
friendly_name: esp8266-pv-battery-indicator
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ""
ota:
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
sensor:
- platform: homeassistant
name: "Battery SOC"
id: soc
entity_id: sensor.sun10k_battery_capacity # <<< ensure you configure your correct entity which returns the batter soc value
accuracy_decimals: 0
# Calculate green color value.
- platform: template
id: soc_green
update_interval: 1s
accuracy_decimals: 0
lambda:
return id(soc).state;
filters:
- calibrate_linear:
- 0 -> 255
- 100 -> 0
# Calculate red color value. The lower, the more red.
- platform: template
id: soc_red
update_interval: 1s
accuracy_decimals: 0
lambda:
return id(soc).state;
filters:
- calibrate_linear:
- 0 -> 0
- 100 -> 255
# Calculate how many LEDs should illuminate
- platform: template
id: soc_lights
update_interval: 1s
accuracy_decimals: 0
lambda:
return id(soc).state;
filters:
- calibrate_linear:
- 0 -> 0
- 100 -> 20 # <<< Type in here the num of addressable leds. (In my example I've used 20)
light:
- platform: neopixelbus
id: led_strip
internal: false
variant: WS2811
pin: D5
num_leds: 20 # <<< Type in here the num of addressable leds. (In my example I've used 20)
type: GRB
color_correct: [90%, 90%, 90%]
name: "PV Battery indicator"
on_turn_on:
light.turn_on:
id: led_strip
effect: "PV Battery indicator"
brightness: 100%
effects:
- addressable_lambda:
name: "PV Battery indicator"
update_interval: 1s
lambda: |-
for (int i = 0; i < it.size(); i++) {
if (id(soc_lights).state > i) {
it[i] = ESPColor(id(soc_green).state, id(soc_red).state, 0);
} else {
it[i] = ESPColor(0, 0, 0);
}
}