Hello all,
I have been struggling for 6 hours straight now, and I still don’t have it working, so this is my call for help
What I’m trying to build:
I have a homeyscript that connects to a datalogger. The datalogger gives a json reply and I’m filtering a specific sensor for temperature out of the json output.
This homeyscript will be launched every 5 minutes to update the temperature in a variable called “temperature”.
I want to use this variable “temperature” in a flow, where I want to measure if this variable is above or below 70 degrees using a logic card.
If yes action A, if no action B.
I have been successful in writing the homeyscript to grab the temperature from the datalogger. This is the code I made:
try {
const res = await fetch('https://datalogger/dlx/download/live?');
if (!res.ok) throw new Error(`HTTP error! Status: ${res.status}`);
const json = await res.json();
const rawTemp = json?.headersets?.[0]?.packets?.[0]?.field_values?.[2]?.value;
if (rawTemp === undefined) throw new Error('Temperature value not found');
const temperature = Number(rawTemp);
log(`Temperature Sensor 3 reading: ${temperature} °C`);
if (!isNaN(temperature) && temperature < 100) {
global.set('temperature', rawTemp);
log(`Temperature Variable set on: ${temperature} °C`);
return temperature;
} else {
return 'Invalid temperature value';
}
} catch (err) {
log(`Error: ${err.message}`);
return `Error: ${err.message}`;
}
The output when I run the script:
Temperature Sensor 3 reading: 73.8 °C
Temperature Variable set on: 73.8 °C
Script Success
Returned: 73.8
I created the variable “temperature” as a number in the screen of the flows.
The flow is extremely simple:
But as you can see the logic is saying the temperature is not greater than 50 despite the fact that the variable and script is saying 73.8
What am I doing wrong?
Thanks!