Ric
Mars 2, 2024, 12:38
1
Bonjours la communauté,
Pour reprendre l’idée de @Prof_Techno , serait il possible de créer une fonctionnalité permettant d’exporter les données au format CVS afin de les croiser avec d’autres données externes?
Merci beaucoup.
Salut @Ric Bonne idée, pense à voter pour la fonctionnalité, on verra si il y a de la demande !
Jluc
Novembre 4, 2025, 10:03
3
Bonjour,
Avant j’enregistrais mes consommations (eau, électricité) sur excel. Depuis que j’utilise Gladys je dispose de beaucoup plus de données mais elle ne s’affichent que pendant un an. Dans la configuration le choix illimité est disponible mais au final, pas les données.
L’historique sur un an est intéressant à comparer à d’autres années alors si ce n’est pas possible sur Gladys, est-ce possible d’enregistrer les données pour les exporter ?
C’est vrai que ce serait chouette de pouvoir analyser ses données sur des plus longues durées. @Terdious avait travaillé sur ce sujet à un moment mais ça n’a pas abouti, je ne sais pas si il y a une demande de fonctionnalité pour ça, ça serait chouette !
Actuellement tu peux faire des exports via l’API, ça se fait assez facilement ! C’est sûr, c’est plus compliqué qu’un clic, mais c’est pas non plus hyper compliqué. Si ça t’intéresse, je peux te faire un tutoriel
Jluc
Novembre 5, 2025, 10:33
5
Je veux bien un tuto si ce n’est pas risqué de l’appliquer. Merci @pierre-gilles
@Jluc Hop je t’ai écris un beau tuto :
Salut à tous !
Je vous propose aujourd’hui un petit tutoriel pour télécharger un CSV de toutes les valeurs historiques d’un capteur.
Pour cela, nous allons passer par l’API HTTP de Gladys.
Étape n°1 : Télécharger un client HTTP
Je vous conseille Yaak .
Étape n°2 : Récupérer un token
L’API de Gladys étant sécurisée, il va falloir récupérer un token.
Créez une nouvelle requête dans Yaak sur l’URL
Méthode : POST
URL : http://IP_DE_VOTRE_INSTANCE_GLADYS/api/v1/login
Body Type : JSON
Body :
…
C’est une bonne occasion de tester l’API de Gladys, ça peut servir pour plein de choses
Jluc
Novembre 6, 2025, 1:03
7
Super, il va falloir que je me lance
Merci et si ça sert à de nombreux utilisateurs Gladys, c’est parfait !
Salut tout le monde !
Ce sujet est désormais en cours de développement .
Une PR a été ouverte pour exporter l’historique d’un élément en CSV depuis le widget graphique :
master ← claude/csv-export-history
ouvert 02:29AM - 16 Aug 26 UTC
Implements feature request: https://community.gladysassistant.com/t/exportation-… des-donnees-au-format-csv/8750
### Description
Users asked on the forum for a way to export their history (device feature values, energy/water consumption in particular) as CSV, so they can cross-analyse it in a spreadsheet with external data and compare one year with another. Until now the only way was to script the REST API by hand.
This PR adds one complete export path, plugged into the place where users already look at their history: the chart widget.
**Server**
- New `device.exportStatesToCsv(deviceFeatureSelectors, start, end)` (`server/lib/device/device.exportStatesToCsv.js`). It reuses the existing raw history query (`getDeviceFeatureStates`) for each selected feature and merges everything into one date-ordered file with the columns `date,device,feature,unit,value` (long format, easy to pivot in a spreadsheet). Values containing a separator, a quote or a line break are properly escaped.
- New authenticated route `GET /api/v1/device_feature/states_csv?device_features=a,b&start=<ISO>&end=<ISO>`, answering `text/csv; charset=utf-8` with a `Content-Disposition` filename. It is usable directly from the API too, which also covers the scripting use case discussed on the forum.
- Invalid input is rejected with clear `BadParameters` errors (no feature, invalid dates, end before start), and an unknown feature returns a 404.
- The file is built in memory, so the export is refused upfront when the period contains more than `MAX_STATES_TO_EXPORT_IN_CSV` (500 000) states: a very chatty sensor over a year cannot exhaust the memory of a Raspberry Pi. The error message tells the user to export a shorter period.
**Front**
- An "Export as CSV" entry is added at the bottom of the chart widget period menu. It exports exactly the device features and the period currently displayed, so the existing period navigation (previous/next period) lets a user export a past year as well.
- The downloaded file starts with a UTF-8 BOM so spreadsheets (Excel in particular) display accented device names correctly.
- Errors are displayed in the widget, with the server detail (e.g. "period too large").
- New i18n keys `dashboard.boxes.chart.exportCsv` and `dashboard.boxes.chart.exportCsvError` added to `en`, `fr` and `de`.
## Forum
Forum: https://community.gladysassistant.com/t/exportation-des-donnees-au-format-csv/8750
### Checklist
- [x] Tests pass: `cd server && npm test` (full Mocha suite — the only failures are pre-existing environment ones: gateway backup/restore tests needing the `sqlite3` CLI, Docker socket and network, identical before and after this change). Coverage checked on the changed files: `server/lib/device/device.exportStatesToCsv.js` is at 100% statements/branches/functions/lines, and the new controller lines are covered by `server/test/controllers/device/device.controller.test.js`. Cypress was not run (no browser binary in this environment).
- [x] Linter and prettier pass on both front and server (`npm run eslint`, `npm run prettier` / `prettier-check`), plus `npm run compare-translations` and `npm run build` on the front.
- [x] No undocumented breaking change (purely additive: one new route, one new lib function, one new UI entry point).
> This pull request was opened by an automated Claude Code run. It needs a human review before merging.
---
_Generated by [Claude Code](https://claude.ai/code/session_01BRdJPgpjHkz9LKu39n8fm8)_
## Summary by CodeRabbit
* **New Features**
* Added CSV export for chart data using selected device features and the displayed time period.
* Downloads include readable filenames and properly formatted, spreadsheet-safe CSV content.
* Added loading indicators, export controls, and clear error messages when exports fail.
* Added support for English, German, and French export labels and messages.
* **Bug Fixes**
* Added validation for missing features, invalid dates, duplicate selections, and oversized export requests.
* Improved handling of legacy single-feature charts and empty time periods.
N’hésitez pas à suivre la PR, à tester dès que possible et à faire vos retours ici.