Hey , I would like to introduce a custom integration I created:
Stateful Scenes
Do you want to use your Home Assistant scenes in HomeKit, but get annoyed when the scenes do not stay ‘on’?
Stateful Scenes solves this problem by creating a switch for each scene and inferring the state of the scene by analysing the entities in the scene. Plus, when you activate a scene in Home Assistant, the scene will also turn on in HomeKit—magic!
Installation
HACS – custom repository
Click this button:
Or, in HACS go to integrations and then click the three buttons at the top right. From there, add a custom repository. Repository name is hugobloem/stateful_scenes
and the category is integration
.
HACS – default repository (not available yet)
Install via HACS by searching for stateful scenes
in the integrations section
Manual
Or, clone the repository and copy the custom_components folder to your home assistant config folder.
git clone GitHub - hugobloem/stateful_scenes: Stateful Scenes in Home Assistant (Home Kit scene compatible) cp -r stateful_scenes/custom_components config/
Configuration
This integration is now configured via the config flow. After you have installed and restarted Home Assistant, go to Devices and Services, Add Integration, and search for Stateful Scenes. Alternatively, just click this button:
Scene path
If your configuration has a different location for scenes you can change the location by changing the Scene path
variable. By default, Home Assistant places all scenes inside scenes.yaml
which is where this integration retrieves the scenes.
Rounding tolerance
Some attributes such as light brightness will be rounded off. Therefore, to assess whether the scene is active a tolerance will be applied. The default tolerance of 1 will work for rounding errors of ±1. If this does not work for your setup consider increasing this value.
Transition time
Furthermore, you can specify the default transition time for applying scenes. This will gradually change the lights of a scene to the specified state. It does need to be supported by your lights.
Supported attributes
Note that while all entity states are supported only some entity attributes are supported at the moment. For the entities listed in the table the state is supported as well as the attributes in the table. Please open an issue, if you want support for other entity attributes.
Entity Domain | Attributes |
---|---|
light |
brightness , rgb_color , effect |
cover |
position |
media_player |
volume_level , source |
fan |
direction , oscillating , percentage |
Scene configurations
For each scene you can specify the individual transition time by changing the transition time variable on the scene’s device page.
HomeKit configuration
Once you have configured this integration, you can add the scenes to HomeKit. I assume that you already set up and configured the HomeKit integration. Expose the newly added switches to HomeKit. Then, in HomeKit define scenes for each Stateful Scenes switch.
Going forward
I have a few things I would like to add to this project, such as restoring entities to a previous state when turning off a scene. If you have any suggestions, please leave a comment, or open an issue on Github. Also, if you run into any problems do not hesitate to reach out on here, or through Github.