Hier een overzicht hoe ik op SMPL display mijn zwembad water data informatie toon (met name om te vertellen hoeveel PH- / PH+ of Chloor erin moet.
Dit is mijn advanced flow
Dit zijn mijn variabelen
Dit is mijn script voor Chloor (idem voor plus met andere variablen)
const variables = await Homey.logic.getVariables()
//console.log('variables', variables)
const id = "089c8476-9044-4bcc-8508-8743f42ea3a7" // my ChlorineMessage
const chlorineText = await Homey.logic.getVariable({id: id})
//console.log(chlorineText);
const text = chlorineText.value;
const pattern = new RegExp('\\d+[.,]?\\d+','gm');
const matches = text.match(pattern);
//console.log(matches);
if(matches){
const extractedNumbers=matches.map(match=>parseFloat(match));
//console.log(extractedNumbers[0]);
//set variable for Chlorine
await Homey.logic.updateVariable({id: "63e8d16e-30f6-4f0b-9245-11aea5e832af", variable: {value: extractedNumbers[0]}});
}
En mijn script voor het berekenen van de chloor tabletten (hoeveelheid)
const variables = await Homey.logic.getVariables()
//console.log('variables', variables);
const idChlorinePerTablet = "a2a05fe4-2b1e-46ee-b68f-c2c7dc3db9d9" // my ChlorinePerTabletVariable
const idChlorineTabletsNeeded = "d30291ce-2215-474b-9544-61abaf1d42bb" // my ChlorinePerTabletNeededVariable
const idChlorineNeeded = "63e8d16e-30f6-4f0b-9245-11aea5e832af" // my chlorineNeeded (total)
const chlorineNeeded = await Homey.logic.getVariable({id: idChlorineNeeded});
const chlorinePerTabletValue = await Homey.logic.getVariable({id: idChlorinePerTablet});
const chlorineTabletsNeededValue = chlorineNeeded.value / chlorinePerTabletValue.value;
await Homey.logic.updateVariable({id: idChlorineTabletsNeeded, variable: {value: chlorineTabletsNeededValue}})
console.log(chlorineTabletsNeededValue);
Result op het SMPL diplay