-
Notifications
You must be signed in to change notification settings - Fork 0
/
shelly_gen1.yaml
357 lines (327 loc) · 10.8 KB
/
shelly_gen1.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# shelly_gen1.yaml
#
# Copyright (C) 2022-2024 Daniele Bochicchio, All Rights Reserved
# For updates see https://github.com/dbochicchio/reactor-mqtt-contrib
#
# *** IMPORTANT ***
# Every time you update the files, a restart is needed.
---
templates:
# Shelly online template
shelly_online_gen1:
capabilities: ["x_mqtt_device"]
# , "x_shelly_gen1"]
requires: [topic]
description: Shelly Online template for gen 1 - dot not use directly
query:
topic: "shellies/%topic%/command"
payload: "update"
qos: 0
retain: false
#lwt: "shellies/%topic%/online"
include:
- shelly_wifi_gen1 # from MQTTController
events:
# "shellies/%topic%/announce":
# "x_shelly_gen1.firwmare_available":
# json_payload: true
# expr: "bool(payload.new_fw)"
# "x_mqtt_device.online":
# expr: 'true'
"shellies/%topic%/online":
"x_mqtt_device.online":
expr: 'bool(payload)'
# actions:
# x_shelly_gen1:
# update_firmware:
# topic: "shellies/%topic%/command"
# payload: "update_fw"
# Shelly relay (simple template)
shelly_relay_simple:
type: Switch
capabilities: ["power_switch", "toggle"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly relay
include:
- shelly_online_gen1
events:
"shellies/%topic%/relay/%channel%":
"power_switch.state":
expr: 'payload == "on"'
"x_mqtt_device.online": true
actions:
power_switch:
on:
topic: "shellies/%topic%/relay/%channel%/command"
payload: "on"
off:
topic: "shellies/%topic%/relay/%channel%/command"
payload: "off"
set:
topic: "shellies/%topic%/relay/%channel%/command"
payload:
expr: "parameters.state ? 'on' : 'off'"
type: raw
# toggle.toggle is implemented by the default handler in MQTTController
# Shelly relay (simple template, reversed)
# HINT: this is useful for relays that are normally closed
shelly_relay_simple_reversed:
type: Switch
capabilities: ["power_switch", "toggle"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly relay (reversed - normally closed)
include:
- shelly_online_gen1
events:
"shellies/%topic%/relay/%channel%":
"power_switch.state":
expr: "payload != 'on'"
"x_mqtt_device.online": true
actions:
power_switch:
on:
topic: "shellies/%topic%/relay/%channel%/command"
payload: "off"
off:
topic: "shellies/%topic%/relay/%channel%/command"
payload: "on"
set:
topic: "shellies/%topic%/relay/%channel%/command"
payload:
expr: "parameters.state ? 'off' : 'on'"
type: raw
# toggle.toggle is implemented by the default handler in MQTTController
# Shelly relay with power meter
shelly_relay_power:
type: Switch
capabilities: ["power_switch", "toggle", "power_sensor", "energy_sensor"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly relay with power meter
include:
- shelly_online_gen1
- shelly_relay_simple
events:
"shellies/%topic%/relay/%channel%":
"power_sensor.value":
if_expr: "payload == 'off'"
expr: "float(0)"
"power_sensor.units": "W"
"x_mqtt_device.online": true
"shellies/%topic%/relay/%channel%/power":
"power_sensor.value":
expr: "float(payload)"
"power_sensor.units": "W"
"x_mqtt_device.online": true
"shellies/%topic%/relay/%channel%/energy":
"energy_sensor.value":
expr: "round(float(payload) * 0.00001667, 4)" # watt-minute - value / (60 * 1000)
"energy_sensor.units": "KWH"
"x_mqtt_device.online": true
# Shelly dimmer
shelly_dimmer:
type: Switch
capabilities: ["power_switch", "toggle", "dimming", "power_sensor", "energy_sensor"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly dimmer
include:
- shelly_online_gen1
events:
"shellies/%topic%/light/%channel%/status":
"power_switch.state":
json_payload: true
expr: "bool(payload.ison)"
"dimming.level":
json_payload: true
expr: "round(float(payload.brightness) / 100, 0)"
"x_mqtt_device.online": true
"shellies/%topic%/light/%channel%/power":
"power_sensor.value":
expr: "float(payload)"
"power_sensor.units": "W"
"x_mqtt_device.online": true
"shellies/%topic%/light/%channel%/energy":
"energy_sensor.value":
expr: "round(float(payload) * 0.00001667, 4)" # watt-minute - value / (60 * 1000)
"energy_sensor.units": "KWH"
"x_mqtt_device.online": true
actions:
power_switch:
on:
topic: "shellies/%topic%/relay/%channel%/set"
payload:
expr: '{turn: "on"}'
type: json
off:
topic: "shellies/%topic%/relay/%channel%/set"
payload:
expr: '{turn: "off"}'
type: json
set:
topic: "shellies/%topic%/relay/%channel%/command"
payload:
expr: '{turn: parameters.state ? "on" : "off"}'
type: json
dimming:
set:
topic: "shellies/%topic%/relay/%channel%/set"
payload:
expr: '{turn: "on", brightness: round(parameters.level * 100, 0) }'
type: json
# toggle.toggle is implemented by the default handler in MQTTController
# Shelly cover
shelly_cover:
type: Switch
capabilities: ["power_switch", "toggle", "cover", "position", "power_sensor", "energy_sensor"]
primary_attribute: power_switch.state
requires: [topic]
description: Shelly relay
include:
- shelly_online_gen1
events:
"shellies/%topic%/roller/0":
"power_switch.state":
expr: "payload == 'open'"
"cover.state":
expr: "payload == 'open'"
"position.value":
expr: "payload == 'open'? 1 : 0"
if_expr: "payload != 'stop'"
"x_mqtt_device.online": true
"shellies/%topic%/roller/0/pos":
"position.value":
expr: "float(payload) / 100"
if_expr: "payload != '-1'"
"x_mqtt_device.online": true
"shellies/%topic%/roller/0/power":
"power_sensor.value":
expr: "float(payload)"
"power_sensor.units": "W"
"x_mqtt_device.online": true
"shellies/%topic%/roller/0/energy":
"energy_sensor.value":
expr: "round(float(payload) / 0.00001667, 4)" # watt-minute - value / (60 * 1000)
"energy_sensor.units": "KWH"
"x_mqtt_device.online": true
actions:
power_switch:
on:
topic: "shellies/%topic%/roller/0/command"
payload: "open"
off:
topic: "shellies/%topic%/roller/0/command"
payload: "close"
set:
topic: "shellies/%topic%/roller/0/command"
payload:
expr: "parameters.state ? 'open' : 'close'"
type: raw
# toggle.toggle is implemented by the default handler in MQTTController
position:
set:
topic: "shellies/%topic%/roller/0/command/pos"
payload:
expr: "float(parameters.value) * 100"
type: raw
cover:
open:
topic: "shellies/%topic%/roller/0/command"
payload: "open"
close:
topic: "shellies/%topic%/roller/0/command"
payload: "close"
stop:
topic: "shellies/%topic%/roller/0/command"
payload: "stop"
# Shelly as scene controller
shelly_scenecontroller:
type: Button
capabilities: ["scene_activation", "button"]
primary_attribute: button.state
requires: [topic, channel]
description: Shelly as button/scene controller
include:
- shelly_online_gen1
events:
"shellies/%topic%/input_event/%channel%":
"scene_activation.scene_id":
json_payload: true
expr: "payload.event"
"scene_activation.since":
expr: "time()"
"button.state":
json_payload: true
expr: >
payload.event == "S" ? "single" :
payload.event == "SS" ? "double" :
payload.event == "SSS" ? "triple" :
payload.event == "L" ? "long" :
"unknown"
"button.since":
expr: "time()"
"x_mqtt_device.online": true
# Shelly HEM
shelly_hem:
type: ValueSensor
capabilities: ["power_sensor", "energy_sensor", "voltage_sensor", "current_sensor", "power_factor_sensor", "x_energy_sensor_exported"]
primary_attribute: power_sensor.value
requires: [topic, channel]
description: Shelly HEM (EM, 3EM)
include:
- shelly_online_gen1
events:
"shellies/%topic%/emeter/%channel%/power":
"power_sensor.value":
expr: "float(payload)"
"power_sensor.units": "W"
"current_sensor.value":
if_expr: "! isnull(payload) && ! isnull(entity.attributes.voltage_sensor.value)"
expr: "round(float(payload) / entity.attributes.voltage_sensor.value, 2)"
"current_sensor.units": "A"
"x_mqtt_device.online": true
"shellies/%topic%/emeter/%channel%/voltage":
"voltage_sensor.value":
expr: "float(payload)"
"voltage_sensor.units": "V"
"current_sensor.value":
if_expr: "! isnull(payload) && ! isnull(entity.attributes.power_sensor.value)"
expr: "round(entity.attributes.power_sensor.value / float(payload), 2)"
"current_sensor.units": "A"
"x_mqtt_device.online": true
"shellies/%topic%/emeter/%channel%/total":
"energy_sensor.value":
expr: "round(float(payload) * 0.001, 4)" # Wh - value * 0.001
"energy_sensor.units": "KWH"
"x_mqtt_device.online": true
"shellies/%topic%/emeter/%channel%/total_returned":
"x_energy_sensor_exported.value":
expr: "round(float(payload) * 0.001, 4)" # Wh - value * 0.001
"x_energy_sensor_exported.units": "KWH"
"x_mqtt_device.online": true
"shellies/%topic%/emeter/%channel%/pf":
"power_factor_sensor.value":
expr: "float(payload)"
"x_mqtt_device.online": true
# CUSTOM CAPABILITIES for Shellies
capabilities:
# x_shelly_gen1:
# actions:
# update_firmware: {}
# reboot: {}
# attributes:
# firwmare_available:
# type: bool
# default: false
# reboot:
# arguments: {}
# topic: "shellies/%topic%/reboot"
# payload: null
x_energy_sensor_exported:
attributes:
value:
type: real
units:
type: string