summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--esphome/config/powerplug_awp07l.yaml128
-rw-r--r--esphome/config/pswitch.yaml172
2 files changed, 300 insertions, 0 deletions
diff --git a/esphome/config/powerplug_awp07l.yaml b/esphome/config/powerplug_awp07l.yaml
new file mode 100644
index 0000000..08a9e62
--- /dev/null
+++ b/esphome/config/powerplug_awp07l.yaml
@@ -0,0 +1,128 @@
1substitutions:
2 device_name: powerplug-awp07l
3 friendly_name: "Power Plug AWP07L"
4 #current_resistor: 0.001
5 #voltage_divider: 1886
6 current_resistor: 0.000995585395670478
7 voltage_divider: 1913.830752419618
8 current_multiply: 0.8667070272988949
9 # max power is 3450W for 15A and 2300W for 10A
10 max_power: "2300"
11
12esphome:
13 name: ${device_name}
14 friendly_name: ${friendly_name}
15
16esp8266:
17 board: esp01_1m
18
19# Enable logging
20logger:
21 # make RXD / TXD available
22 baud_rate: 0
23
24# Enable Home Assistant API
25api:
26 encryption:
27 key: !secret api_encryption_key
28
29# OTA
30ota:
31 - platform: esphome
32 password: !secret ota_password
33
34# WiFi Credentials
35wifi:
36 domain: .lan
37 ssid: !secret wifi_ssid
38 password: !secret wifi_password
39 # see https://github.com/esphome/issues/issues/1532
40 power_save_mode: HIGH
41
42 # Enable fallback hotspot (captive portal) in case wifi connection fails
43 ap:
44 ssid: "${device_name} Hotspot"
45 password: !secret wifi_ap_password
46
47captive_portal:
48
49binary_sensor:
50 - platform: gpio
51 name: "Button"
52 device_class: power
53 pin:
54 number: GPIO13
55 inverted: true
56 on_press:
57 - switch.toggle: relay
58 internal: true
59
60sensor:
61 - platform: hlw8012
62 model: BL0937
63 sel_pin:
64 number: GPIO12
65 inverted: true
66 cf_pin: GPIO05
67 cf1_pin: GPIO14
68 current_resistor: ${current_resistor}
69 voltage_divider: ${voltage_divider}
70 current:
71 name: "Current"
72 unit_of_measurement: "A"
73 accuracy_decimals: 3
74 icon: "mdi:flash-outline"
75 filters:
76 - multiply: ${current_multiply}
77 - throttle_with_priority:
78 timeout: 10s
79 value:
80 - nan
81 - 0
82 voltage:
83 name: "Voltage"
84 unit_of_measurement: "V"
85 icon: "mdi:flash-outline"
86 filters:
87 - throttle_with_priority:
88 timeout: 10s
89 value:
90 - nan
91 - 0
92 power:
93 name: "Power"
94 unit_of_measurement: "W"
95 icon: "mdi:flash-outline"
96 filters:
97 - throttle_with_priority:
98 timeout: 10s
99 value:
100 - nan
101 - 0
102 on_value_range:
103 - above: ${max_power}
104 then:
105 - switch.turn_off: relay
106 - output.turn_off: led
107 energy:
108 name: "Energy"
109 unit_of_measurement: "Wh"
110 icon: "mdi:flash-outline"
111 update_interval: 1s
112 change_mode_every: 4
113
114switch:
115 - platform: gpio
116 name: "Relay"
117 pin: GPIO15
118 id: relay
119 on_turn_on:
120 - output.turn_on: led
121 on_turn_off:
122 - output.turn_off: led
123
124output:
125 - platform: esp8266_pwm
126 id: led
127 pin: GPIO00
128 inverted: true
diff --git a/esphome/config/pswitch.yaml b/esphome/config/pswitch.yaml
new file mode 100644
index 0000000..3b361e1
--- /dev/null
+++ b/esphome/config/pswitch.yaml
@@ -0,0 +1,172 @@
1substitutions:
2 device_name: pswitch
3 friendly_name: "Printer Switch"
4 current_resistor: 0.0007978220592127652
5 voltage_divider: 4422.084168336673
6 # max power is 3450W for 15A and 2300W for 10A
7 max_power: "3450"
8
9esphome:
10 name: ${device_name}
11 friendly_name: ${friendly_name}
12
13esp8266:
14 board: esp01_1m
15
16# Enable logging
17logger:
18 # make RXD / TXD available
19 baud_rate: 0
20 level: DEBUG
21
22# Enable Home Assistant API
23api:
24 encryption:
25 key: !secret api_encryption_key
26
27# OTA
28ota:
29 - platform: esphome
30 password: !secret ota_password
31
32# WiFi Credentials
33wifi:
34 domain: .lan
35 ssid: !secret wifi_ssid
36 password: !secret wifi_password
37 # see https://github.com/esphome/issues/issues/1532
38 power_save_mode: HIGH
39
40 # Enable fallback hotspot (captive portal) in case wifi connection fails
41 ap:
42 ssid: "${device_name} Hotspot"
43 password: !secret wifi_ap_password
44
45captive_portal:
46
47binary_sensor:
48 - platform: gpio
49 name: "Button"
50 device_class: power
51 pin:
52 number: GPIO01
53 inverted: true
54 on_press:
55 - switch.toggle: relay
56 internal: true
57
58sensor:
59 - platform: hlw8012
60 model: BL0937
61 sel_pin: GPIO12
62 cf_pin: GPIO04
63 cf1_pin: GPIO05
64 current_resistor: ${current_resistor}
65 voltage_divider: ${voltage_divider}
66 voltage:
67 id: voltage
68 filters:
69 - skip_initial: 2
70 power:
71 id: power
72 internal: true
73 filters:
74 - skip_initial: 2
75 on_value:
76 then:
77 # calculate current through P=U*I
78 - lambda: id(current).publish_state(x / id(voltage).state);
79 # idle power down. <5W
80 - if:
81 condition:
82 for:
83 time: 5min
84 condition:
85 and:
86 - switch.is_on: relay
87 - lambda: return id(power).state < 5.0;
88 then:
89 - logger.log: "idle power down"
90 - switch.turn_off: relay
91 on_value_range:
92 - above: ${max_power}
93 then:
94 - switch.turn_off: relay
95 energy:
96 id: energy
97 internal: true
98 update_interval: 1s
99 initial_mode: "VOLTAGE"
100 change_mode_every: never
101
102 - platform: template
103 id: current
104 accuracy_decimals: 3
105 update_interval: never
106 internal: true
107
108 # templates sensors for the ui. we only update the sensor on relay events or through interval
109 # but only if switch is on. this way we don't push updates without changes to frontend
110 - platform: template
111 name: "Current"
112 id: current_ui
113 unit_of_measurement: "A"
114 accuracy_decimals: 3
115 icon: "mdi:flash-outline"
116 update_interval: never
117
118 - platform: template
119 name: "Voltage"
120 id: voltage_ui
121 unit_of_measurement: "V"
122 icon: "mdi:flash-outline"
123 update_interval: never
124
125 - platform: template
126 name: "Power"
127 id: power_ui
128 unit_of_measurement: "W"
129 icon: "mdi:flash-outline"
130 update_interval: never
131
132 - platform: template
133 name: "Energy"
134 id: energy_ui
135 unit_of_measurement: "Wh"
136 icon: "mdi:flash-outline"
137 update_interval: never
138
139switch:
140 - platform: gpio
141 name: "Relay"
142 id: relay
143 pin: GPIO14
144 on_turn_on:
145 - output.turn_on: led
146 - lambda: id(current_ui).publish_state(id(current).state);
147 - lambda: id(voltage_ui).publish_state(id(voltage).state);
148 - lambda: id(power_ui).publish_state(id(power).state);
149 - lambda: id(energy_ui).publish_state(id(energy).state);
150 on_turn_off:
151 - output.turn_off: led
152 - lambda: id(current_ui).publish_state(0.0);
153 - lambda: id(voltage_ui).publish_state(0.0);
154 - lambda: id(power_ui).publish_state(0.0);
155 - lambda: id(energy_ui).publish_state(0.0);
156
157output:
158 - platform: esp8266_pwm
159 id: led
160 pin: GPIO13
161
162interval:
163 - interval: 10s
164 then:
165 - if:
166 condition:
167 switch.is_on: relay
168 then:
169 - lambda: id(current_ui).publish_state(id(current).state);
170 - lambda: id(voltage_ui).publish_state(id(voltage).state);
171 - lambda: id(power_ui).publish_state(id(power).state);
172 - lambda: id(energy_ui).publish_state(id(energy).state);