Skip to content

Commit

Permalink
Add "ac_power" argument for ShellyH&T
Browse files Browse the repository at this point in the history
  • Loading branch information
bieniu committed Sep 10, 2019
1 parent c124486 commit 6f1d8a4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Go to [HA community](https://community.home-assistant.io/t/shellies-discovery-sc
- Shelly Plug
- Shelly Plug S
- Shelly RGBW2 (color and white mode)
- Shelly H&T
- Shelly H&T (with or without USB adapter)
- Shelly Smoke
- Shelly Sense
- ShellyEM
Expand Down Expand Up @@ -102,6 +102,7 @@ automation:
shellyswitch-334455: 'cover'
shellyrgbw2-AABB22: 'white'
shellyrgbw2-CC2211: 'rgbw'
shellyht-2200AA: 'ac_power'
```
## Script arguments
key | optional | type | default | description
Expand Down
5 changes: 3 additions & 2 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- Shelly Plug
- Shelly Plug S
- Shelly RGBW2 (color and white mode)
- Shelly H&T
- Shelly H&T (with or without USB adapter)
- Shelly Smoke
- Shelly Sense
- ShellyEM
Expand Down Expand Up @@ -64,7 +64,7 @@ automation:
data:
topic: shellies/command
payload: announce

- id: 'shellies_discovery'
alias: 'Shellies Discovery'
trigger:
Expand All @@ -85,6 +85,7 @@ automation:
shellyswitch-334455: 'cover'
shellyrgbw2-AABB22: 'white'
shellyrgbw2-CC2211: 'rgbw'
shellyht-2200AA: 'ac_power'
```
## Script arguments
key | optional | type | default | description
Expand Down
15 changes: 13 additions & 2 deletions python_scripts/shellies_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
shellyswitch-334455: 'cover'
shellyrgbw2-AABB22: 'white'
shellyrgbw2-CC2211: 'rgbw'
shellyht-2200AA: 'ac_power'
qos - maximum QoS level of the topics, this is optional argument, default is 0 (integer)
Expand All @@ -71,6 +72,8 @@
shellyrgbw2-CC2211: 'rgbw' - means that Shelly RGBW2 works in color-mode
(default)
shellyht-2200AA: 'ac_power' - means that ShellyH&T is AC powered via USB adapter
You can install script manually or via HACS.
"""

Expand Down Expand Up @@ -149,7 +152,9 @@
ATTR_OFF = "off"
ATTR_TRUE_FALSE_PAYLOAD = {ATTR_ON: "true", ATTR_OFF: "false"}
ATTR_1_0_PAYLOAD = {ATTR_ON: "1", ATTR_OFF: "0"}
ATTR_EXPIRE_AFTER = "43200"
ATTR_AC_POWER = "ac_power"

expire_after = "43200"

develop = False
retain = True
Expand Down Expand Up @@ -618,14 +623,20 @@
state_topic = "~{}".format(sensors[sensor_id])
else:
state_topic = "~sensor/{}".format(sensors[sensor_id])
if data.get(id):
if data.get(id) == ATTR_AC_POWER:
expire_after = "7200"
elif data.get(id.lower()):
if data.get(id.lower()) == ATTR_AC_POWER:
expire_after = "7200"
if battery_powered:
payload = (
'{"name":"' + sensor_name + '",'
'"stat_t":"' + state_topic + '",'
'"unit_of_meas":"' + sensors_units[sensor_id] + '",'
'"dev_cla":"' + sensors_classes[sensor_id] + '",'
'"val_tpl":"' + sensors_templates[sensor_id] + '",'
'"exp_aft":"' + ATTR_EXPIRE_AFTER + '",'
'"exp_aft":"' + expire_after + '",'
'"uniq_id":"' + unique_id + '",'
'"qos":"' + str(qos) + '",'
'"dev": {"ids": ["' + mac + '"],'
Expand Down

0 comments on commit 6f1d8a4

Please sign in to comment.