# Displaying sensor curves on the dashboard

**URL:** <https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535>\
**Category:** Demandes livrées\
**Created:** [September 20, 2021, 5:54am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535 "2021-09-20T05:54:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 5:54am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/1 "2021-09-20T05:54:00Z")

</div>

Hello everyone!

I’m creating this feature request even though it’s already quite advanced so that we can discuss it together on the forum and not just on GitHub.

For the timeline, @euguuu had started a first technical specification and had a first PR by the end of 2020. It was super complete and in terms of research, he went very far!! 🙂

However, the PR was not finished, and I did not agree with all the technical choices that had been made, so I started working on another PR from scratch based on the same research, but with a different implementation.

I started working on it this summer (mid-July), and it was not a simple development!

Concretely, my specification for this feature was:

- Display sensor values in less than 50ms regardless of the dataset (even 2 million sensor values)
- Ability to change the time frame in live by the dashboard user
- A super simple and clear UI.
- The background pre-calculation of aggregated sensor values should not slow down Gladys.
- The user should be able to know if these sensor data have been aggregated or if something went wrong.

For now, it looks like this:

[https://streamable.com/2utkhd](https://streamable.com/2utkhd)

The big challenge of this development is to calculate in the background the aggregated sensor values, and to do it without slowing down Gladys, and **while communicating with the user.**

A new view therefore appears in Gladys, the «&nbsp;background tasks&nbsp;» view:

 ![Screenshot 2021-09-20 at 13.48.03](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/7/749eea86ebf502d89346c43255271b8458963565.jpeg)

In the future, the goal is to integrate all background tasks (scenes, etc.) into this view to give the user more visibility into what is happening in the background in their Gladys.

My PR is available here:

> <https://github.com/GladysAssistant/Gladys/pull/1248>
>
> \### Pull Request check-list
> 
> To ensure your Pull Request can be accepted as fa…st as possible, make sure to review and check all of these items:
> 
> \- \[x\] If your changes affects code, did your write the tests?
> \- \[x\] Are tests passing? (\`npm test\` on both front/server)
> \- \[x\] Is the linter passing? (\`npm run eslint\` on both front/server)
> \- \[x\] Did you run prettier? (\`npm run prettier\` on both front/server)
> \- \[x\] If you are adding a new features/services, did you run integration comparator? (\`npm run compare-translations\` on front)
> \- \[x\] If your changes modify the API (REST or Node.js), did you modify the API documentation? (Documentation is based on comments in code)
> \- \[x\] If you are adding a new features/services which needs explanation, did you modify the user documentation? See \[the GitHub repo\](https://github.com/GladysAssistant/v4-website) and the \[website\](https://gladysassistant.com).
> \- \[x\] Did you add fake requests data for the demo mode (\`front/src/config/demo.json\`) so that the demo website is working without a backend? (if needed) See \[https://demo.gladysassistant.com\](https://demo.gladysassistant.com).
> 
> NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
> 
> \### Description of change
> 
> \<img width="1440" alt="Screenshot 2021-10-22 at 12 58 38" src="https://user-images.githubusercontent.com/7365207/138628975-9ccea155-c2b2-4ca5-b8db-6ac2db564a8c.png"\>

I would appreciate any feedback [@contributors](https://community.gladysassistant.com/groups/contributors) 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 5:58am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/2 "2021-09-20T05:58:49Z")

</div>

To provide more details on the technical implementation, there are now 3 types of aggregations:

- Hourly aggregations: we keep a maximum of 100 events per hour
- Daily aggregations: we keep a maximum of 100 events per day
- Monthly aggregations: we keep a maximum of 100 events per month

The goal is to be able to respond to queries with different time frames:

- Give me the temperature of the last year (we use monthly data)
- Give me the temperature of the last 10 minutes (live data)
- Give me the temperature of the last 2 weeks (daily)

What do you think?

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 6:07am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/3 "2021-09-20T06:07:32Z")

</div>

@Terdious If you have a bit of time (you tell me :p) it would be great if we could test this at your place before I merge, what do you think? 🙂

---

<div class="post-metadata">

**Author:** ![Terdious](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/terdious/32/6316_2.png) [@Terdious](https://community.gladysassistant.com/u/Terdious)\
**Post date:** [September 20, 2021, 8:59am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/4 "2021-09-20T08:59:54Z")

</div>

With great pleasure!! We’ll find the time!!^^  
Can we already test it?  
As for timing (^^), when do you expect feedback at the latest?

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 9:12am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/5 "2021-09-20T09:12:32Z")

</div>

@Terdious Yes you can test, the branch is in a working state!

Whenever you want, I will only deploy if people have tested it beforehand, so the sooner the better 🙂

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [September 20, 2021, 10:29am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/6 "2021-09-20T10:29:44Z")

</div>

I provided my first feedback on GitHub.

I restored my production database but I only have 24 hours of data and I don’t know why.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 10:54am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/7 "2021-09-20T10:54:49Z")

</div>

Thanks for the super detailed feedback @VonOx!

Are you sure the aggregation went well, it’s not normal that you only have the last 24 hours

Do you have the logs?

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [September 20, 2021, 11:15am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/8 "2021-09-20T11:15:54Z")

</div>

In fact, it’s on my production database (device\_state) that I only have 24H

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 20, 2021, 11:18am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/9 "2021-09-20T11:18:12Z")

</div>

You had to configure your production DB to only save 24 hours of data

There is a variable that defines the retention time

(That reminds me that we don’t expose this variable anywhere, I need to display it somewhere)

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [September 20, 2021, 11:34am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/10 "2021-09-20T11:34:17Z")

</div>

I must admit I’m not quite sure how I ended up with this ^^  
 ![image](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/a/afcd053c0f574343dce48413a70f824fa2c22599.png)

I reset the value to 90

---

<div class="post-metadata">

**Author:** ![damalgos](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@damalgos](https://community.gladysassistant.com/u/damalgos)\
**Post date:** [September 21, 2021, 8:24am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/11 "2021-09-21T08:24:12Z")

</div>

I just checked to test your integration, overall the functionality/UI is fine. I couldn’t really test your integration because my production instance has no data in the database. Basically, only the latest data exists. I didn’t touch anything specific to my production instance…

For this, it’s a Xiaomi sensor integrated via Zigbee2MQTT

I’m trying to figure out why it doesn’t store more data…

keep\_history is set to one… I think there’s a bug…

---

<div class="post-metadata">

**Author:** ![damalgos](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@damalgos](https://community.gladysassistant.com/u/damalgos)\
**Post date:** [September 21, 2021, 8:30am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/12 "2021-09-21T08:30:00Z")

</div>

Oh, same! I was looking for where that value was

2 people who have the same weird thing 😃

---

<div class="post-metadata">

**Author:** ![damalgos](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@damalgos](https://community.gladysassistant.com/u/damalgos)\
**Post date:** [September 21, 2021, 9:00am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/13 "2021-09-21T09:00:05Z")

</div>

> [@pierre-gilles](#):
>
> (This reminds me that we don’t display this variable anywhere, I need to display it somewhere)

Yes, I was also looking on the UI and if others have this issue, it might be interesting to display it.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 21, 2021, 10:55am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/14 "2021-09-21T10:55:37Z")

</div>

Weird all this, I’m going to investigate 🙂

And yes, clearly we need to display the value in the UI now that we’re using the history

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 24, 2021, 1:42am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/15 "2021-09-24T01:42:34Z")

</div>

For information, @VonOx gave me some initial feedback on GitHub, which I just replied to here: [Add the ability to vizualize device states on the dashboard by Pierre-Gilles · Pull Request #1248 · GladysAssistant/Gladys · GitHub](https://github.com/GladysAssistant/Gladys/pull/1248#issuecomment-926279523)

Lots of good feedback, both bug fixes and practical improvements to make the feature really useful for the end user.

This is exactly the kind of feedback I’m interested in, I want you to say whether you think it’s a useful and usable feature, or if something is missing.

The goal is to have something that is:

- Very design-oriented
- Configurable and flexible like Grafana
- But very easy to use, with default values that do the work for you and provide a good result with minimal configuration.

So I’m going to improve my version and try to propose a corrected second iteration 🙂

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 24, 2021, 6:23am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/16 "2021-09-24T06:23:19Z")

</div>

A small preview of what I’ve been working on since this morning: a clean display of errors in the «&nbsp;background tasks&nbsp;» view! 🙂

I’ve always been against displaying raw logs in the UI (because we know what that leads to, then we get lazy and do integrations where we ask people to look for IDs in the logs 😂), but I’m in favor of a view like this, where:

- All known errors are translated, and the steps to follow are clearly explained for the user. Example here with a simple error: Gladys restarted while a task was running: this is normal behavior, and it should be specified.
- For unknown errors, we display it as-is so the user can give us feedback, then two options:
  - It’s a bug, we fix the bug
  - It’s an error that can occur under certain conditions (not a bug): Example «&nbsp;OUT\_OF\_MEMORY&nbsp;»/«&nbsp;DISK FULL&nbsp;», etc… In this case, we add this error to the list of translated errors, with a clear message, and with steps to resolve the error.

Here’s what the view looks like for now:

 ![localhost_1444_dashboard_settings_jobs (1)](https://gladys-assistant-community.b-cdn.net/uploads/default/original/2X/0/05968d7efbd75435a06cf73c7670ec4d69c66a60.jpeg)

What do you think? 🙂

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [September 24, 2021, 6:42am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/17 "2021-09-24T06:42:36Z")

</div>

> [@pierre-gilles](#):
>
> A small preview of what I’ve been working on since this morning

It’s morning 😏

> [@pierre-gilles](#):
>
> What do you think?

It’s clear because the error is contextualized with respect to the task.

Access to the complete log could be a plus (it avoids the user having to use SSH) but that’s another topic.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 24, 2021, 7:01am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/18 "2021-09-24T07:01:10Z")

</div>

> [@VonOx](#):
>
> It’s morning 😏

😂

> [@VonOx](#):
>
> Access to the full log could be a plus (it avoids the user having to use ssh) but that’s another topic.

This is the complete error.

In the case of sensor aggregation, as Node.js is single-threaded, I didn’t want to block the main Gladys thread, so the aggregation is done in a separate worker.

The log displayed here is the complete error log sent by the worker, so there’s nothing more to see via SSH 🙂

In any case, there normally shouldn’t be any errors. I added this precisely so that we’re ready for the day we push a mistake, or the day someone with a huge DB hits a technical limitation of their machine (so we can see it), but this case normally shouldn’t happen very frequently.

---

<div class="post-metadata">

**Author:** ![VonOx](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/vonox/32/10128_2.png) [@VonOx](https://community.gladysassistant.com/u/VonOx)\
**Post date:** [September 24, 2021, 7:42am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/19 "2021-09-24T07:42:04Z")

</div>

> [@pierre-gilles](#):
>
> In the case of sensor aggregation, since Node.js is single-threaded, I didn’t want to block the main Gladys thread, so the aggregation is done in a separate worker.

I was talking more about the general log, there you have the case of background tasks.

My idea was more for everything related to services, etc.  
That’s why I said it was another topic.

---

<div class="post-metadata">

**Author:** ![pierre-gilles](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/pierre-gilles/32/5886_2.png) [@pierre-gilles](https://community.gladysassistant.com/u/pierre-gilles)\
**Post date:** [September 24, 2021, 7:48am UTC](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535/20 "2021-09-24T07:48:53Z")

</div>

The next step for me, and it’s a background task, is to add the execution of scenes to this view.

The goal is to be able to see what happened:

- Why a trigger was validated? Or not?
- The execution plan of the scene, and the different conditions validated / or not

After that it will be out of this PR.

[Next page](https://community.gladysassistant.com/t/affichage-des-courbes-de-capteurs-sur-le-dashboard/6535.md?page=2)
