diff --git a/source/_integrations/shelly.markdown b/source/_integrations/shelly.markdown index 6ada2d20a971..90fbea0edd19 100644 --- a/source/_integrations/shelly.markdown +++ b/source/_integrations/shelly.markdown @@ -331,7 +331,25 @@ The integration supports the following virtual components: ## Scripts (generation 2 and 3) -For each device script, the integration creates a `switch` entity that allows you to control the script. These entities are disabled by default. +For each device script, the integration creates a `switch` entity that allows you to control the script and an `event` entity. These entities are disabled by default. + +The `event` entity shows event that are emitted by the script using [Shelly.emitEvent()](https://shelly-api-docs.shelly.cloud/gen2/Scripts/ShellyScriptLanguageFeatures#shellyemitevent). 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); +``` ## Additional info