« quelle a été la consommation en Kwh de la prise onduleur pour la journée du 12 juillet 2026 »
« quel coût en euro pour la consommation de la prise télé pour le mois de juin 2026 »
etc…
guim31
Juillet 18, 2026, 4:04
2
Si je ne m’abuse, ça n’a pas de rapport avec les graphiques mais avec un historique d’état ou calcul de ceux-ci ou je me plante ?
@guim31 oui peut-être, mais est-ce que les cumuls (pour une journée par exemple) sont conservés en tant qu’historique ou bien sont recalculés pour l’affichage du graphique ?
C’est bon, l’IA peut désormais répondre aux questions liées à la consommation électrique d’un équipement, en kWh et en euros !
master ← claude/chat-ia-energy-queries-xjrwub
ouvert 11:19AM - 23 Jul 26 UTC
### Pull Request check-list
To ensure your Pull Request can be accepted as fast… as possible, make sure to review and check all of these items:
- [x] If your changes affect the code, did you write the tests?
- [x] Are server tests passing with coverage? (`cd server && npm run coverage`) — Codecov requires **100% coverage on lines changed in this PR** (all new lines in `buildSchemas.js` are covered by the two new tests)
- [ ] Did Cypress E2E tests pass? (`npm run cypress:run` from repo root, if UI changed) — no UI change
- [x] Is the linter passing? (`npm run eslint` on both front/server)
- [x] Did you run prettier? (`npm run prettier` on both front/server)
- [ ] If you are adding a new feature/service, did you run the integration comparator? (`npm run compare-translations` on front) — no front change
- [ ] Did you test this pull request in real life? With real devices? — tested with unit tests only; real-life testing with an energy monitoring setup welcome
- [ ] If your changes modify the API (REST or Node.js), did you modify the API documentation? — no REST API change, the new tool is documented through its MCP/JSON schema description
- [ ] If you are adding a new features/services which needs explanation, did you modify the user documentation?
- [ ] Did you add fake requests data for the demo mode (`front/src/config/demo.js`) so that the demo website is working without a backend? — not needed, server-side only
### Description of change
This PR lets the AI Chat answer questions like:
- « quelle a été la consommation en kWh de la prise onduleur pour la journée du 12 juillet 2026 »
- « quel coût en euro pour la consommation de la prise télé pour le mois de juin 2026 »
Previously the chat only had `device_get_history`, which works with relative intervals (`last-day`, `last-month`…) and averaged aggregates, so it could neither target a specific date/month nor compute a consumption total or a cost.
**What's added:**
1. **New MCP tool `device.get-energy-consumption`** (`server/services/mcp/lib/buildSchemas.js`), exposed only when at least one device has `energy-sensor` features of type `thirty-minutes-consumption` or `thirty-minutes-consumption-cost`. It reuses the existing `device.energySensorManager.getConsumptionByDates()` (same code path as the energy dashboard):
- `device`: energy monitoring device name (enum),
- `start_date` / `end_date`: inclusive `YYYY-MM-DD` dates (same local-midnight boundaries as the dashboard),
- `unit`: `kwh` (consumption, with automatic Wh → kWh conversion) or `currency` (cost, using the cost feature's currency unit),
- `group_by`: optional `hour`/`day`/`week`/`month`/`year` detail (defaults to `day`).
The response contains the period total first, then the per-period detail. In currency mode, the home electricity contract subscription is returned as a separate `home_subscription` entry so the model doesn't mix it up with the device's own consumption cost. Friendly error messages are returned for unknown devices, invalid dates, or devices without cost tracking configured.
2. **Intent router update** (`gateway.classifyAiChatToolCategories.js`): the `device_query` category description now mentions energy consumption (kWh) and energy cost over a period, so these questions are routed with the right tools.
3. **System prompt update** (`aiChat.prompt.txt`): a rule instructs the model to use `device_get_energy_consumption` with inclusive `YYYY-MM-DD` dates for consumption/cost questions, and never `device_get_history` for consumption totals or costs.
4. **Tests** (`buildSchemas.test.js`): two new tests covering the kWh single-day query, the monthly cost query with subscription entry, the no-cost-tracking case, empty periods, unknown device, invalid/reversed dates, and the tool not being exposed without energy monitoring devices.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01UwzEsLH8BRLUUQu9iUBvYA
---
_Generated by [Claude Code](https://claude.ai/code/session_01UwzEsLH8BRLUUQu9iUBvYA)_
## Summary by CodeRabbit
* **New Features**
* Added an energy consumption and cost reporting tool for supported smart-home devices.
* Supports inclusive date-range queries (YYYY-MM-DD) with daily grouping and totals in kWh or currency.
* Includes subscription cost details when available, and adds notes when no data exists for the selected period.
* **Bug Fixes**
* Energy totals and costs now rely on dedicated energy measurements rather than historical activity.
* **Tests**
* Added end-to-end coverage for tool exposure, output shaping, and validation/error scenarios.
Ça partira dans la prochaine version de Gladys
C’est disponible dans Gladys Assistant 4.84 :
Bonsoir à tous !!
Je suis super heureux de sortir ce soir une version qui, je pense, va vraiment changer la vitesse d’évolution du projet.
Les intégrations externes arrivent enfin dans Gladys ! Elles vont permettre d’enrichir beaucoup plus rapidement la liste des appareils et services compatibles, tout en permettant à chacun de développer et partager ses propres intégrations.
Je vous explique tout dans cet article