Added documentation about the shelly.script_event event type (#36992)

* Added documentation about the shell.script_event

* Added missing comma to improve the flow of the text

* Updated documentation about the new script event entity

* Added an example script which uses events

* Moved the script entity to the correct location in the shelly documentation

Signed-off-by: wjtje <33957974+wjtje@users.noreply.github.com>

---------

Signed-off-by: wjtje <33957974+wjtje@users.noreply.github.com>
This commit is contained in:
Wouter 2025-02-04 13:41:38 +01:00 committed by GitHub
parent c261826d66
commit 71cc89bcf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -154,6 +154,24 @@ If the **BUTTON TYPE** of the switch connected to the device is set to `momentar
If the **Input Mode** of the switch connected to the device is set to `Button`, the integration creates an event entity for this switch. You can use this entity in your automations. If the **Input Mode** of the switch connected to the device is set to `Button`, the integration creates an event entity for this switch. You can use this entity in your automations.
Each script which generates events using [Shelly.emitEvent()](https://shelly-api-docs.shelly.cloud/gen2/Scripts/ShellyScriptLanguageFeatures#shellyemitevent) also gets an corresponding event entity. This entity is disabled by default. After changing a script, it's required to manually reload the device before new event types show up.
For example, the following script will emit an event every time an input (button or switch) on the device is changed.
```javascript
// Example shelly script
function eventHandler(event, userdata) {
if (
typeof event.component === "string" &&
event.component.substring(0, 5) === "input"
) {
let id = Number(event.component.substring(6));
Shelly.emitEvent("input_event", { id: id });
}
}
Shelly.addEventHandler(eventHandler);
```
## Events ## Events
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. 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.