# Edge Panel - Timer Event Script not running

**URL:** <https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 17, 2024, 4:53pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716 "2024-11-17T16:53:58Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 17, 2024, 4:53pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/1 "2024-11-17T16:53:58Z")

</div>

Hi,

I need to monitor the seconds a boolean is on.

I created a simple script where I increment an int variable by 1 if a boolean is true. I tested in "script console" and saw it´s working.

When I set it in a "timer script" in "gateway events" to run every 1s "shared" or "dedicated" mode, nothing happens with the variable that should being incremented.

I'm using Edge Panel.

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [November 17, 2024, 5:06pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/2 "2024-11-17T17:06:04Z")

</div>

Hi,

Instead of doing this, how about using the `system.tag.queryTagCalculations` method ?

> **[system.tag.queryTagCalculations | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagCalculations)**
>
> Queries various calculations (aggregations) for a set of tags over a specified range.

Use the "DurationOn" calculation.

For more info on available calculations:

> **[Tag History Bindings in Perspective | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/working-with-perspective-components/bindings-in-perspective/tag-history-bindings-in-perspective#aggregation-mode)**
>
> Tag History Binding

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 18, 2024, 6:11am UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/3 "2024-11-18T06:11:20Z")

</div>

Hi,

Thanks for very fast answer.

I've tried to use [system.tag.queryTagCalculations] but it didn´t work even in "script console". So I was wondering if it would work in Edge Panel version, maybe only in normal iginition, Do you know if it does?

Anyway, now I'm intrigued why the script that runs well in "script console" didn´t do it in "timer event - gateway". This is my first time trying to implement it, so I guess I'm doing something wrong. Do I need to enable something in the gateway web interface first?

The case is, I have a script that read and write to tags if I run it in script console. When I put it in a timer event it does nothing with the tags.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 18, 2024, 9:15am UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/4 "2024-11-18T09:15:34Z")

</div>

The problem was I was not saving the project but just hiting apply buttom.  
After save I could see the error in the gateway script status and fix it.

Later i'll try the approach of using system.tag.queryTagCalculations for this task.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 18, 2024, 2:15pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/5 "2024-11-18T14:15:49Z")

</div>

Alternatively, you can add a custom prop to the tag and use the tag's change script to write the timestamp to it when it turns on.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 26, 2024, 8:34pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/6 "2024-11-26T20:34:37Z")

</div>

Thanks amarks, I'll try this also.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 26, 2024, 8:45pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/7 "2024-11-26T20:45:44Z")

</div>

> [@Rodrigo\_Bernardes](#):
>
> "script console" didn´t do it in "timer event - gateway".

Just want to point out that the Script Console runs is Vison Client Scope, and so it sometimes has access to functions that aren't available in Gateway Scope, or vice versa. There are also functions which have different calling signatures depending on which scope you are calling them from.

It is possible to write a script which does what you want in the script console but is not capable of running in Gateway Scope.

The Script Console is just not a good place to test scripts intended for Gateway Scope unless you have take the necessary steps to insure that the script will be executed in the scope it is intended for, weather that be via Message Handler or Third Party Module.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 27, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/8 "2024-11-27T14:32:58Z")

</div>

Hi Irose, thank you for the reply.

This is exactly the problem I'm having now again.

I'm using the function system.tag.queryTagHistory to calculate the totals produced by hour from a totalizer signal coming from a weight meter.

So it works perfectly in Scrip Console, but when I put it in Scheduled Gateway Event, the dataset returned comes with "null" in the value I need.

But if we look at the documentation of the function, it says it is gateway scope also.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 27, 2024, 2:34pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/9 "2024-11-27T14:34:32Z")

</div>

You'll need to show your script, there may be something else that is bungling things up.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 27, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/10 "2024-11-27T14:52:43Z")

</div>

Sure, here it is:

def onScheduledEvent():

```
import datetime
data = datetime.datetime.now()
data_formatada = data.strftime("%d/%m/%Y %H:%M:%S")
Path_Hora_Atual = data.strftime("[edge]Plant/Y%Y/%m/%d/%H")	
endTime = system.date.now()
startTime = system.date.addMinutes(endTime, -60)	
dataSet = system.tag.queryTagHistory(paths=['WIT-001/Total_Global'], startDate=startTime, endDate=endTime, returnSize=1, aggregationMode="Range", returnFormat='Wide')
Total_Hora_Atual = dataSet.getValueAt(0,1)
system.tag.writeBlocking([Path_Hora_Atual], [Total_Hora_Atual])

```

