# HomeyScript issue

**URL:** <https://community.homey.app/t/homeyscript-issue/123264>\
**Category:** Apps\
**Tags:** homeyscript\
**Created:** [December 8, 2024, 7:18pm UTC](https://community.homey.app/t/homeyscript-issue/123264 "2024-12-08T19:18:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 7:18pm UTC](https://community.homey.app/t/homeyscript-issue/123264/1 "2024-12-08T19:18:47Z")

</div>

I’m having problems with flow tags when created with HomeyScript.

currently I have 2 homeyScripts that both work fine when running from tests.  
From 1 script the output flow tags are available for selection.  
From script 2 the output flow tag does not show up.

The syntax for setting the tag is the same in each script.

Diagnostic report:  
9fe37241-b3e0-4b41-beee-de16804596fe

---

<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:** [December 8, 2024, 7:22pm UTC](https://community.homey.app/t/homeyscript-issue/123264/2 "2024-12-08T19:22:53Z")

</div>

> [@Sander\_Muurmans](#):
>
> From script 2 the output flow tag does not show up.

Can you share the error message?  
~~What flow tag do~~  
Can you share the script, please?

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 7:33pm UTC](https://community.homey.app/t/homeyscript-issue/123264/3 "2024-12-08T19:33:32Z")

</div>

Here is the entire script:

```auto
// Helper function to convert "mm:ss.SSS" to total seconds as a float
function parseTimeToSeconds(timeString) {
    if (!timeString) return null;
    const [minutes, seconds] = timeString.split(':');
    return parseInt(minutes) * 60 + parseFloat(seconds);
}

const apiuri = 'https://ergast.com/api/f1/current/next/qualifying.json'
const response = await fetch('https://ergast.com/api/f1/current/24/qualifying.json');
const data = await response.json();

// Check if the qualifying data exists
if (!data.MRData || !data.MRData.RaceTable || !data.MRData.RaceTable.Races[0]) {
    console.log('No qualifying data available.');
    return;
}

const qualifyingResults = data.MRData.RaceTable.Races[0].QualifyingResults;

if (!qualifyingResults || qualifyingResults.length === 0) {
     console.log('No qualifying results found.');
     return;
}

// Extract times from Q1, Q2, and Q3 for the first position
const firstPositionTimes = qualifyingResults[0];
const firstQ1Time = parseTimeToSeconds(firstPositionTimes.Q1);
const firstQ2Time = firstPositionTimes.Q2 ? parseTimeToSeconds(firstPositionTimes.Q2) : null;
const firstQ3Time = firstPositionTimes.Q3 ? parseTimeToSeconds(firstPositionTimes.Q3) : null;
const maxNameLength = Math.max(...qualifyingResults.map(q => q.Driver.familyName.length + q.Driver.givenNamelength));
//console.log(maxNameLength);

// Generate formatted output for each position
const outputLines = qualifyingResults.map(result => {
    const position = result.position.padEnd(2, ' ');
    const driverNumber = result.Driver.permanentNumber.padStart(2, ' ');
    const driverName = `${result.Driver.givenName} ${result.Driver.familyName} [${driverNumber}]`.padEnd(maxNameLength + 6,' ');

    // Parse Q1, Q2, Q3 times
    const q1Time = parseTimeToSeconds(result.Q1);
    const q2Time = result.Q2 ? parseTimeToSeconds(result.Q2) : null;
    const q3Time = result.Q3 ? parseTimeToSeconds(result.Q3) : null;

    // Calculate differences from P1 times
    const q1Difference = firstQ1Time !== null && q1Time !== null ? (q1Time - firstQ3Time).toFixed(3) : 999;
    const q2Difference = firstQ2Time !== null && q2Time !== null ? (q2Time - firstQ3Time).toFixed(3) : 999;
    const q3Difference = firstQ3Time !== null && q3Time !== null ? (q3Time - firstQ3Time).toFixed(3) : 999;
    const qFastestDifference = Math.min(q1Difference,q2Difference,q3Difference).toFixed(3);

    // Return formatted string
    return `P${position} : ${driverName} + ${qFastestDifference}s`;
});

let outputValue = String(outputLines.join('\n'));
//console.log(outputValue);
await tag('QualifyingResults', outputValue);

return outputValue;

```

There is no error message. The flow tag ‘QualifyingResults’ is simply not created / available for selection.

---

<div class="post-metadata">

**Author:** ![Caseda](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/caseda/32/138695_2.png) [@Caseda](https://community.homey.app/u/Caseda)\
**Post date:** [December 8, 2024, 7:51pm UTC](https://community.homey.app/t/homeyscript-issue/123264/4 "2024-12-08T19:51:41Z")

</div>

It gets created here just fine under the “HomeyScript” tags (you are probably just looking at the wrong spot for your variable):

> P1 : Lando Norris [4] + 0.000s  
> P2 : Oscar Piastri [81] + 0.209s  
> P3 : Carlos Sainz [55] + 0.229s  
> P4 : Nico Hülkenberg [27] + 0.291s  
> P5 : Max Verstappen [33] + 0.350s  
> P6 : Pierre Gasly [10] + 0.389s  
> P7 : George Russell [63] + 0.537s  
> P8 : Fernando Alonso [14] + 0.601s  
> P9 : Valtteri Bottas [77] + 0.609s  
> P10 : Sergio Pérez [11] + 0.669s  
> P11 : Yuki Tsunoda [22] + 0.824s  
> P12 : Liam Lawson [30] + 0.877s  
> P13 : Lance Stroll [18] + 1.134s  
> P14 : Charles Leclerc [16] + 0.707s  
> P15 : Kevin Magnussen [20] + 1.037s  
> P16 : Alexander Albon [23] + 1.226s  
> P17 : Guanyu Zhou [24] + 1.285s  
> P18 : Lewis Hamilton [44] + 1.292s  
> P19 : Franco Colapinto [43] + 1.317s  
> P20 : Jack Doohan [61] + 1.510s

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 7:57pm UTC](https://community.homey.app/t/homeyscript-issue/123264/5 "2024-12-08T19:57:23Z")

</div>

Unfortunately I am certain that I am looking at the correct spot, since variables from another script DID show up there. Only the one from this script (which works as you’ve demonstrated), does not show up.

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

---

<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:** [December 8, 2024, 8:09pm UTC](https://community.homey.app/t/homeyscript-issue/123264/6 "2024-12-08T20:09:18Z")

</div>

When you didn’t already: The script has to run at least once before the tag is selectable from the flow.

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 8:11pm UTC](https://community.homey.app/t/homeyscript-issue/123264/7 "2024-12-08T20:11:18Z")

</div>

I’ve ran it from test mode, from an advanced flow, and from a basic flow. All of them at least 10 times when trying to debug this issue ☹

The script works every time, but it never results in a flow tag becoming available.

---

<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:** [December 8, 2024, 8:25pm UTC](https://community.homey.app/t/homeyscript-issue/123264/8 "2024-12-08T20:25:09Z")

</div>

It works:

 ![1000000099](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/2/d2a3a90e877fee84e4b05762979abb85115b217e.jpeg)

 ![1000000101](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/a/dab58f1d708100a53231d962468e28332e82d19c.jpeg)

Try emptying browser cache and force reload the my.homey.app page

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 8:38pm UTC](https://community.homey.app/t/homeyscript-issue/123264/9 "2024-12-08T20:38:14Z")

</div>

Thanks for the tip, did not try that yet and seems like a plausible cause.

Just tried opening the site with ‘InPrivate’ mode, so no browser cache at all. Unfortunately, same result ☹

Also I tried completely rebooting the Homey. Also did not change the outcome.

---

<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:** [December 8, 2024, 9:45pm UTC](https://community.homey.app/t/homeyscript-issue/123264/10 "2024-12-08T21:45:38Z")

</div>

Hmmm, that’s really odd.  
I’m on Homey 2019, dunno if that’s related?

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 8, 2024, 9:57pm UTC](https://community.homey.app/t/homeyscript-issue/123264/11 "2024-12-08T21:57:19Z")

</div>

I’m on the early 2023 version, but I doubt that it matters.

I did notice you are using a Homey Code activity instead of the Homey Script activity. I expect the behaviour to be slightly different between those two. Anyways, I tried Homey Code aswell and this also does not work for me.

---

<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:** [December 8, 2024, 10:12pm UTC](https://community.homey.app/t/homeyscript-issue/123264/12 "2024-12-08T22:12:05Z")

</div>

Idea: Try to delete the tag (even if you think it don’t exist):

```auto
await tag('QualifyingResults', null);

```

Maybe after this it gets created as should when you run the script?

---

<div class="post-metadata">

**Author:** ![Sander\_Muurmans](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_muurmans/32/109670_2.png) [@Sander\_Muurmans](https://community.homey.app/u/Sander_Muurmans)\
**Post date:** [December 9, 2024, 8:32pm UTC](https://community.homey.app/t/homeyscript-issue/123264/13 "2024-12-09T20:32:37Z")

</div>

I find it hard to believe, but your suggestion actually solved the issue!!!

---

<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:** [December 9, 2024, 8:44pm UTC](https://community.homey.app/t/homeyscript-issue/123264/14 "2024-12-09T20:44:13Z")

</div>

Nice to hear! I’m going to buy a “staatslot” now.

Why is it hard to believe? I just seem to have good ideas every now and then 🤣🤪😬

This particular issue made me think about bitrot.
