generated from esphome/esphome-project-template
-
Notifications
You must be signed in to change notification settings - Fork 19
/
localbytes-plug-pm-factory.yaml
73 lines (67 loc) · 2.78 KB
/
localbytes-plug-pm-factory.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
substitutions:
ap_timeout: "5s"
packages:
device_base: !include localbytes-plug-pm.yaml
esphome:
# Factory calibrate the power monitoring
on_boot:
priority: 250
then:
- if:
condition:
#Are we connected to the network
lambda: |-
return strcmp(wifi::global_wifi_component->wifi_ssid().c_str(), "LOCALBYTES_230") == 0;
then:
- switch.turn_on: relay
- lambda: |-
id(power_monitor).set_change_mode_every(4);
id(power_monitor).set_update_interval(250);
- logger.log:
level: INFO
format: "Plug calibration start"
- delay: 4s
- lambda: |-
id(voltage_multiply) = (230 / id(voltage).raw_state);
ESP_LOGI("custom", "Voltage %f -- %f",id(voltage).raw_state,id(voltage_multiply));
id(power_multiply) = (96 / id(power).raw_state);
ESP_LOGI("custom", "Power %f -- %f",id(power).raw_state,id(power_multiply));
id(current_multiply) = (0.42 / id(current).raw_state);
ESP_LOGI("custom", "Current %f -- %f",id(current).raw_state,id(current_multiply));
id(power_monitor).set_change_mode_every(8);
id(power_monitor).set_update_interval(10000);
- delay: 250ms
- if:
condition:
#Is the current power reading somewhat sensible?
lambda: |-
ESP_LOGI("custom", "VPC: %f %f %f",id(voltage).state,id(power).state,id(current).state);
return ((220 <= id(voltage).state) && (id(voltage).state <= 240))
&& ((86 <= id(power).state) && (id(power).state <= 106))
&& ((0.2 <= id(current).state) && (id(current).state < 0.6));
then:
- logger.log:
level: INFO
format: "Plug calibration complete"
- switch.turn_off: relay
- light.turn_off: led
else:
- logger.log:
level: ERROR
format: "Plug calibration error"
- switch.turn_off: relay
- light.turn_on: led
- delay: 0.5s
- light.turn_off: led
- delay: 0.5s
- light.turn_on: led
- delay: 0.5s
- light.turn_off: led
- delay: 0.5s
- light.turn_on: led
- delay: 0.5s
- light.turn_off: led
- delay: 0.5s
- light.turn_on: led
- delay: 0.5s
- light.turn_off: led