# Concernant l'IA : état des piles

**URL:** <https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354>\
**Category:** Demandes livrées\
**Tags:** feature-core, in-progress\
**Created:** [Juillet 17, 2026, 12:50 UTC](https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354 "2026-07-17T12:50:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris75](https://gladys-assistant-community.b-cdn.net/letter_avatar_proxy/v4/letter/c/6a8cbe/32.png) [@Chris75](https://community.gladysassistant.com/u/Chris75)\
**Post date:** [Juillet 17, 2026, 12:50 UTC](https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354/1 "2026-07-17T12:50:49Z")

</div>

«&nbsp;donne moi l’état en % de toutes les piles&nbsp;»

" quel est l’état de la pile du capteur température salon"

etc …

---

<div class="post-metadata">

**Author:** ![cursor-bot](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/cursor-bot/32/22252_2.png) [@cursor-bot](https://community.gladysassistant.com/u/cursor-bot)\
**Post date:** [Août 17, 2026, 12:08 UTC](https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354/2 "2026-08-17T12:08:19Z")

</div>

Salut tout le monde !

Ce sujet est désormais **en cours de développement**.

Une PR a été ouverte pour permettre à l’assistant IA de répondre sur l’état des piles :

> <https://github.com/GladysAssistant/Gladys/pull/2898>
>
> Implements feature request: https://community.gladysassistant.com/t/concernant-l…ia-etat-des-piles/10354
> 
> This PR was opened by an automated Claude Code run and needs human review before merging.
> 
> \### Description
> 
> The forum request asks the AI to answer questions such as « donne moi l'état en % de toutes les piles » and « quel est l'état de la pile du capteur température salon ».
> 
> \*\*What was missing:\*\* battery levels are ordinary device features (\`DEVICE\_FEATURE\_CATEGORIES.BATTERY\`, type \`integer\`, unit percent), but the \`battery\` category is \*\*not\*\* part of \`sensorFeatures\` in \`server/services/mcp/lib/selectFeature.js\`. As a consequence the AI could not read them at all today: battery features never appear in the \`schema://home\` resource, they are absent from the \`device\_type\` enum of \`device.get-state\`, and a \`device.get-state\` call filtered on them returns nothing. So neither of the two questions above could be answered — this is not a duplicate of an existing tool.
> 
> \*\*What this PR adds:\*\*
> 
> \- \`isBatteryFeature\` in \`selectFeature.js\` (alongside the other feature predicates) and wired on the \`MCPHandler\` prototype.
> \- A new \`device.get-battery-levels\` MCP tool in \`buildSchemas.js\`, registered only when at least one device of the home reports a battery level, like \`device.set-shutter\`, \`device.set-light\`, \`sensor.set-state\` and \`device.get-energy-consumption\` are. Categories: \`device\_query\` and \`other\`.
> - Optional \`device\` and \`room\` parameters (both zod enums built from the home), so the same tool serves the "all batteries" question (no parameter) and the "this one sensor" question.
> - Each entry carries the room, the device name, the feature name, the category, the value, the unit and the \`age\` of the value, through the shared \`formatValue\` helper — same shape as \`device.get-state\`, so the existing prompt rules about \`age\` apply unchanged.
> - Fresh values are read with \`device.getBySelector\` at call time, like \`device.get-state\`, instead of the cached list built when the tools are registered.
> \- Error branches modelled on the neighbouring tools, all returning an explicit sentence instead of an empty list (an empty result is the case where a model invents a plausible value): unknown room (with the list of the real rooms, "No room" excluded), unknown device name (with the list of the devices that do report a level), and a scope with no battery powered device.
> \- A prompt rule in \`server/config/prompts/aiChat.prompt.txt\` pointing the model at \`device\_get\_battery\_levels\` for every battery question, telling it that devices absent from the result do not report a level, and what to say when the tool is not available.
> 
> \*\*Sorting choice:\*\* results are sorted by level ascending, lowest battery first, because what a user asking for the state of all their batteries actually wants is the ones to replace — and a model summarizing a long list answers from its head. Devices that have never reported a level (\`last\_value\` null) are kept at the end rather than sorted as if they were 0.
> 
> \*\*Deliberately not done:\*\* the \`battery\` category was \*not\* added to \`isSensorFeature\`. That would have been the smaller diff, but every battery feature would then be added to the home schema and to every \`device.get-state\` answer, where it is noise for questions about temperature, lights or shutters, and it would also have made battery features writable through \`sensor.set-state\` for MQTT devices. Only \`battery\` (percentage) is covered; \`battery-low\` (binary) is left out of scope.
> 
> \## Forum
> 
> Forum: https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354
> 
> \### Checklist
> 
> \- \[x\] Tests pass: \`cd server && npm run coverage\` (Codecov requires 100% coverage on changed lines) and Cypress (\`npm run cypress:run\`) if the UI changed
> \- \[x\] Linter and prettier pass on both front and server (\`npm run eslint\`, \`npm run prettier\`)
> \- \[x\] No undocumented breaking change
> 
> Details on what was actually run:
> 
> \- \`npm\_config\_service=mcp npm run test-service\` → 144 passing, including 4 new tests: the sorted whole-home listing (with a device without a room and two devices that never reported a level), filtering by device and by room, the three error branches, and the tool not being registered when no device has a battery. Every existing \`mcpHandler\` mock in \`buildSchemas.test.js\` got \`isBatteryFeature\` added, since \`getAllTools\` now calls it.
> \- \`c8\` over the MCP suite: no uncovered line and no uncovered branch in the new code (\`selectFeature.js\` at 100%). The only lines \`c8\` reports as uncovered in \`buildSchemas.js\` (798-801, a \`device.turn-on-off\` branch) are pre-existing and untouched.
> \- \`npm run eslint\` in \`server/\`: 0 errors (only pre-existing warnings elsewhere in the repo, none in the touched files). \`npm run prettier-check\`: clean.
> \- \`test/lib/gateway/gateway.forwardMessageToAiChat.test.js\`: 43 passing. Not run: the full server suite. \`test/lib/gateway/gateway.restoreBackupEvent.test.js\` has 2 failures, verified identical on an untouched checkout of \`master\` — unrelated to this change.
> \- No front-end change, so Cypress was not run.
> 
> \---
> \_Generated by \[Claude Code\](https://claude.ai/code/session\_013yxguVaLdJ8ZKmw5x3HePT)\_
> 
> 
> 
> \## Summary by CodeRabbit
> 
> \- \*\*New Features\*\*
> - Added battery-level information for supported devices.
> - Battery readings can be filtered by device, room, or home.
> - Results are sorted from lowest to highest charge level.
> - Low-battery indicators reflect configured warning thresholds.
> - Unavailable or missing readings are clearly handled.
> - Electric vehicle and home storage batteries are excluded from results.
> - Battery tools are available only when supported by the connected devices.
> \- \*\*Bug Fixes\*\*
> - Improved validation for unknown device and location filters.
> - Added more reliable handling of sensor state and persisted settings.

N’hésitez pas à suivre la PR, à tester dès que possible et à faire vos retours ici.

---

<div class="post-metadata">

**Author:** ![cursor-bot](https://gladys-assistant-community.b-cdn.net/user_avatar/community.gladysassistant.com/cursor-bot/32/22252_2.png) [@cursor-bot](https://community.gladysassistant.com/u/cursor-bot)\
**Post date:** [Août 28, 2026, 12:31 UTC](https://community.gladysassistant.com/t/concernant-lia-etat-des-piles/10354/3 "2026-08-28T12:31:15Z")

</div>


