Skip to content

Commit

Permalink
Support triple_push event for relays (#164)
Browse files Browse the repository at this point in the history
* Support triple_push event

* Update readme files
  • Loading branch information
bieniu authored Feb 14, 2023
1 parent 54ebc4f commit f99ce15
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![PayPal_Me][paypal-me-shield]][paypal-me]

## :warning: WARNING
Please do not update firmware to `0.12.0` if you are using `consumption type` for relays. The new firmware does not handle `consumption type` correctly.
Firmware `0.12.x` and `0.13.x` don't support `consumption type` for relays.

This script adds MQTT discovery support for Shelly Gen2 devices in the [Home Assistant](https://home-assistant.io/).

Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Community Forum][forum-shield]][forum] [![Buy me a coffee][buy-me-a-coffee-shield]][buy-me-a-coffee] [![PayPal_Me][paypal-me-shield]][paypal-me]

## :warning: WARNING
Please do not update firmware to `0.12.0` if you are using `consumption type` for relays. The new firmware does not handle `consumption type` correctly.
Firmware `0.12.x` and `0.13.x` don't support `consumption type` for relays.

This script adds MQTT discovery support for Shelly Gen2 devices in the [Home Assistant](https://home-assistant.io/).

Expand Down
89 changes: 71 additions & 18 deletions python_scripts/shellies_discovery_gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
EVENT_DOUBLE_PUSH = "double_push"
EVENT_LONG_PUSH = "long_push"
EVENT_SINGLE_PUSH = "single_push"
EVENT_TRIPLE_PUSH = "triple_push"

HOME_ASSISTANT = "home-assistant"

Expand Down Expand Up @@ -293,6 +294,7 @@
TRIGGER_BUTTON_DOUBLE_PRESS = "button_double_press"
TRIGGER_BUTTON_LONG_PRESS = "button_long_press"
TRIGGER_BUTTON_SHORT_PRESS = "button_short_press"
TRIGGER_BUTTON_TRIPLE_PRESS = "button_triple_press"

UNIT_AMPERE = "A"
UNIT_CELSIUS = "°C"
Expand All @@ -311,6 +313,7 @@
EVENT_DOUBLE_PUSH: TRIGGER_BUTTON_DOUBLE_PRESS,
EVENT_LONG_PUSH: TRIGGER_BUTTON_LONG_PRESS,
EVENT_SINGLE_PUSH: TRIGGER_BUTTON_SHORT_PRESS,
EVENT_TRIPLE_PUSH: TRIGGER_BUTTON_TRIPLE_PRESS,
}

DESCRIPTION_BUTTON_MUTE_ALARM = {
Expand Down Expand Up @@ -770,7 +773,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 1,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 1,
ATTR_RELAY_BINARY_SENSORS: {SENSOR_OVERTEMP: DESCRIPTION_SENSOR_OVERTEMP},
ATTR_SENSORS: {
Expand All @@ -783,7 +791,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PLUS_1PM: {
ATTR_NAME: "Shelly Plus 1PM",
Expand All @@ -792,7 +800,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 1,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 1,
ATTR_RELAY_BINARY_SENSORS: {
SENSOR_OVERPOWER: DESCRIPTION_SENSOR_OVERPOWER,
Expand All @@ -816,7 +829,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PLUS_2PM: {
ATTR_NAME: "Shelly Plus 2PM",
Expand All @@ -834,7 +847,12 @@
},
ATTR_INPUTS: 2,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 2,
ATTR_RELAY_BINARY_SENSORS: {
SENSOR_OVERPOWER: DESCRIPTION_SENSOR_OVERPOWER,
Expand All @@ -859,7 +877,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PLUS_HT: {
ATTR_BATTERY_POWERED: True,
Expand Down Expand Up @@ -888,7 +906,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 4,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_SENSORS: {
SENSOR_LAST_RESTART: DESCRIPTION_SENSOR_LAST_RESTART,
SENSOR_SSID: DESCRIPTION_SENSOR_SSID,
Expand All @@ -899,7 +922,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PLUS_PLUG_IT: {
ATTR_NAME: "Shelly Plus Plug IT",
Expand Down Expand Up @@ -1065,7 +1088,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 2,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 1,
ATTR_RELAY_BINARY_SENSORS: {SENSOR_OVERTEMP: DESCRIPTION_SENSOR_OVERTEMP},
ATTR_SENSORS: {
Expand All @@ -1079,7 +1107,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PRO_1PM: {
ATTR_NAME: "Shelly Pro 1PM",
Expand All @@ -1088,7 +1116,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 2,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 1,
ATTR_RELAY_BINARY_SENSORS: {
SENSOR_OVERPOWER: DESCRIPTION_SENSOR_OVERPOWER,
Expand All @@ -1114,7 +1147,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PRO_2: {
ATTR_NAME: "Shelly Pro 2",
Expand All @@ -1123,7 +1156,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 2,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 2,
ATTR_RELAY_BINARY_SENSORS: {SENSOR_OVERTEMP: DESCRIPTION_SENSOR_OVERTEMP},
ATTR_SENSORS: {
Expand All @@ -1137,7 +1175,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
MODEL_PRO_2PM: {
ATTR_NAME: "Shelly Pro 2PM",
Expand All @@ -1155,7 +1193,12 @@
},
ATTR_INPUTS: 2,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 2,
ATTR_RELAY_BINARY_SENSORS: {
SENSOR_OVERPOWER: DESCRIPTION_SENSOR_OVERPOWER,
Expand Down Expand Up @@ -1190,7 +1233,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 3,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 3,
ATTR_RELAY_BINARY_SENSORS: {SENSOR_OVERTEMP: DESCRIPTION_SENSOR_OVERTEMP},
ATTR_RELAY_SENSORS: {SENSOR_TEMPERATURE: DESCRIPTION_SENSOR_RELAY_TEMPERATURE},
Expand Down Expand Up @@ -1250,7 +1298,12 @@
ATTR_BUTTONS: {BUTTON_RESTART: DESCRIPTION_BUTTON_RESTART},
ATTR_INPUTS: 4,
ATTR_INPUT_BINARY_SENSORS: {SENSOR_INPUT: DESCRIPTION_SENSOR_INPUT},
ATTR_INPUT_EVENTS: [EVENT_SINGLE_PUSH, EVENT_DOUBLE_PUSH, EVENT_LONG_PUSH],
ATTR_INPUT_EVENTS: [
EVENT_SINGLE_PUSH,
EVENT_DOUBLE_PUSH,
EVENT_LONG_PUSH,
EVENT_TRIPLE_PUSH,
],
ATTR_RELAYS: 4,
ATTR_RELAY_BINARY_SENSORS: {
SENSOR_OVERPOWER: DESCRIPTION_SENSOR_OVERPOWER,
Expand All @@ -1276,7 +1329,7 @@
UPDATE_FIRMWARE: DESCRIPTION_UPDATE_FIRMWARE,
UPDATE_FIRMWARE_BETA: DESCRIPTION_UPDATE_FIRMWARE_BETA,
},
ATTR_MIN_FIRMWARE_DATE: 20220308,
ATTR_MIN_FIRMWARE_DATE: 20230209,
},
}

Expand Down

0 comments on commit f99ce15

Please sign in to comment.