Skip to main content
Glama
homeassistant-ai

Home Assistant MCP Server

Official

Manage Energy Dashboard Preferences

ha_manage_energy_prefs
Destructive

Read, update, or add energy sources, device consumption entries, and cost tariffs for the Home Assistant Energy Dashboard.

Instructions

Manage the Home Assistant Energy Dashboard preferences.

The Energy Dashboard configuration (grid/solar/battery/gas/water energy sources, individual device consumption sensors for electricity and water, cost tariffs) is stored in .storage/energy and not otherwise reachable via REST, services, or helper flows — this tool is the only way for agents to inspect or modify it.

WHEN TO USE:

  • mode='get' / 'set': inspect or replace the full Energy Dashboard config. Use 'set' for bulk edits or anything touching multiple top-level keys at once.

  • mode='add_device' / 'remove_device': add or remove a single device-consumption entry. The tool performs a fresh read-modify-write internally; the caller does NOT manage config_hash. Use water=True to target the water meter list instead of electricity.

  • mode='add_source': append a single entry to energy_sources (grid, solar, battery, gas, or water). Same atomic read-modify-write semantics.

WHEN NOT TO USE:

  • To create the underlying statistics themselves — they must already exist as HA entities before being referenced here; create them via the relevant integration's config flow first.

CAVEATS:

  • energy/save_prefs has per-key FULL-REPLACE semantics. Passing {"device_consumption": [<one entry>]} deletes every other device the user had configured — silently, with no error. mode='set' requires a fresh config_hash for optimistic locking; convenience modes hide this entirely.

  • config_hash accepts both a single str (full-blob lock) and a dict[_PrefsKey, str] keyed by top-level keys (per-key lock, taken from the config_hash_per_key field of the mode='get' response). The per-key form lets an agent submit only the top- level key it wants to change — set-equality between config keys and dict keys is enforced, and any key outside the canonical set (typo, etc.) on either side is rejected with VALIDATION_FAILED rather than silently dropped (so an empty submission cannot succeed as a no-op). A per-key submission still fully replaces that key's value as the save endpoint requires. Mismatch on any locked key returns RESOURCE_LOCKED with the offending keys in the response's top-level mismatched_keys (create_error_response flattens the context dict onto the response root).

  • dry_run=True skips the hash check entirely for both forms; the per-key form is therefore silently accepted on dry runs even if its keys would mismatch the current state.

  • A local shape check runs before every write; malformed payloads are rejected with a shape_errors list.

  • After a successful write, the tool calls energy/validate and returns any residual issues as post_save_validation_errors in the response. These reflect semantic problems (missing stats, unit mismatches) that shape checks can't catch; the save persists regardless — correct the config and write again if needed.

  • The underlying save endpoint is admin-only. Non-admin tokens will receive an authorization error from Home Assistant.

  • Convenience modes are NOT idempotent: 'add_device' on an existing stat_consumption returns RESOURCE_ALREADY_EXISTS; 'remove_device' on a missing entry returns RESOURCE_NOT_FOUND. 'add_source' rejects duplicates by (type, stat_energy_from) for solar/battery/gas/water (RESOURCE_ALREADY_EXISTS); grid entries are appended without a duplicate check (multiple grid variants are legitimate, and grid has no single canonical uniqueness key) — the caller is responsible for de-duplicating grid sources.

  • Convenience modes do NOT bypass the local shape check on dry_run: dry_run=True still raises RESOURCE_ALREADY_EXISTS (duplicate add_device / add_source), RESOURCE_NOT_FOUND (missing remove_device), or VALIDATION_FAILED (post-mutator shape error) when the proposed mutation is not applicable. The mutator and shape check both run before the dry-run short-circuit.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modeYesOperation mode. Primitives: 'get' reads the current prefs; 'set' writes a full prefs payload (per-top-level-key full-replace). Convenience modes: 'add_device' / 'remove_device' / 'add_source' perform a single read-modify-write atomically — no config_hash from the caller, the tool fetches it fresh internally.
nameNoOptional display name for mode='add_device'. Only used when adding a new device entry; ignored otherwise.
waterNoIf True, mode='add_device' / 'remove_device' targets 'device_consumption_water' instead of 'device_consumption'. Default False.
configNoFull prefs payload for mode='set'. Must contain the top-level keys you intend to replace: 'energy_sources', 'device_consumption', 'device_consumption_water'. Any top-level key present in this payload REPLACES the existing list entirely; any omitted key is preserved. Call with mode='get' first, mutate the returned config, then pass the whole object back. Ignored by convenience modes.
sourceNoSingle energy_sources entry for mode='add_source'. Must contain 'type' (one of grid|solar|battery|gas|water) and the type-specific required fields (e.g. solar/battery/gas/water require 'stat_energy_from'). Every source type also accepts an optional 'name' (display label in the energy graphs); battery additionally accepts 'stat_soc' (state-of-charge statistic). Note: HA Core's voluptuous schema for grid sources requires the full field set (cost_adjustment_day, stat_energy_to, stat_cost, entity_energy_price, number_energy_price, entity_energy_price_export, number_energy_price_export, stat_compensation) — the local shape check is narrower, so a minimal {'type': 'grid'} passes locally but surfaces in post_save_validation_errors after writing. Pass the unused fields as None to satisfy the server. Required for mode='add_source'; ignored otherwise.
dry_runNoIf True, no write is performed. For mode='set': runs a local shape check on the proposed config AND calls the server's energy/validate against the CURRENT persisted state (Home Assistant's validate endpoint cannot validate an unsubmitted payload). For convenience modes: simulates the mutation against a fresh read and reports what would change without writing — but still raises RESOURCE_ALREADY_EXISTS (duplicate add_device, or duplicate add_source for solar/battery/gas/water), RESOURCE_NOT_FOUND (missing remove_device), or VALIDATION_FAILED (post-mutator shape error) when the proposed mutation is not applicable. Default False.
config_hashNoHash from a previous mode='get' call. REQUIRED for mode='set' unless dry_run=True. Two forms: str (full-blob lock) or dict (per-key lock, taken from the config_hash_per_key field of mode='get'). Pass the dict form as a native object, NOT a JSON-encoded string — a stringified dict is treated as a full-blob token and will report RESOURCE_LOCKED; clients that can only send strings should use the str full-blob form. See the tool docstring for fail-closed semantics. Ignored by convenience modes.
included_in_statNoOptional 'parent' statistic for mode='add_device'. Set this to a statistic that already INCLUDES this device's consumption (e.g., a whole-home or circuit-level meter that this device feeds into). The Energy Dashboard will subtract this device's reading from the parent so the parent's contribution is not double-counted. Ignored otherwise.
stat_consumptionNoStatistic entity_id for mode='add_device' / 'remove_device' (e.g. 'sensor.fridge_energy'). Required for those modes; ignored otherwise.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Beyond annotations (destructiveHint=true), the description discloses full-replace semantics, hash-locking behavior, admin-only permission, dry_run effects, error types (RESOURCE_LOCKED, RESOURCE_ALREADY_EXISTS, RESOURCE_NOT_FOUND, VALIDATION_FAILED), and non-idempotence. This adds substantial value over annotations alone.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections and bullet points, but it is very long and wordy. Some caveats could be condensed without losing meaning. The front-loading of overall purpose is good, but the length detracts from conciseness, earning a mid-range score.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (9 parameters, 1 required, 100% schema coverage, output schema present, annotations provided), the description covers all important aspects: operational modes, error cases, locking semantics, dry_run behavior, shape validation, and security constraints. It leaves no gaps for an agent to misunderstand.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

While input schema has 100% description coverage (baseline 3), the description adds extra detail like config_hash accepting dict/object, source field requirements per type, and included_in_stat semantics. This extra context justifies a slight above-baseline score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool manages Home Assistant Energy Dashboard preferences, enumerates all operation modes (get, set, add_device, remove_device, add_source), and differentiates itself from siblings by noting this is the only way to access the energy storage. It provides specific verb-resource pairs and scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes explicit WHEN TO USE and WHEN NOT TO USE sections, detailing each mode's purpose. It advises when to use convenience modes vs. set, and notes that underlying statistics must be created via other integrations first. Though alternatives aren't explicitly named, the guidance is comprehensive.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/homeassistant-ai/ha-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server