-
-
Notifications
You must be signed in to change notification settings - Fork 36.5k
Add Shelly script events entities #135979
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
Add Shelly script events entities #135979
Conversation
… this event is send to the hass event bus
|
Hey there @balloob, @bieniu, @thecode, @chemelli74, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Event are hard to use; why not use an event entity? |
|
How should the user create these entities? Should they automatically be created when a user fires an event from the device? |
I think that would be the best option, there is a similar implementation in BTHome.
|
|
I've got a proof of concept working where each script gets it's own event entity. But when creating those entities a list of possible event types that can be fired is required. This is not known at the time of creating because the user can create any event they want within a script. |
|
I've done the following modifications:
Are there any other modifications required? |
- Added device name to event entity - The event entity is now only created when a script has any event types - The test for this entity now uses snapshots
…script and will now be automatically removed when the script no longer exsists
bieniu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one small comment.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
…_listeners and used _event_listeners instead to listen for script events
|
I've removed the dangling |
thecode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @wjtje 👍
bieniu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, tested with a real device, thanks @wjtje 👍

Breaking change
Proposed change
With this change it allows users to write scripts on Shelly devices which can emit events using
Shelly.emitEvent(name, data)that will be send to event entity so automatons can react on it.I've created this example script (shelly-double-toggle.js) that will count the number of times the input is toggled and send that result using an event to Home Assistant so automatons can react on it.
This is an example of how an event emitted by a Shelly device would show up in Home Assistant.

Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: