# Keep precipitation for 10 days in an array or fifo queue with 10 places and add a new value every day

**URL:** <https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472>\
**Category:** Questions & Help\
**Created:** [June 28, 2023, 7:26pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472 "2023-06-28T19:26:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmeester](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pmeester/32/17275_2.png) [@pmeester](https://community.homey.app/u/pmeester)\
**Post date:** [June 28, 2023, 7:26pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/1 "2023-06-28T19:26:51Z")

</div>

Can that be done in an (advanced) flow? If so, would you have an example for me?

Thanks!

---

<div class="post-metadata">

**Author:** ![Sharkys](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sharkys/32/54029_2.png) [@Sharkys](https://community.homey.app/u/Sharkys)\
**Post date:** [June 28, 2023, 10:16pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/2 "2023-06-28T22:16:19Z")

</div>

Try with Better logic… [Better Logic Library App for Homey | Homey](https://homey.app/en-us/app/net.i-dev.betterlogic/Better-Logic-Library/)  
You can import/export variables but it do not allow to create array as such, if I’m not mistaken.  
Why do you need to store them ? They are available in insights from some sensor, or ?

Eg. Netatmo Rain sensor have “rain today” :

 ![obrazek](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/d/cd0b0a82cfc7ee3c7e514e4b55f1758f2bae785b.png)

So then you can use [Insights trends](https://homey.app/en-us/app/com.spkes.insightTrendsReloaded/Insight-Trends-Reloaded/) for some statistical analysis / use.

Or [Device capability](https://homey.app/en-us/app/nl.qluster-it.DeviceCapabilities/Device-Capabilities/) app and read values via Retrieve values…  
 ![obrazek](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/4/e401ab383fc9a1127a74b0b77897f53fb036531a.png)

---

<div class="post-metadata">

**Author:** ![pmeester](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pmeester/32/17275_2.png) [@pmeester](https://community.homey.app/u/pmeester)\
**Post date:** [June 30, 2023, 7:16am UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/3 "2023-06-30T07:16:12Z")

</div>

Thank you. I do not have a device, I use Weatherpro. The free version only provides the current precipitation every 15 minutes. I add them up during the day and for watering plants I would like to keep a running history of the precipitation of last 10 days.

I was wondering if a JSON structure could be used to store the values in a variable. But how to manipulate the JSON structure…

In any case, I can probably do it in a Homey Script routine.

Paul

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [June 30, 2023, 9:17pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/4 "2023-06-30T21:17:14Z")

</div>

@pmeester

You can use the JSON handler app for handlering jsons.

But even in the BetterLogicLibrary you can use arrays.  
Just place [1,2,3,4] in a variable for instance.  
Now, use the BLL expression cards and place the variable containing the array in it, plus `[0]` behind it, and you will recieve the fiest element in the array.

BLL alows predefined functions, so you can create push functions for instance.

Example:

> [@\[APP\]\[Pro\] Better Logic Library - For Users](https://community.homey.app/t/app-pro-better-logic-library-for-users/71876/35):
>
> Hey @Rrrr , Wel, yeah, not specificly, but generally, BLL supports Arrays. because i don’t exactly know how users will want to use this, i haven’t implemented special array functions or anything, but you can do that yourself quite easily. For instance, here a small array functionality. Create a BLL function called pushAsString and place this in it’s body: function(arr, value) { arr.push(value); return JSON.stringify(arr); } Add a flowcard Set variable to text: Set ArrayTest to [] A…

---

<div class="post-metadata">

**Author:** ![pmeester](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pmeester/32/17275_2.png) [@pmeester](https://community.homey.app/u/pmeester)\
**Post date:** [July 1, 2023, 5:42am UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/5 "2023-07-01T05:42:56Z")

</div>

@Arie_J_Godschalk, Thank you. Can you give an example? If I have a string variable S1=[1,2,3,4,5], then:  
If I use BLL “Set Number Variable” then I do not get the string variable S1 as an option to do S1[0] with. I only get real number variables

If I use BLL “Set a variable N1 S1[0]” then I get the error “Not a number”

---

<div class="post-metadata">

**Author:** ![Paul\_Nas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/paul_nas/32/80581_2.png) [@Paul\_Nas](https://community.homey.app/u/Paul_Nas)\
**Post date:** [November 9, 2023, 11:11pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/6 "2023-11-09T23:11:29Z")

</div>

Hi @Arie_J_Godschalk, I am trying to build a rate limit queue for logging to Google Sheets using an array but for some reason I can’t read the values. I managed to use your example to fill a 2-dimensional array with values (each log line is an array within the array variable), which is awesome, but when I try to read the first value, I get nothing:

 ![Scherm­afbeelding 2023-11-09 om 23.33.22](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/f/4fea2c478f58248791171404c18845c57d10b97b.png)  
Even though I can see that the array contains 2 values:  
 ![Scherm­afbeelding 2023-11-09 om 23.33.07](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/e/7eba47434f761fa928c7aecad1121700c26a8421.png)  
I’m not sure what I’m doing wrong. I am expecting to get “[“Badkamer”,“09-11-2023 11:03:44”,“39.8”,“25.5”,”“,”“]” as a value, on which I would do further array value reading ([0], [1] etc).

At any rate, some array operation cards such as reading of values, push, pop, shift and unshift would be nice!

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [November 10, 2023, 4:44am UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/7 "2023-11-10T04:44:04Z")

</div>

@Paul_Nas Well, what you expecting is that it would return an array, but this flowcard does not do that, because the returning tags are either string, number or boolean.  
If you want to grap an json/array, use the json handler app.  
But perhaps i can add a json tag to the execution flowcard. Please create a ticket?

---

<div class="post-metadata">

**Author:** ![Paul\_Nas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/paul_nas/32/80581_2.png) [@Paul\_Nas](https://community.homey.app/u/Paul_Nas)\
**Post date:** [November 10, 2023, 3:05pm UTC](https://community.homey.app/t/keep-precipitation-for-10-days-in-an-array-or-fifo-queue-with-10-places-and-add-a-new-value-every-day/83472/8 "2023-11-10T15:05:38Z")

</div>

@Arie_J_Godschalk it took some effort to figure this out but I got it working thanks to your help! I created a non-array array using ‘|’ as a delimiter which I then turned into an array with a predefined function in BLL, read with JSON Handler and passed on to Google Sheets for logging. The (incomplete) AF is:

 ![Scherm­afbeelding 2023-11-10 om 15.58.56](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a2a2a35b40a5bbfec0978567b0d0d05b077dd36a.jpeg)

My buffer array looks like this:

 ![Scherm­afbeelding 2023-11-10 om 15.21.22](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/f/df6a7360929db273c3a85429d1ba86263a13ce5d.png)

Function ‘Splits’:  
 ![Scherm­afbeelding 2023-11-10 om 15.23.12](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/e/9ec4c6bb8dcddfd24b008acc412a7fa6c99e7e9d.png)

To fill the array with new values, I use function ‘pushArray’:  
 ![Scherm­afbeelding 2023-11-10 om 15.25.34](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/5/057a78d8d0f1bd263c52127c58c20d5410aca0ea.png)

All I have to do now is write the oldest value of the array to Google Sheets every 3 minutes or so using the above (unless there’s nothing in the array) and apply this solution to all my logging. Yay! Maybe I could do without the function ‘Splits’ and instead use \_.split but then I wouldn’t know what each element is called so I can’t reference them in JSON Handler… @pmeester can you use any of my stuff to solve your problem?
