# Inputing data in to different gauges on for each day of the week

**URL:** <https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704>\
**Category:** Dashboard\
**Created:** [4 September 2024 11:59 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704 "2024-09-04T11:59:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xfear1](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xfear1](https://discourse.nodered.org/u/xfear1)\
**Post date:** [4 September 2024 11:59 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/1 "2024-09-04T11:59:31Z")

</div>

Hi,  
I have a problem that need some solving, I am collecting data from a PLC via Modbus, each pulse adds to my counter this information is reset everyday in my PLC, how can I save this data for each gauge with a condition that is the right day of the week.  
If today is sunday all the other gauges are frozen with the last value saved and only the right day can add value. I know how to reset everything in the end of the week, but not the rest of the problem.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 September 2024 13:03 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/2 "2024-09-04T13:03:22Z")

</div>

Save your counts as an array of 7 elements. You can use a context variable for this.

A function node like this should work to maintain the counts

```auto
const day = new Date().getDay() // sunday - 0, saturday = 6
let daycounts = context.get("daycounts") || [0,0,0,0,0,0,0] // Hold counters as an array
daycounts[day] ++ // Increment today's counter
context.set("daycounts", daycounts) // save it
msg.payload = daycounts
return msg;

```

And a node-red-dashboard gauge can be set to display eg Wednesday's count like this

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac11c4cc99684afcace941412e5146f49949c74d.png)

---

<div class="post-metadata">

**Author:** ![xfear1](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xfear1](https://discourse.nodered.org/u/xfear1)\
**Post date:** [4 September 2024 14:14 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/3 "2024-09-04T14:14:11Z")

</div>

Hello,  
I did how you told me but it is increasing the value every modbus pulse.  
Is there a way to send the value my modbus is reading?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/555f58f45a9e9f6dc9a5bc3dfa4bc7ba3d164431.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 September 2024 17:33 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/4 "2024-09-04T17:33:22Z")

</div>

My suggestion above was based on you saying "each pulse adds to my counter".

If in fact each pulse includes the total count for that day I imagine that you can store the value passed in the array rather than incrementing a counter.

---

<div class="post-metadata">

**Author:** ![xfear1](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xfear1](https://discourse.nodered.org/u/xfear1)\
**Post date:** [4 September 2024 18:54 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/5 "2024-09-04T18:54:04Z")

</div>

I'm kind of new with node-red how do I do a command like that?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 September 2024 19:25 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/6 "2024-09-04T19:25:36Z")

</div>

Have you tried any variations of the code I posted?

If you show me your incoming data (not a picture, post actual data) I may be persuaded to give you another hint.

---

<div class="post-metadata">

**Author:** ![xfear1](https://avatars.discourse-cdn.com/v4/letter/x/4da419/32.png) [@xfear1](https://discourse.nodered.org/u/xfear1)\
**Post date:** [5 September 2024 12:32 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/7 "2024-09-05T12:32:15Z")

</div>

My data comes direcly from a modbus adress, using holding registers.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d90a336171c2707db6555602795f07f339862d09.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 September 2024 12:39 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/8 "2024-09-05T12:39:22Z")

</div>

Sadly I have no idea what modbus addresses or holding registers are so I can't offer any more advice.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 October 2024 12:39 UTC](https://discourse.nodered.org/t/inputing-data-in-to-different-gauges-on-for-each-day-of-the-week/90704/9 "2024-10-05T12:39:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
