-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelly_gen3.yaml
118 lines (109 loc) · 4.04 KB
/
shelly_gen3.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
# shelly_plus_relay_simple.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_gen3:
capabilities: ["x_mqtt_device"]
requires: [topic]
description: Shelly Gen3 Online status
include:
- shelly_wifi_gen3 # from MQTTController
events:
"%topic%/online":
"x_mqtt_device.online":
expr: 'bool(payload)'
# Shelly relay (simple template)
shelly_relay_gen3:
type: Switch
capabilities: ["power_switch", "toggle"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly Gen3 relay
lwt: "%topic%/online"
query:
topic: "%topic%/command"
payload: "status_update"
include:
- shelly_online_gen3
events:
# command-based events
"%topic%/status/switch:%channel%":
"power_switch.state":
json_payload: true
if_expr: "payload?.output !== null"
expr: "bool( payload.output )"
"x_mqtt_device.online": true
# RPC-based events
# {"src":"shellyplus1-cc7b5c87baa0","dst":"shellies/shelly-sprinklers-terrace/events","method":"NotifyStatus","params":{"ts":1716622594.36,"switch:0":{"id":0,"output":true,"source":"http","timer_duration":300.00,"timer_started_at":1716622594.37}}}
"%topic%/events/rpc":
"power_switch.state":
json_payload: true
if_expr: "(payload.method==='NotifyStatus' || payload.method==='NotifyFullStatus') && payload?.params?['switch:' + str(channel)]?.output !== null"
expr: "bool( payload.params['switch:' + str(channel)].output )"
"x_mqtt_device.online": true
actions:
power_switch:
"on":
topic: "%topic%/command/switch:%channel%"
payload: "on"
"off":
topic: "%topic%/command/switch:%channel%"
payload: "off"
"set":
topic: "%topic%/command/switch:%channel%"
payload:
expr: "parameters.state ? 'on' : 'off'"
type: raw
# toggle.toggle is implemented by the default handler in MQTTController
# Shelly relay with power meter
shelly_relay_power_gen3:
type: Switch
capabilities: ["power_sensor", "energy_sensor", "voltage_sensor", "current_sensor"]
primary_attribute: power_switch.state
requires: [topic, channel]
description: Shelly Gen3 relay with power meter
lwt: "%topic%/online"
query:
topic: "%topic%/command"
payload: "status_update"
include:
- shelly_relay_gen3
events:
"%topic%/events/rpc":
"power_switch.state":
json_payload: true
if_expr: "(payload.method==='NotifyStatus' || payload.method==='NotifyFullStatus') && payload?.params?['switch:' + str(channel)]?.output !== null"
expr: "bool( payload.params['switch:' + str(channel)].output )"
"x_mqtt_device.online": true
"%topic%/status/switch:%channel%":
# "power_switch.state":
# json_payload: true
# if_expr: "payload?.output !== null"
# expr: "bool( payload.output )"
"power_sensor.value":
json_payload: true
if_expr: "payload?.apower != null"
expr: "float( payload.apower )"
"power_sensor.units": "W"
"energy_sensor.value":
json_payload: true
if_expr: "payload?.aenergy?.total != null"
expr: "round(float( payload.aenergy.total) * 0.00001667, 4)" # value / (60 * 1000)
"energy_sensor.units": "KWH"
"current_sensor.value":
json_payload: true
if_expr: "payload?.current != null"
expr: "round(float( payload.current ), 2)"
"current_sensor.units": "A"
"voltage_sensor.value":
json_payload: true
if_expr: "payload?.voltage != null"
expr: "round(float( payload.voltage ), 2)"
"voltage_sensor.units": "V"
"x_mqtt_device.online": true