Update shelly.markdown (#17626)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Ron Schaeffer 2021-05-20 15:01:30 +01:00 committed by GitHub
parent a2183ef812
commit 71e16f1990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,9 +70,44 @@ Shelly device relays are added to the Home Assistant by default as `switch` enti
## Events
If the **BUTTON TYPE** of the switch connected to the device is set to `momentary` or `detached switch`, integration fires events when the switch is used. You can use these events in your automations.
If the **BUTTON TYPE** of the switch connected to the device is set to `momentary` or `detached switch`, integration fires events under the type `shelly.click` when the switch is used. You can use these events in your automations.
### Automation examples
Also, some devices do not add an entity for the button/switch. For example, the Shelly Button1 has only one entity for the battery level. It does not have an entity for the button itself. To trigger automations based on button presses, use the `shelly.click` event.
### Listening for events
You can subscribe to the `shelly.click` event type in [Developer Tools/Events](/docs/tools/dev-tools/) in order to examine the event data JSON for the correct parameters to use in your automations. For example, `shelly.click` returns event data JSON similar to the following when you press the Shelly Button1.
```json
Event 0 fired 9:53 AM:
{
"event_type": "shelly.click",
"data": {
"device_id": "e09c64a22553484d804353ef97f6fcd6",
"device": "shellybutton1-A4C12A45174",
"channel": 1,
"click_type": "single"
},
"origin": "LOCAL",
"time_fired": "2021-04-28T08:53:12.755729+00:00",
"context": {
"id": "e0f379706563aaa0c2c1fda5174b5a0e",
"parent_id": null,
"user_id": null
}
}
```
### Automations
The simplest way to create automations is to use the Home Assistant automation editor. For example, to set an automation triggered by a double press of a particular Shelly Button1:
1. In the Triggers section of the automation, set Trigger Type to `Device`.
2. In the Device dropdown menu. find the Shelly Button1.
3. In the Trigger dropdown menu, select `Button double clicked`.
4. Set any conditions and actions to complete your automation.
You can also create automations using YAML, for example:
```yaml
- alias: "Toggle living room light"