// Helper functions to be able to fetch variables from the better logic app
let betterlogic = await Homey.apps.getApp({id: "net.i-dev.betterlogic"})
let getVar = async (name) => {
let x = await betterlogic.apiGet(name)
if (!x) throw new Error("Could not find variable [" + name + "]")
// Fetch the aggregated state variables that is needed to do the logic.
let timeperiod = await getVar('timeperiod')
let presence = await getVar('presence-bedroom')
let bright = await getVar('bright')
// timeperiod values: morning, day, evening, late, night
if (bright && timperiod !== 'morning') {
} else if (timeperiod !== "night") {
console.log("Setting scene to [" + scene + "]")
betterlogic.apiPut("scene-bedroom/" + scene)