summaryrefslogtreecommitdiffstats
path: root/esphome/config/printerswitch.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'esphome/config/printerswitch.yaml')
-rw-r--r--esphome/config/printerswitch.yaml172
1 files changed, 172 insertions, 0 deletions
diff --git a/esphome/config/printerswitch.yaml b/esphome/config/printerswitch.yaml
new file mode 100644
index 0000000..55ca307
--- /dev/null
+++ b/esphome/config/printerswitch.yaml
@@ -0,0 +1,172 @@
1substitutions:
2 device_name: printerswitch
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);