# Use variable from script in a flow, I fail miserably

**URL:** <https://community.homey.app/t/use-variable-from-script-in-a-flow-i-fail-miserably/138350>\
**Category:** Questions & Help\
**Created:** [June 18, 2025, 6:38pm UTC](https://community.homey.app/t/use-variable-from-script-in-a-flow-i-fail-miserably/138350 "2025-06-18T18:38:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rendier](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rendier/32/93913_2.png) [@Rendier](https://community.homey.app/u/Rendier)\
**Post date:** [June 18, 2025, 6:38pm UTC](https://community.homey.app/t/use-variable-from-script-in-a-flow-i-fail-miserably/138350/1 "2025-06-18T18:38:59Z")

</div>

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:

```auto
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:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/d/fd36751a128116098d0c9a5874848ceab832be6d.png)

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!

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [June 18, 2025, 7:21pm UTC](https://community.homey.app/t/use-variable-from-script-in-a-flow-i-fail-miserably/138350/2 "2025-06-18T19:21:09Z")

</div>

The second log line shows the value of the same constance `temperature`, that’s why you see two identical values

I also would refrain from using the same name _temperature_ for different things;  
example:

```auto
const rawTemp = json?.headersets?.[0]?.packets?.[0]?.field_values?.[2]?.value;
rawTemp = Number(rawTemp);
global.set('Temperature_hs', rawTemp);

```

> [@Rendier](#):
>
> ```auto
> global.set('temperature', rawTemp);
> log(`Temperature Variable set on: ${temperature} °C`);
> 
> ```

To retrieve and view the ‘temperature’ tag in the console, you’d use `global.get`, as shown in the Homeyscript example scripts

To know what’s going on, and view it’s value: add a timeline card f.i., and add that tag [temperature] to it.

And please format your code as code  
(add ``` above and below your script).  
Now there’s _ **fancy quotes** _ in it, that never works in scripts