onScheduledEvent()

So the value I need is supposed to be here, but it returns null  
Total\_Hora\_Atual = dataSet.getValueAt(0,1)

As I said, if I put it in Console it works and I see the tag I need changing properly.  
Another information is that the script runs normally, but returns null.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/7/8734dfde9da82f6d6b7a461990ab0cfa9973a60d.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [November 27, 2024, 3:24pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/11 "2024-11-27T15:24:31Z")

</div>

> [@Rodrigo\_Bernardes](#):
>
> I'm using the function system.tag.queryTagHistory to calculate the totals produced by hour from a totalizer signal coming from a weight meter.

But you're script isn't doing that, it is calculating the the range for the _last_ hour. Perhaps that's what you intend, perhaps not.

I agree, I do not see anything in the script that should not run the same way in Gateway Scope. I believe the only way you would get a null value is if there is only a single value in the time frame, but I am not entirely certain of that fact.

I have simplified the script to avoid the import (there is never a need to use the 'datetime' module, the `system.date.*` functions provide all the same functionality), and also to use only the necessary non-default parameters to the `system.tag.queryTagHistory()` function.

```python
Path_Hora_Atual = system.date.format(system.date.now(),"'[edge]Plant/Y'yyyy/MM/dd/HH")
data = system.tag.queryTagHistory(['WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)
Total_Hora_Atual = data.getValueAt(0,1)
system.tag.writeBlocking([Path_Hora_Atual],[Total_Hora_Atual])

```

Try that and see if it yields any different results (in theory it will be exactly the same).

I am interested in how and why you are generating tags by hour, that seems like something that is being done in a sub-optimal way IMO.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 27, 2024, 5:47pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/12 "2024-11-27T17:47:22Z")

</div>

Irose, thanks for the code sugestion.

I updated the scheduled script with it, but result was the same as expected.

One intriguing thing I realized is that when I press "Apply" button in the gateway event scripts window, the script executes, and correctly. So, a few seconds after, running as per the schedule, it brings NULL value.

Well, about the "tags per hour" for now this was the way I found to store data, as I´m using Ignition Edge and it´s supposed not to have databases.

---

<div class="post-metadata">

**Author:** ![Samuel\_Sueur](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@Samuel\_Sueur](https://forum.inductiveautomation.com/u/Samuel_Sueur)\
**Post date:** [November 27, 2024, 7:51pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/13 "2024-11-27T19:51:00Z")

</div>

Can you log the value in the wrapper.log using the `system.util.getLogger()` function?

> [@Rodrigo\_Bernardes](#):
>
> One intriguing thing I realized is that when I press "Apply" button in the gateway event scripts window, the script executes, and correctly. So, a few seconds after, running as per the schedule, it brings NULL value.

I'm not sure I understand this correctly. Do you mean that the tag value is NULL? Because your script obviously isn't returning anything, just writing to a tag at the end.

Using Louis's script, I've added the system.util.getLogger part.

```python
Path_Hora_Atual = system.date.format(system.date.now(),"'[edge]Plant/Y'yyyy/MM/dd/HH")
data = system.tag.queryTagHistory(['WIT-001/Total_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)
Total_Hora_Atual = data.getValueAt(0,1)
system.util.getLogger("ScheduledEventValue").info(Total_Hora_Atual)
system.tag.writeBlocking([Path_Hora_Atual],[Total_Hora_Atual])

```

Once this runs, check the "logs" section in the gateway and see whether the value is equal to null or not.

---

<div class="post-metadata">

**Author:** ![Rodrigo\_Bernardes](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rodrigo\_Bernardes](https://forum.inductiveautomation.com/u/Rodrigo_Bernardes)\
**Post date:** [November 27, 2024, 8:12pm UTC](https://forum.inductiveautomation.com/t/edge-panel-timer-event-script-not-running/98716/14 "2024-11-27T20:12:57Z")

</div>

Hi,

I found the error, in a reply of our colegue @pturmel  
I was just put the provider [edge] when calling the function

**wrong way**  
data = system.tag.queryTagHistory(['WIT-001/Total\_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)

**right way**  
data = system.tag.queryTagHistory(['[edge]WIT-001/Total\_Global'],returnSize = 1, aggregationMode = 'Range',rangeHours = 1)

Thanks everyone.
