Ric
March 2, 2024, 12:38pm
1
Hello community,
Building on @Prof_Techno ’s idea, would it be possible to create a feature that allows exporting data in CSV format so they can be cross-referenced with other external data?
Thank you very much.
Hi @Ric Good idea, think about voting for the feature, we’ll see if there’s demand!
Jluc
November 4, 2025, 10:03am
3
Hello,
Previously I recorded my consumption (water, electricity) in Excel. Since I started using Gladys I have a lot more data but they are only displayed for one year. In the settings the unlimited option is available but ultimately the data are not.
A one-year history is interesting to compare with other years, so if this is not possible on Gladys, is it possible to save the data to export them?
It’s true that it would be nice to be able to analyze your data over longer periods. @Terdious had worked on this topic at one point but it didn’t come to fruition, I don’t know if there’s a feature request for that, it would be great!
At the moment you can do exports via the API, it’s fairly easy! Sure, it’s more complicated than a click, but it’s not super complicated either. If you’re interested, I can make a tutorial for you
Jluc
November 5, 2025, 10:33am
5
I’d like a tutorial if it’s not risky to apply it. Thanks @pierre-gilles
@Jluc Hey, I wrote a nice tutorial for you:
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 :
…
It’s a good opportunity to test the Gladys API, it can be useful for lots of things
Jluc
November 6, 2025, 1:03pm
7
Great, I’ll have to get started
Thanks, and if it helps many Gladys users, that’s perfect!
Hi everyone!
This topic is now in development .
A PR has been opened to export the history of an item in CSV from the graph widget:
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.
Don’t hesitate to follow the PR, test as soon as possible, and give your feedback here.
Desktop view:
Mobile view:
Of course, with the new theme