Scene activations

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:

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.js
let 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-0etg
let home = getVar('home').value
let timeperiod = getVar('timeperiod').value
let presence = getVar('presence-0etg').value
let tv = getVar('tv').value
// Scenes: normal, soft, dim, flood
// Timeperiods: morning, day, evening, late, night
let 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.js
let 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-2etg
let home = getVar('home').value
let bright = getVar('bright').value
let timeperiod = getVar('timeperiod').value
let presence = getVar('presence-2etg').value
// Scenes: normal, soft, dim, away, night, nightp, bright, flood
// Timeperiods: morning, day, evening, late, night
let 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;