# Gateway Script Not Triggering

**URL:** <https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [April 10, 2024, 11:03pm UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671 "2024-04-10T23:03:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Crawford](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ryan\_Crawford](https://forum.inductiveautomation.com/u/Ryan_Crawford)\
**Post date:** [April 10, 2024, 11:03pm UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/1 "2024-04-10T23:03:30Z")

</div>

Good Afternoon,

I have a script where I would like it to generate a random number then pass it into a variable. However I am find that the tag is not updating.

I would like this to run under a timer (every 1 second) but I am not having any luck with this.

I do have other scripts running with tigger from timers and triggered from a tag change, and this works correctly when I put it in the script console.

```auto
import random

# Function to generate random consumption values for power meters
def generate_consumption():
    print("Generating random consumption value...")
    return random.randint(100, 500) # Random value between 100 and 500 kWh

# Generate random consumption values for power meters
print("Generating consumption values for power meters...")
meter1_consumption = generate_consumption()
print("Meter 1 consumption:", meter1_consumption)

# Write the generated values to corresponding tags
print("Writing generated values to tags...")
system.tag.write("[default]tagpath", meter1_consumption)

# Call the function to update power meters once
# update_power_meters()

```

Any suggestionswould be great.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 10, 2024, 11:07pm UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/2 "2024-04-10T23:07:34Z")

</div>

Is `system.tag.write` depreciated?

> **[system.tag.writeBlocking | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-writeBlocking)**
>
> Writes values to tags at the given paths.

Also, you should get in the habit of supplying the tag paths and values as lists (in `[]`).

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 10, 2024, 11:23pm UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/3 "2024-04-10T23:23:44Z")

</div>

> [@Transistor](#):
>
> depreciated

I'm sure it's still appreciated, especially by upgraders. 😆

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 10, 2024, 11:38pm UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/4 "2024-04-10T23:38:30Z")

</div>

> [@Ryan\_Crawford](#):
>
> I would like this to run under a timer (every 1 second) but I am not having any luck with this.

Can you share a screenshot of how you've got the timer script set up? Any errors in the gateway console? If you add logging statements with `system.util.getLogger`, are you seeing those output to confirm your script is actually running? Have you saved the project (gotta ask 😄)?

---

<div class="post-metadata">

**Author:** ![Ryan\_Crawford](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ryan\_Crawford](https://forum.inductiveautomation.com/u/Ryan_Crawford)\
**Post date:** [April 11, 2024, 1:46am UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/5 "2024-04-11T01:46:25Z")

</div>

> [@paul-griffith](#):
>
> system.util.getLogger

Thanks for the resposne peter!

haha fair question, yes I have saved it... multiple times. And I cant see any errors in the consol output.

 ![CFKTN18p1O](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3b3631aec9cdc7f785387db1c7a8f46a6c7759c9.jpeg)  
 ![ysu1xfUZ7s](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/69315ff7d423fc6ce9e7e3b758dc8d4dfa3efbe5.jpeg)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 11, 2024, 1:57am UTC](https://forum.inductiveautomation.com/t/gateway-script-not-triggering/88671/6 "2024-04-11T01:57:23Z")

</div>

> [@Ryan\_Crawford](#):
>
> And I cant see any errors in the consol output.

The errors won't be in the console. They will be in the gateway logs. Gateway events run in the gateway.
