# Created a script, tested and works. Can't make it work with a flow

**URL:** <https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607>\
**Category:** Questions & Help\
**Tags:** homeyscript, flow\
**Created:** [April 28, 2025, 2:25pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607 "2025-04-28T14:25:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 2:25pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/1 "2025-04-28T14:25:08Z")

</div>

I made a script to make my shutters go down when a certain °C is reached and also when a certain lux level is reached. When I test the script, it works but when I want to create an automated flow nothing happens.  
How can I solve this?

thx

---

<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:** [April 28, 2025, 2:40pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/2 "2025-04-28T14:40:20Z")

</div>

We can’t read your mind yet 😬☺  
Please share script, flow and error message(s), thanks.

Hint, in advanced flow you can run code right from a Homeyscript “Then” card: “Run `code` …”

 ![1000047124](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/7/2781a47d9f27399a155ce833fd15fda40a65bd87.jpeg)

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 2:43pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/3 "2025-04-28T14:43:40Z")

</div>

The script:

```auto
// 🛠️ Tes appareils (noms réels Homey)
const idHueMotionSensor = '13d9a1d7-01a5-4ff2-82ba-6ff85fa586af'; // ID exact du capteur extérieur
const idVoletSalleDeBain = 'fc90b0ab-4674-4552-baa3-d403d2c330df'; // L'ID exact du volet salle de bain
const idVoletCuisineStudio = 'daae4439-8355-41ac-8caa-61afc367762b'; // ID exact du volet Cuisine Studio
const idVoletChambreStudio = 'c1eb7824-2b03-43e5-9e0f-c7dfdaba4688'; // L'ID exact du volet Chambre Studio
const idVoletRez = '89753380-58e2-420b-a173-97cac92b1765'; // ID exact du volet salon rez-de-chaussée

async function main() {
  // Récupération des appareils
  const devices = await Homey.devices.getDevices();
  
  const sensor = Object.values(devices).find(device => device.id === idHueMotionSensor);
  const voletSalleDeBain = Object.values(devices).find(device => device.id === idVoletSalleDeBain);
  const voletCuisineStudio = Object.values(devices).find(device => device.id === idVoletCuisineStudio);
  const voletChambreStudio = Object.values(devices).find(device => device.id === idVoletChambreStudio);
  const voletRez = Object.values(devices).find(device => device.id === idVoletRez);

  if (!sensor) {
    console.log('❌ Capteur extérieur non trouvé.');
    return;
  }

  // Lecture des valeurs
  const temperature = sensor.capabilitiesObj['measure_temperature'].value;
  const luminance = sensor.capabilitiesObj['measure_luminance'].value;

  // Lecture de la date actuelle
  const now = new Date();
  const mois = now.getMonth() + 1;
  const jour = now.getDate();

  console.log(`Température actuelle : ${temperature}°C`);
  console.log(`Luminosité actuelle : ${luminance} lux`);
  console.log(`Date actuelle : ${jour}/${mois}`);

  // Vérification de la période (entre 1er avril et 20 septembre)
  const estDansPeriode = 
    (mois > 4 && mois < 9) || 
    (mois === 4 && jour >= 1) || 
    (mois === 9 && jour <= 20);

  // Conditions (temp > 25°C et lux > 30000 et période correcte)
  if (temperature > 25 && luminance > 30000 && estDansPeriode) {
    console.log('Conditions OK, fermeture des volets...');

    // Fermer les volets existants uniquement
    if (voletSalleDeBain) {
      await voletSalleDeBain.setCapabilityValue('windowcoverings_state', 'down');
    } else {
      console.log('⚠️ Volet salle de bain non trouvé.');
    }

    if (voletCuisineStudio) {
      await voletCuisineStudio.setCapabilityValue('windowcoverings_state', 'down');
    } else {
      console.log('⚠️ Volet Cuisine Studio non trouvé.');
    }

    if (voletChambreStudio) {
      await voletChambreStudio.setCapabilityValue('windowcoverings_state', 'down');
    } else {
      console.log('⚠️ Volet Chambre Studio non trouvé.');
    }

    if (voletRez) {
      await voletRez.setCapabilityValue('windowcoverings_state', 'down');
    } else {
      console.log('⚠️ Volet salon rez-de-chaussée non trouvé.');
    }

  } else {
    console.log('Conditions non remplies, aucune action.');
  }
}

// Exécution
main().catch(console.error);

```

Flow:

 ![Screenshot 2025-04-28 at 16-42-50 Homey Pro de Harold](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/d/ad6cff6f62518bef800a8745cf5d0856be723985.png)

For the flow I don’t have an error it just won’t automatically start

Thx

---

<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:** [April 28, 2025, 2:47pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/4 "2025-04-28T14:47:31Z")

</div>

The trigger card only triggers once, when the temp was below 25° and then became greater than 25.  
Just like how a thermostat functions.

When it’s already over 25°, and the temperature rises, it will never trigger.

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 2:50pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/5 "2025-04-28T14:50:11Z")

</div>

Oh ok and is there a way to trigger it again at a higher temperature if the lux hasn’t been reached but reached once it’s 26°C? Or do I create a new script and flow? Thx

---

<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:** [April 28, 2025, 2:53pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/6 "2025-04-28T14:53:17Z")

</div>

Yes, add another flow with  
When..  
Lux became greater than X  
And..  
logic card [temperature] is greater than 25  
Then..

A bit like this logic card, you can just enter `25` into the second field:

 ![1000047126](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/4/0454781b78adc7dabab07b79579967807fa6c241.jpeg)

Do you know how to find and insert a tag from a sensor?

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 2:59pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/7 "2025-04-28T14:59:47Z")

</div>

No didn’t look it up yet. Thx for your help!

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 3:04pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/8 "2025-04-28T15:04:10Z")

</div>

![Screenshot 2025-04-28 at 17-03-37 Homey Pro de Harold](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/c/9ca90d2a6b4a4d9e0a0c7b736cc42aad475f1f49.png)

Does this looks like it?

---

<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:** [April 28, 2025, 3:10pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/9 "2025-04-28T15:10:27Z")

</div>

Yes.  
You can add notification cards at Then and Else, to be able to see what happens. You can add the lux and temperature tags f.i., and the flow name.

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [April 28, 2025, 3:11pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/10 "2025-04-28T15:11:12Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![tomasko](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tomasko/32/79143_2.png) [@tomasko](https://community.homey.app/u/tomasko)\
**Post date:** [May 5, 2025, 3:44pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/11 "2025-05-05T15:44:02Z")

</div>

@Har_Dou for your future projects you may consider using triggers like this:  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/b/4b920af11d154106c49dac8a5607ec52748c25e1.png)  
with this trigger flow is started every time your sensors updates value (of luminance in my case), but keep in mind it might be too often to run the whole flow (depends on frequency of your sensor synchronization), so you can add simple logic to continue flow only in valid scenarios, like this:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/2/82c8db73a7a19c5a73a49d3e590a3e333b6cc839.png)  
so you will not run your code every time your sensor updates but only if relevant… hope it helps for your future automations 😉

---

<div class="post-metadata">

**Author:** ![Har\_Dou](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/har_dou/32/120716_2.png) [@Har\_Dou](https://community.homey.app/u/Har_Dou)\
**Post date:** [May 8, 2025, 1:28pm UTC](https://community.homey.app/t/created-a-script-tested-and-works-cant-make-it-work-with-a-flow/135607/12 "2025-05-08T13:28:22Z")

</div>

thx will try it
