Scene activations
Logic deciding which scene to activate depending on a set of aggregated state variables.
Be aware: In order to use scene activations, basic knowledge of javascript is required.
I have one scene activation logic for each scene variable. A scene variable is a text value representing the different available scenes for a room or area.
The scene activation is responsible for translating a set of input variables (aggregated state) into one of the available scenes for a room.
A very basic example: bedroom
Bedroom has a scene variable scene-bedroom, a text string that always contains one of the defined scenes for that room. In a simple setup a room can have off, normal, dimmed.
The logic to decide the scene, may be bright, presence-bedroom and timeperiod. Both bright and presence-bedroom is boolean, indicating whether there is bright daylight and whether there is someone present in the bedroom (motion and door sensors). The timeperiod variable is a string that can contain one of a few values indicating which part of the day.
A scene activation consists of a homeyscript and a flow that triggers the homeyscript. I use homeyscript because it allows more advanced logic than what is available in the flow editor (which is far too limited).
The flow Scene activation bedroom, triggers when one of aggregated state variables that are involved changes.

The scene activation flow
Use the better logic "On of these variables changed" card, as seen in the illustration above.
The card takes a comma-separated list of better logic variables – the aggregated state variables that is needed for this flow.
The scene activation homeyscript
The scene activation homeyscript will run when one of the aggregated state variables changes. The script can be split into three sections:
Fetching the aggregated state variables
Logic calculating the output scene depending on the aggregated state.
Setting the output scene variable
Fetching the aggregated state variables
The first section with helper functions is the same for all scene activation homeyscript, and can be copied as part of a boiler plate template.
In the example above we fetch three better logic variables into local javascript variables available to perform the logic.
Output the variables to the console for debugging is useful:
Scene logic
We use the aggregated state variables fetched above to decide which scene to activate for this room. It must always end up with one of the defined scenes for that room.
Setting the scene variable
Notice the trailing slash needed to be added to the name of the better logic scene variable.
Complete example
The complete homeyscript as described above:
Testing the scene activation
Use the better logic app settings and manually edit each of the aggregate states, and verify that the scene variable are updated correctly, and also verify how the lighting, music or temperature changes accordingly to the scene.
One common mistake is the have typos in the "On of these variables changed"-card.
Alternative way of fetching variables
If you run into issues with delays adding up when fetching a large number of variables, you may fetch data in parallell like this:
More examples
Living room lights
Here is the homescript for kjellerstua:
Outdoor lights
Example for outdoor lighting.
2nd floor lights
Here is another older example for the second floor:
Children's room lights
Example from a childrens room. inputScene is a variable controlled by a person using a set of buttons for choosing modus.
Music 2nd floor lights
Here is an example controlling a music scene, including a variable for music volume:
Music bathroom
Here is another logic for music, controlling music on the bathroom:
Last updated
Was this helpful?