What I call the scene activation flows are flows that based upon a set of aggregated states, calculates some logic to decide which scene for a given area.
There need to be one scene activation flow for each aggregated state variable that might change, in order to trigger.
I use this naming scheme for the trigger flows: SA areaname [variable].
For the basement, I have these flows:
SA 0etg [presence]
SA 0etg [timeperiod]
SA 0etg [tv]
These three aggregated states are used to calculate which scene is active.
The logic to decide which scene runs as a homeyscript.
Here is an example of SA 0etg [presence]:
Homeyscripts does not have sufficient permissions to set logic variables directly, instead the homeyscript will export a tag, by adding a line like this:
await setTagValue("scene-0kjellerstua", {type: 'string', title:'Scene 0kjellerstua'}, sceneid)
and when the homeyscript run as an and-condition, the result will be available in a tag, and you will set the scene variable in a then-condition. Be aware to use the tag listed under HomeyScript:
I have one homeyscript with logic for each scene variable. The script makes use of a set of logic variables as input. Make sure that the same logic variables that you actually make use of has a trigger flow as mention above (with the variable has changed in the when condition).
Here is the homescript for kjellerstua:
Scene-0etg.jslet variables = await Homey.logic.getVariables()let getVar = (name) => {let x = _.find(variables, (val, key) => {return (val.name === name) })if (typeof x === 'undefined') throw new Error("Could not find variable [" + name + "]")return x}// Variables: home,timeperiod,presence-0etglet home = getVar('home').valuelet timeperiod = getVar('timeperiod').valuelet presence = getVar('presence-0etg').valuelet tv = getVar('tv').value// Scenes: normal, soft, dim, flood// Timeperiods: morning, day, evening, late, nightlet sceneid = "off"if (presence) {if (tv) {sceneid = "tv"} else if (timeperiod === 'day') {sceneid = "normal"} else {sceneid = "dim"}}await setTagValue("scene-0kjellerstua", {type: 'string', title:'Scene 0kjellerstua'}, sceneid)return true;
Here is another example for the second floor:
Scene-2etg.jslet variables = await Homey.logic.getVariables()let getVar = (name) => {let x = _.find(variables, (val, key) => {return (val.name === name) })if (typeof x === 'undefined') throw new Error("Could not find variable [" + name + "]")return x}// Variables: home,bright,timeperiod,presence-2etglet home = getVar('home').valuelet bright = getVar('bright').valuelet timeperiod = getVar('timeperiod').valuelet presence = getVar('presence-2etg').value// Scenes: normal, soft, dim, away, night, nightp, bright, flood// Timeperiods: morning, day, evening, late, nightlet sceneid = "off"if (timeperiod === 'night' && presence) {sceneid = "nightp"} else if (timeperiod === 'night') {sceneid = "night"} else if (!home) {sceneid = "away"} else if (!presence) {sceneid = "night"} else if (bright) {sceneid = "bright"} else if (timeperiod === "morning") {sceneid = "soft"} else if (timeperiod === "evening") {sceneid = "soft"} else if (timeperiod === "late") {sceneid = "dim"} else {sceneid = "normal"}await setTagValue("scene-2etg", {type: 'string', title:'Scene 2etg'}, sceneid)return true;