I have some code in order to recognize if a myStrom-Switch has a load < 2 W:
async function checkPowerGreaterThanOne() {
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
try {
const response = await fetch("http://172.16.1.50/report", requestOptions);
const result = await response.json();
// Check if "power" is less than 2.0
if (result.power < 2.0) {
console.log("Power is less than 2.0: " + result.power);
return true;
} else {
console.log("Power is greater than 2.0: " + result.power);
return false;
}
} catch (error) {
console.log('error', error);
throw error;
}
}
// Call the function and handle the asynchronous response if needed
checkPowerGreaterThanOne()
.then(result => {
// Use the result here
console.log("Result:", result);
})
.catch(error => {
// Handle errors if necessary
console.error("Error:", error);
});
This code runs correct and returns true or false. But when I run the code in the flow-card, always the “no” output is selected – can anybody help me?