# Script to automatically increase the brightness level

**URL:** <https://community.homey.app/t/script-to-automatically-increase-the-brightness-level/94361>\
**Category:** Developers\
**Created:** [November 11, 2023, 7:53pm UTC](https://community.homey.app/t/script-to-automatically-increase-the-brightness-level/94361 "2023-11-11T19:53:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dudu\_95](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dudu_95/32/93061_2.png) [@dudu\_95](https://community.homey.app/u/dudu_95)\
**Post date:** [November 11, 2023, 7:53pm UTC](https://community.homey.app/t/script-to-automatically-increase-the-brightness-level/94361/1 "2023-11-11T19:53:10Z")

</div>

Hello, if you’re interested, I can provide you with a script that turns on a bulb at 0 lux and gradually increases the intensity to 100% every 5 seconds. You can freely adjust the duration between each increment. Personally, I use this script in the morning with a flow: when the time is 7 AM, the script runs, allowing for a gentle wake-up. I use an Ikea bulb where you can choose the color temperature, whether it’s warm or cool. 😀

```auto
// ID de l'ampoule
const ampouleId = "1f674fe-a9e4-4cbb-891-969a9b123d2"; // Please insert the ID of your bulb here.

async function allumerAmpoule() {
    try {
        // Récupérer la référence de l'ampoule en utilisant son ID
        const ampouleChambre = await Homey.devices.getDevice({ id: ampouleId });

        // Affiche l'objet ampouleChambre dans la console
        console.log(ampouleChambre);

        // Vérifier si l'ampoule a été trouvée
        if (ampouleChambre) {
            // Vérifier si la capacité 'onoff' est prise en charge
            if (ampouleChambre.capabilities && ampouleChambre.capabilities.includes('onoff')) {
                // Allumer l'ampoule avec un niveau de lux à 0%
                ampouleChambre.setCapabilityValue('dim', 0);
                ampouleChambre.setCapabilityValue('onoff', true);
                let lux = 0.01;
                while (lux <= 1.01) {
                    await wait(500); // Attendre 0.5 seconde
                    ampouleChambre.setCapabilityValue('dim', lux);
                    console.log(`Niveau de lux actuel : ${Math.round(lux * 100)}%`);
                    lux += 0.01;
                }
                console.log(`fin`);
            } else {
                console.error(`L'ampoule de la chambre ne supporte pas la capacité 'onoff'.`);
            }
        } else {
            console.error(`Ampoule de la chambre introuvable avec l'ID : ${ampouleId}`);
        }
    } catch (error) {
        console.error(`Une erreur s'est produite lors de la récupération de l'ampoule : ${error}`);
    }
}

// Appeler la fonction asynchrone
allumerAmpoule();

```

---

<div class="post-metadata">

**Author:** ![Torch1969](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/torch1969/32/33305_2.png) [@Torch1969](https://community.homey.app/u/Torch1969)\
**Post date:** [November 11, 2023, 9:24pm UTC](https://community.homey.app/t/script-to-automatically-increase-the-brightness-level/94361/2 "2023-11-11T21:24:56Z")

</div>

Hi @dudu_95, thx for sharing this. It’s always nice to look into other persons homeyscript ideas and code to get some inspiration.

Did you know the same can be done with the [chronograph](https://homey.app/nl-nl/app/nl.fellownet.chronograph/Chronograph/) app using a transition? Advantage is that the transition will continue after homey restart. Then you are sure you will wake up, even if the homey restarted just after 7 am 😉😴

---

<div class="post-metadata">

**Author:** ![dudu\_95](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/dudu_95/32/93061_2.png) [@dudu\_95](https://community.homey.app/u/dudu_95)\
**Post date:** [November 12, 2023, 12:52am UTC](https://community.homey.app/t/script-to-automatically-increase-the-brightness-level/94361/3 "2023-11-12T00:52:13Z")

</div>

No, I didn’t know. I will try it. Thank you.
