-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb_smart_plug_1.yaml
209 lines (186 loc) · 6.42 KB
/
rgb_smart_plug_1.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
substitutions:
devicename: rgb_smart_plug_1
friendly_name: RGB Smart Plug 16A
device_description: Energy Monitoring 16A Smart Plug with button and RGB led.
esphome:
name: $devicename
comment: ${device_description}
platform: ESP8266
board: esp01_1m
wifi:
ssid: "SSID"
password: "PASSWORD"
fast_connect: on #we only have one WiFi AP so just use the first one that matches
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: $devicename
password: "PASSWORD"
captive_portal:
# Enable logging
logger:
baud_rate: 0 #disable UART logging since we aren't connected to GPIO1 TX
# Web server can be removed after enabling HA API
web_server:
port: 80
ota:
# Enable Home Assistant API
api:
# Enable time component for use by daily power sensor
time:
- platform: homeassistant
id: homeassistant_time
sensor:
# Reports how long the device has been powered (in minutes)
- platform: uptime
name: ${friendly_name} Uptime
filters:
- lambda: return x / 60.0;
unit_of_measurement: minutes
# Reports the WiFi signal strength
- platform: wifi_signal
name: ${friendly_name} Wifi Signal
update_interval: 60s
# Reports the Current, Voltage, and Power used by the plugged-in device (not counting this plug's own usage of about 0.8W/0.019A, so subtract those when calibrating with this plugged into a Kill-A-Watt type meter)
- platform: hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO5
cf1_pin: GPIO14
current_resistor: 0.001 #The value of the shunt resistor for current measurement. Defaults to the Sonoff POW’s value 0.001 ohm.
# voltage_divider: 2401 # Commented out, using default
power:
name: ${friendly_name} Power
unit_of_measurement: W
id: wattage
filters:
- delta: 10 # Don't report if change is less than 10W from previous reported, make it smaller if you got smaller load
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 0.0 #Need to keep 0 mapped to 0 for when connected device is not drawing any power
- 16.9 -> 5.7 # -0.8W from just this plug
current:
name: ${friendly_name} Current
unit_of_measurement: A
filters:
- delta: 1
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 0.0 #Need to keep 0 mapped to 0 for when connected device is not drawing any power
- 0.0376 -> 0.025 # -0.019A from just this plug, very raw calibration
voltage:
name: ${friendly_name} Voltage
unit_of_measurement: V
filters:
- delta: 2
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 0.0 #Don't care if 0 reading aligns with 0 real Volts since we won't ever measure that
- 574.78 -> 228.0 #load was on
change_mode_every: 1 #Skips first reading after each change, so this will double the update interval. Default 8
update_interval: 10s #10s setting => 20 second effective update rate for Power, 40 second for Current and Voltage. Default 60s
# Reports the total Power so-far each day, resets at midnight, see https://esphome.io/components/sensor/total_daily_energy.html
- platform: total_daily_energy
name: ${friendly_name} Total Daily Energy
power_id: wattage
filters:
- multiply: 0.001 ## convert Wh to kWh
unit_of_measurement: kWh
binary_sensor:
# Reports if this device is Connected or not
# - platform: status
# name: ${friendly_name} Status
# Button on the side is pressed and then toggle relay
- platform: gpio
device_class: power
pin:
number: GPIO13
inverted: True
name: ${friendly_name} Button # Name to make button visible in HA
on_press:
- switch.toggle: relay
text_sensor:
# Reports the ESPHome Version with compile date
- platform: version
name: ${friendly_name} ESPHome Version
# Reports detailed wifi info, can be commented out
- platform: wifi_info
ip_address:
name: ${friendly_name} IP Address
# ssid: # Some additional wifi info that is not normally needed
# name: ${friendly_name} Connected SSID
# bssid:
# name: ${friendly_name} Connected BSSID
switch:
# Relay itself
- platform: gpio
name: ${friendly_name}
pin: GPIO15
id: relay
restore_mode: RESTORE_DEFAULT_OFF #Try to restore relay state after reboot/power-loss event.
#RESTORE_DEFAULT_OFF (Default) - Attempt to restore state and default to OFF if not possible to restore. Uses flash write cycles.
#RESTORE_DEFAULT_ON - Attempt to restore state and default to ON. Uses flash write cycles.
#ALWAYS_OFF - Always initialize the pin as OFF on bootup. Does not use flash write cycles.
#ALWAYS_ON - Always initialize the pin as ON on bootup. Does not use flash write cycles.
on_turn_on: # Action when relay is turned on
- script.execute: led_power_on
on_turn_off: # Action when relay is turned off
- script.execute: led_relay_off
output:
# Output GPIOs for RGB led
- platform: esp8266_pwm # Red
id: red_output
pin: GPIO0
- platform: esp8266_pwm # Green
id: green_output
pin: GPIO4
- platform: esp8266_pwm # Blue
id: blue_output
pin: GPIO2
light:
# RGB light
- platform: rgb
name: ${friendly_name} Light
id: rgb_light
red: red_output
green: green_output
blue: blue_output
default_transition_length: 0.5s
restore_mode: ALWAYS_OFF
effects: # List some effects
- strobe
- flicker
- random
# Blink the red light if we aren't connected to WiFi. Could use https://esphome.io/components/status_led.html instead but then we couldn't use the red light for other things as well.
# Only if not connected after 30s
interval:
- interval: 2000ms
then:
- if:
condition:
for:
time: 30s
condition:
not:
wifi.connected:
then:
- light.turn_on:
id: rgb_light
brightness: 100%
red: 100%
green: 0%
blue: 0%
flash_length: 250ms
script:
- id: led_relay_off # Normal operation when relay is off
then:
- light.turn_off:
id: rgb_light
- id: led_power_on # Normal operation when relay is on
then:
- light.turn_on:
id: rgb_light
brightness: 80%
red: 0%
green: 100%
blue: 50%