-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathi_spindel.yaml
182 lines (156 loc) · 4.6 KB
/
i_spindel.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
## inspiriert durch https://www.ispindel.de/
esphome:
name: i_spindel_1
platform: ESP8266
board: d1_mini
on_boot:
then:
- script.execute: wait_for_maintainance_on_boot
wifi:
networks:
- ssid: !secret wifi_essid
password: !secret wifi_pwd
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "fallback"
password: "fallback"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# wird die iSpindel eingeschaltet?
globals:
- id: on_power_up
type: bool
restore_value: yes
initial_value: 'true'
## Deep Sleep: https://esphome.io/components/deep_sleep.html
deep_sleep:
id: deep_sleep_control
sleep_duration: 32min
binary_sensor:
- platform: homeassistant
id: i_spindel_1_prevent_deep_sleep
name: iSpindel 1 Prevent Deep Sleep
entity_id: input_boolean.esphome_prevent_deep_sleep
internal: true
- platform: homeassistant
id: i_spindel_1_brewery_prevent_deep_sleep
name: iSpindel 1 Brewery Prevent Deep Sleep
entity_id: input_boolean.brewery_esphome_prevent_deep_sleep
internal: true
# i2c configuration
i2c:
sda: GPIO5
scl: GPIO2
# sensors configuration
sensor:
# Analog Sensor zur Batteriemessung
# Schaltung: https://ezcontents.org/esp8266-battery-level-meter
- platform: adc
name: "iSpindel 1 relative Battery Voltage"
update_interval: 10s
pin: A0
id: "vcc"
internal: true
filters:
- multiply: 4.2
- platform: template
name: "iSpindel 1 Battery Voltage"
unit_of_measurement: 'V'
icon: 'mdi:current-dc'
update_interval: 10s
accuracy_decimals: 2
lambda: |-
return (id(vcc).state);
- platform: template
name: "iSpindel 1 Battery Percentage"
unit_of_measurement: '%'
device_class: battery
update_interval: 10s
accuracy_decimals: 0
lambda: |-
return ((id(vcc).state-3) /1.2 * 100.00);
# Gyro-Sensor
- platform: mpu6050
address: 0x68
update_interval: 5s
id: mpu6050_1
accel_x:
name: "iSpindel 1 MPU6050 Accel X"
id: accel_x
accel_y:
name: "iSpindel 1 MPU6050 Accel Y"
id: accel_y
accel_z:
name: "iSpindel 1 MPU6050 Accel z"
id: accel_z
gyro_x:
name: "iSpindel 1 MPU6050 Gyro X"
gyro_y:
name: "iSpindel 1 MPU6050 Gyro Y"
gyro_z:
name: "iSpindel 1 MPU6050 Gyro z"
temperature:
name: "iSpindel 1 MPU6050 Temperature"
filters:
offset: 1.4
# Winkelberechnung: https://how2electronics.com/measure-tilt-angle-mpu6050-arduino/
- platform: template
name: "iSpindel 1 MPU6050 Angle X"
unit_of_measurement: "°"
icon: "mdi:angle-acute"
lambda: |-
return RAD_TO_DEG * (atan2(-(id(accel_y).state), -(id(accel_z).state))+PI);
update_interval: 5s
- platform: template
name: "iSpindel 1 MPU6050 Angle Y"
unit_of_measurement: "°"
icon: "mdi:angle-acute"
lambda: |-
return RAD_TO_DEG * (atan2(-(id(accel_x).state), -(id(accel_z).state))+PI);
update_interval: 5s
- platform: template
name: "iSpindel 1 MPU6050 Angle Z"
unit_of_measurement: "°"
icon: "mdi:angle-acute"
lambda: |-
return RAD_TO_DEG * (atan2(-(id(accel_y).state), -(id(accel_x).state))+PI);
update_interval: 5s
## Deep Sleep: https://esphome.io/components/deep_sleep.html
script:
- id: wait_for_maintainance_on_boot
mode: queued
then:
- delay: 20s
- if:
condition:
lambda: |-
return id(on_power_up) == true;
then:
- logger.log: '[DEEP_SLEEP]: Entering wait_for_maintainance_on_boot, 3 mins left for admin stuff..'
- delay: 60s
- lambda: |-
id(on_power_up) = false;
else:
- logger.log: '[DEEP_SLEEP]: Comming from deep-sleep, no wait_for_maintainance_on_boot needed..'
- logger.log: '[DEEP_SLEEP]: Starting deep-sleep control workflow now....'
- script.execute: consider_deep_sleep
- id: consider_deep_sleep
mode: queued
then:
- logger.log: '[DEEP_SLEEP]: Entering consider_deep_sleep'
- delay: 20s
- if:
condition:
or:
- binary_sensor.is_on: i_spindel_1_prevent_deep_sleep
- binary_sensor.is_on: i_spindel_1_brewery_prevent_deep_sleep
then:
- logger.log: '[DEEP_SLEEP]: Skipping sleep per prevent_deep_sleep..'
else:
- logger.log: '[DEEP_SLEEP]: Entering deep sleep per !prevent_deep_sleep..'
- deep_sleep.enter: deep_sleep_control
- script.execute: consider_deep_sleep