-
Notifications
You must be signed in to change notification settings - Fork 0
/
solar-power-gauge.yml
178 lines (162 loc) · 4.05 KB
/
solar-power-gauge.yml
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
esphome:
name: solar-gauge
friendly_name: Solar gauge
on_boot:
- priority: -100
then:
- script.execute: stepper_init
on_shutdown:
then:
- script.execute: stepper_backward_full
- script.wait: stepper_backward_full
substitutions:
step_speed: 400 steps/s
# How long it takes to go the max # of steps (good to overshoot
# since esphome seems to undershoot the speed a bit)
step_delay: 1.8s
# Total number of steps for a full dial rotation (also good to
# overshoot so that the gauge fully resets its position during
# initialization)
steps_total: "645"
# The number of steps until the dial is at its maximum position
# (A full rotation is too far)
steps_gauge_max: "276"
# The number of kW represented when the dial is at max position
gauge_max: "10.0"
globals:
- id: stepper_initialized
type: bool
initial_value: "false"
esp32:
board: seeed_xiao_esp32c3
variant: esp32c3
framework:
type: arduino
logger:
api:
encryption:
# UPDATE THIS
key: YOUR_PASSWORD
ota:
# UPDATE THIS
password: YOUR_PASSWORD
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "Solar-Gauge Fallback Hotspot"
# UPDATE THIS
password: YOUR_PASSWORD
captive_portal:
output:
# uln2003's sleep_pin can be used, but setting it manually has
# been more reliable (and saves power)
- platform: gpio
id: stepper_enable
pin: GPIO6
stepper:
- platform: uln2003
id: gauge_stepper
pin_a: GPIO5
pin_b: GPIO3
pin_c: GPIO2
pin_d: GPIO4
max_speed: $step_speed
acceleration: inf
deceleration: inf
number:
- platform: template
id: gauge_control
name: Gauge Control
min_value: 0
max_value: 10
step: 0.5
optimistic: True
set_action:
then:
# Without this delay, `id(gauge_control).state` has not yet
# been updated
- delay: 50ms
- script.execute: stepper_refresh
script:
- id: stepper_forward_full
mode: queued
then:
- logger.log: Stepper forward full
- script.execute:
id: stepper_set
steps: $steps_total
- id: stepper_backward_full
mode: queued
then:
- logger.log: Stepper backward full
- script.execute:
id: stepper_set
steps: 0
- id: stepper_init
mode: queued
then:
- delay: 2s
- script.execute: stepper_forward_full
- script.wait: stepper_forward_full
- script.execute: stepper_backward_full
- script.wait: stepper_backward_full
- globals.set:
id: stepper_initialized
value: "true"
- logger.log: Stepper initialized
- id: stepper_set
mode: queued
parameters:
steps: int
then:
- logger.log:
format: Stepper set %d
args: [steps]
- output.turn_on: stepper_enable
- stepper.set_target:
id: gauge_stepper
target: !lambda return steps;
- delay: $step_delay
- output.turn_off: stepper_enable
- id: stepper_refresh
then:
- wait_until:
lambda: return id(stepper_initialized);
- script.execute:
id: stepper_set
steps: !lambda return id(gauge_control).state / $gauge_max * $steps_gauge_max;
time:
- platform: sntp
on_time:
seconds: 15
minutes: 0
hours: /12
then:
- script.execute: stepper_init
- script.wait: stepper_init
- script.execute: stepper_refresh
button:
- platform: template
name: Stepper forward full
on_press:
then:
- script.execute: stepper_forward_full
- platform: template
name: Stepper backward full
on_press:
then:
- script.execute: stepper_backward_full
sensor:
- platform: homeassistant
id: power_production
# Replace this with your home assistant power entity ID
entity_id: sensor.your_power_sensor
unit_of_measurement: kW
device_class: power
state_class: measurement
on_value:
then:
- number.set:
id: gauge_control
value: !lambda return x;