# Posible to update a timer period in Edge Action?

**URL:** <https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810>\
**Category:** Octave\
**Created:** [May 21, 2023, 8:51pm UTC](https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810 "2023-05-21T20:51:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpinc](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dpinc](https://forum.sierrawireless.com/u/dpinc)\
**Post date:** [May 21, 2023, 8:51pm UTC](https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810/1 "2023-05-21T20:51:07Z")

</div>

I have a use case that requires the ability to set a timer duration (period) dynamically.  
Using a virtual resource would be ideal.

I need to be able to update the timer duration (period) in an edge action.

The particular test is to set a value for ULPM “up time” duration – i.e. how long  
the device should stay “awake” between ULPM sessions.

I have a test working with a timer duration (period) specified in the timer resource, but  
I need to be able to read this value from a VR and update the ulpm\_up\_timer period with the new value in an EA.

I cant see how to accomplish this. Two timers are currently in use:  
_bootup\_timer_  
_ulpm\_up\_timer_

So the timer config looks like:

```auto
timer
   config <output> = {"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}} (ts: 1684700154.699300)
         data type = JSON (e.g., '{"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}}')
         default = JSON: {"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}}

```

Is it possible to update ulpm\_up\_timer “period” to new value in edge action?

Many Thanks!

---

<div class="post-metadata">

**Author:** ![njoyeux](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/njoyeux/32/6714_2.png) [@njoyeux](https://forum.sierrawireless.com/u/njoyeux)\
**Post date:** [May 22, 2023, 8:00am UTC](https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810/2 "2023-05-22T08:00:39Z")

</div>

Hi @dpinc  
You can achieve this by writing the timer configuration with an edge action.  
Something like this should do the trick:

```auto
var my_new_period = 100
var timer_config = {bootup_timer:{period:1,repeat:1,autostart:true},ulpm_up_timer:{period: my_new_period, repeat:1,autostart:false}}
return {
		  "dh://timer/config": [timer_config]
	  }

```

HTH,  
Nicolas

---

<div class="post-metadata">

**Author:** ![dpinc](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dpinc](https://forum.sierrawireless.com/u/dpinc)\
**Post date:** [May 23, 2023, 2:33am UTC](https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810/3 "2023-05-23T02:33:39Z")

</div>

Thanks! This works, but for some reason the module reboots when the timer config is updated. I took care to verify that the correct element in the correct timer is updated. For testing I backed up the original timer config to a VR. You can see that ulpm\_up\_timer period was updated from 302 to 401 – see below:

Original timer config (save as BU to VR):

```auto
root@swi-mdm9x28-wp:~# dhub list /app/virtual/timer_config_BU
timer_config_BU
   value <input> = {"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":302,"repeat":1,"autostart":false}} (ts: 1684808396.425500)
         data type = JSON (e.g., '{"value":{"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}},"timestamp":1684800859.49399}')
         default = JSON: {"value":{"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}},"timestamp":1684800859.49399}
root@swi-mdm9x28-wp:~#

```

Updated timer config (as applied)

```auto
root@swi-mdm9x28-wp:~# dhub list /app/timer/config
config <output> = {"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":401,"repeat":1,"autostart":false}} (ts: 1684808396.407007)
      data type = JSON (e.g., '{"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}}')
      default = JSON: {"bootup_timer":{"period":1,"repeat":1,"autostart":true},"ulpm_up_timer":{"period":300,"repeat":1,"autostart":false}}
root@swi-mdm9x28-wp:~#

```

I think I would be in good shape if I can keep it from rebooting upon timer config update. Thanks for your support!

---

<div class="post-metadata">

**Author:** ![dpinc](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dpinc](https://forum.sierrawireless.com/u/dpinc)\
**Post date:** [May 28, 2023, 9:41pm UTC](https://forum.sierrawireless.com/t/posible-to-update-a-timer-period-in-edge-action/29810/4 "2023-05-28T21:41:03Z")

</div>

It seems updating timer config causes many undesirable behaviors with any other timers, observations, and actions. The timer config update suggested was successful, but the device state appears to be reset with unpredictable results.

For anyone with a similar need to set / vary a timer duration dynamically, (which does not appear to be supported by the platform) a solution that worked for my case was to set the timer duration (period) at some small duration, i.e. one minute. A Virtual Resource was used to specify a duration “multiplier”. This value was read at each timer expire. The desired timer expiry action is only executed when the timer count (i.e. the number of times the timer expires) reaches or exceeds the Virtual Resource duration multiplier value. While not as efficient as updating the duration directly, this is the next best solution found.
