# Calculate X number of Events in a 24hr period

**URL:** <https://forums.losant.com/t/calculate-x-number-of-events-in-a-24hr-period/4398>\
**Category:** Help\
**Tags:** dashboard, workflow\
**Created:** [March 9, 2022, 7:37pm UTC](https://forums.losant.com/t/calculate-x-number-of-events-in-a-24hr-period/4398 "2022-03-09T19:37:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Cruz](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/jose_cruz/32/1580_2.png) [@Jose\_Cruz](https://forums.losant.com/u/Jose_Cruz)\
**Post date:** [March 9, 2022, 7:37pm UTC](https://forums.losant.com/t/calculate-x-number-of-events-in-a-24hr-period/4398/1 "2022-03-09T19:37:23Z")

</div>

Greetings. Was looking around the forums, but was able to find only 1 conversation back in 2019 close to my question, but not clear still. So, here it goes…

Trying to figure out the best and most logical way to calculate the number of times an event triggers from a sensor (say, **ON** msgs/payloads) within a day.

So, for example, I have a device that alerts **ON** about **25 times a day** (almost exactly _once every hour_, with a bit more…). I can graph that **ON/OFF** in a 24hr dash graph, but would also like to **add a saved value** of whatever that ON event triggered (which I have a separate numeric _attribute_ for) and come up with a **total after 24 hrs** (call it `24hr_metric_value` for example), so I can, also, display the `24hr_metric_value` with an indicator dash block . Makes sense?

I’m thinking `data/time` node with some logic, counters, maybe `latch` node as well, etc but would like your opinion first before delving into it. As always, thx 🔴

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [March 9, 2022, 7:58pm UTC](https://forums.losant.com/t/calculate-x-number-of-events-in-a-24hr-period/4398/2 "2022-03-09T19:58:31Z")

</div>

If the ON/OFF value is stored on the device as an attribute, I think you may be able to get what you’re after using the [Time At Value](https://docs.losant.com/references/aggregations/#time-at-value) data aggregation method. So, given a duration of 24 hours, run a gauge query with a “Time At Value” aggregation method targeting the value of “ON”. What you’ll get back is the time, in milliseconds, that the value of that particular attribute was “ON” over that 24-hour period.

Let me know if I’m off-base with what you’re after, and if so, I’ll see if I can come up with another suggestion.

---

<div class="post-metadata">

**Author:** ![Jose\_Cruz](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/jose_cruz/32/1580_2.png) [@Jose\_Cruz](https://forums.losant.com/u/Jose_Cruz)\
**Post date:** [March 9, 2022, 8:22pm UTC](https://forums.losant.com/t/calculate-x-number-of-events-in-a-24hr-period/4398/3 "2022-03-09T20:22:09Z")

</div>

@Dylan_Schuster , thank you - yes, the ON/OFF value is stored on the device as an attributed. Let me ‘play’ with this a bit and I’ll let you know if it works/not/get stucked for more info, 🔴
