-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchbot_switch.yaml
47 lines (45 loc) · 1.6 KB
/
switchbot_switch.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
# switchbot_switch.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:
# Switchbot mapped from https://github.com/fphammerle/switchbot-mqtt
switchbot_switch:
type: Switch
capabilities: ["power_switch", "toggle", "battery_power", "wifi_status"]
primary_attribute: power_switch.state
requires: [topic]
description: Switchbot switch mapped via switchbot-mqtt
query: "homeassistant/switch/switchbot/%topic%/request-device-info"
events:
"homeassistant/switch/switchbot/%topic%/state":
"power_switch.state":
expr: "payload == 'ON'"
"x_mqtt_device.online": true
"homeassistant/switch/switchbot/%topic%/battery-percentage":
"battery_power.level":
expr: "float(payload ?? 0)/100"
"battery_power.since":
expr: "time()"
"x_mqtt_device.online": true
"homeassistant/switchbot-mqtt/status":
"x_mqtt_device.online":
expr: "payload == 'online'"
actions:
power_switch:
"on":
topic: "homeassistant/switch/switchbot/%topic%/set"
payload: "ON"
"off":
topic: "homeassistant/switch/switchbot/%topic%/set"
payload: "OFF"
"set":
topic: "homeassistant/switch/switchbot/%topic%/set"
payload:
expr: "parameters.state ? 'ON' : 'OFF'"
type: raw
# toggle.toggle is implemented by the default handler in MQTTController