Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation about the shelly.script_event event type #36992

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions source/_integrations/shelly.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ If the **BUTTON TYPE** of the switch connected to the device is set to `momentar

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.

At last, it's possible to send events from scripts using the [Shelly.emitEvent()](https://shelly-api-docs.shelly.cloud/gen2/Scripts/ShellyScriptLanguageFeatures#shellyemitevent) function, these events will show up under the type `shelly.script_event`.

wjtje marked this conversation as resolved.
Show resolved Hide resolved
### 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.
Expand Down Expand Up @@ -185,6 +187,32 @@ Event 0 fired 9:53 AM:

The `generation` value indicates the generation of the device that is the source of the event.

The `shelly.script_event` returns event data JSON similar to the following when using the example code for [Shell.emitEvent()](https://shelly-api-docs.shelly.cloud/gen2/Scripts/ShellyScriptLanguageFeatures#shellyemitevent).

wjtje marked this conversation as resolved.
Show resolved Hide resolved
```json
Event 1 fired 9:50 AM:
{
"event_type": "shelly.script_event",
"data": {
"device_id": "e58a73d99f7c0d789d80e60ac20d0e01",
"device": "shellyplus2pm-d0ef76c7242c",
"component": "script:1",
"event": "this_happened",
"data": {
"why": 42,
"what": "when"
}
},
"origin": "LOCAL",
"time_fired": "2025-01-19T08:50:52.214180+00:00",
"context": {
"id": "01JHYW3YNPBHP6C5Z8BJDTPHDN",
"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:
Expand Down
Loading