Im Home Assistant wird es als 2 Relais mit Symbolen und 2 binären Sensoren (einschließlich Leistung, Strom und Sensoren) angezeigt. Wenn die „max_power“ auf einem Kanal überschritten wird, wird dieser Kanal ausgeschaltet und eine dauerhafte Benachrichtigung wird im HA erstellt. Wenn die „max_temp“ überschritten wird, werden die 2 Kanäle abgeschaltet und eine dauerhafte Benachrichtigung wird im HA erstellt.
configuration.yaml
1substitutions:
2 devicename: shelly_25
3
4 channel_1: Light 1
5 channel_2: Light 2
6
7
8
9 max_power: "2000.0"
10 max_temp: "70.0"
11
12esphome:
13 name: ${devicename}
14 platform: ESP8266
15 board: esp01_1m
16
17wifi:
18 ssid: "WIFI SSID"
19 password: "PW"
20 power_save_mode: none
21 output_power: 20dB
22 fast_connect: on
23 manual_ip:
24 static_ip: 192.168.178.77
25 gateway: 192.168.178.1
26 subnet: 255.255.255.0
27
28
29 # Enable fallback hotspot (captive portal) in case wifi connection fails
30 ap:
31 ssid: "NAME"
32 password: "PW"
33
34
35captive_portal:
36
37# Enable logging
38logger:
39 level: DEBUG
40
41# Enable Home Assistant API
42api:
43
44
45ota:
46
47
48web_server:
49 port: 80
50
51time:
52 - platform: sntp
53 id: my_time
54
55i2c:
56 sda: GPIO12
57 scl: GPIO14
58
59sensor:
60 - platform: ade7953
61 irq_pin: GPIO16 # Prevent overheating by setting this
62 voltage:
63 name: ${devicename} voltage
64 # On the Shelly 2.5 channels are mixed ch1=B ch2=A
65 current_a:
66 name: ${channel_2} current
67 internal: true
68 current_b:
69 name: ${channel_1} current
70 internal: true
71 active_power_a:
72 name: ${channel_2} power
73 id: power_channel_2
74 # active_power_a is normal, so don't multiply by -1
75 on_value_range:
76 - above: ${max_power}
77 then:
78 - light.turn_off: lightid2
79 - homeassistant.service:
80 service: persistent_notification.create
81 data:
82 title: Message from ${devicename}
83 data_template:
84 message: Switch turned off because power exceeded ${max_power}W
85 active_power_b:
86 name: ${channel_1} power
87 id: power_channel_1
88 # active_power_b is inverted, so multiply by -1
89 filters:
90 - multiply: -1
91 on_value_range:
92 - above: ${max_power}
93 then:
94 - light.turn_off: lightid1
95 - homeassistant.service:
96 service: persistent_notification.create
97 data:
98 title: Message from ${devicename}
99 data_template:
100 message: Switch turned off because power exceeded ${max_power}W
101 update_interval: 30s
102
103 - platform: total_daily_energy
104 name: ${channel_1} energy
105 power_id: power_channel_1
106 filters:
107 # Multiplication factor from W to kWh is 0.001
108 - multiply: 0.001
109 unit_of_measurement: kWh
110
111 - platform: total_daily_energy
112 name: ${channel_2} energy
113 power_id: power_channel_2
114 filters:
115 # Multiplication factor from W to kWh is 0.001
116 - multiply: 0.001
117 unit_of_measurement: kWh
118
119 # NTC Temperature
120 - platform: ntc
121 sensor: temp_resistance_reading
122 name: ${devicename} temperature
123 unit_of_measurement: "°C"
124 accuracy_decimals: 1
125 icon: "mdi:thermometer"
126 calibration:
127 b_constant: 3350
128 reference_resistance: 10kOhm
129 reference_temperature: 298.15K
130 on_value_range:
131 - above: ${max_temp}
132 then:
133 - light.turn_off: lightid1
134 - light.turn_off: lightid2
135 - homeassistant.service:
136 service: persistent_notification.create
137 data:
138 title: Message from ${devicename}
139 data_template:
140 message: Switch turned off because temperature exceeded ${max_temp}°C
141 - platform: resistance
142 id: temp_resistance_reading
143 sensor: temp_analog_reading
144 configuration: DOWNSTREAM
145 resistor: 32kOhm
146 - platform: adc
147 id: temp_analog_reading
148 pin: A0
149
150status_led:
151 pin:
152 number: GPIO0
153 inverted: yes
154
155output:
156 - platform: gpio
157 pin: GPIO4
158 id: shelly_25_relay_1
159 - platform: gpio
160 pin: GPIO15
161 id: shelly_25_relay_2
162
163light:
164 - platform: binary
165 name: "${channel_1}"
166 output: shelly_25_relay_1
167 id: lightid1
168 - platform: binary
169 name: "${channel_2}"
170 output: shelly_25_relay_2
171 id: lightid2
172
173binary_sensor:
174 - platform: gpio
175 pin:
176 number: GPIO13
177 name: "${channel_1} input"
178 on_state:
179 then:
180 - light.toggle: lightid1
181 - platform: gpio
182 pin:
183 number: GPIO5
184 name: "${channel_2} input"
185 on_state:
186 then:
187 - light.toggle: lightid2