Monitoring electricity bills and submitting meter readings is a breeze when integrated into your local smart home system. This post explains how to connect your Hidroelectrica (iHidro portal) account with Home Assistant and your AI developer assistant, Antigravity (agy).
1. Prerequisites and Installation
To interface with the iHidro portal API, we use the community custom integration:
- Add Custom Repository:
In HACS (Home Assistant Community Store), navigate to Integrations ➔ select the three dots (⋮) in the top-right corner ➔ select Custom repositories ➔ add:
- URL:
https://github.com/cnecrea/hidroelectrica - Category:
Integration
- Install & Restart: Search for Hidroelectrica, click install, and restart Home Assistant.
- Configure: Go to Settings ➔ Devices & Services ➔ Add Integration ➔ Search for Hidroelectrica ➔ Log in using your iHidro credentials.
This generates base utility entities for your active electrical connections.
2. Creating Numeric Custom Sensors
The default integration returns the balance status as "Da" (unpaid balance exists) or "Nu" (no balance outstanding). To display the actual pending sum as a state on your dashboard, add these template sensors to configuration.yaml:
template:
- sensor:
- name: "Hidroelectrica Balance 894"
state: >
{% set val = state_attr('sensor.hidroelectrica_0000000000_sold_factura', 'Sold') %}
{{ val | replace(' lei', '') | replace(',', '.') | float if val is not none else 0.0 }}
unit_of_measurement: "RON"
device_class: monetary
icon: mdi:cash
- name: "Hidroelectrica Balance 011"
state: >
{% set val = state_attr('sensor.hidroelectrica_0000000000_sold_factura', 'Sold') %}
{{ val | replace(' lei', '') | replace(',', '.') | float if val is not none else 0.0 }}
unit_of_measurement: "RON"
device_class: monetary
icon: mdi:cash
3. Lovelace Custom Dashboard Cards
Because archived indexes and payment history lists are stored inside attributes, you can render them as formatted tables using Lovelace Markdown Cards. Make sure to specify the literal block scalar (| or |-) to preserve newlines:
A. Index History Table
type: markdown
title: Istoric Index Hidroelectrica (894)
content: |-
| Dată citire | Index |
| :--- | :--- |
{% for key, value in states.sensor.hidroelectrica_0000000000_arhiva_index_energie_electrica_2026.attributes.items() -%}
{% if 'Index' in key -%}
| {{ key | replace('Index (Regularizare) ', '') }} | **{{ value }}** |
{% endif -%}
{% endfor %}
B. Payment Archive Table
type: markdown
title: Istoric Plăți Hidroelectrica (894)
content: |-
| Descriere Plată | Sumă |
| :--- | :--- |
{% for key, value in states.sensor.hidroelectrica_0000000000_arhiva_plati_2026.attributes.items() -%}
{% if 'Plat' in key -%}
| {{ key }} | **{{ value }}** |
{% endif -%}
{% endfor %}
---
**Total Plătit în 2026**: {{ state_attr('sensor.hidroelectrica_0000000000_arhiva_plati_2026', 'Sumă totală') }}
4. Antigravity (agy) CLI Integration
To query these states, agy runs the local Home Assistant API query script located at get_ha_sensor.sh. Here is the full bash script source code:
#!/usr/bin/env bash
# =============================================================================
# Home Assistant Sensor CLI Bridge
# Queries the local REST API for device status
# =============================================================================
set -eo pipefail
ENTITY_ID=$1
if [[ -z "$ENTITY_ID" ]]; then
echo "Usage: $0 <entity_id>"
exit 1
fi
TOKEN_FILE="/home/gvoina/homeassistant/api_token.txt"
if [[ ! -f "$TOKEN_FILE" ]]; then
echo "Error: API token not found at $TOKEN_FILE."
echo "Please save your Long-Lived Access Token to that file."
exit 1
fi
TOKEN=$(cat "$TOKEN_FILE" | tr -d '\r\n[:space:]')
RESPONSE=$(curl -s -X GET \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
"http://localhost:8123/api/states/$ENTITY_ID")
if echo "$RESPONSE" | jq -e '.state' >/dev/null 2>&1; then
STATE=$(echo "$RESPONSE" | jq -r '.state')
UNIT=$(echo "$RESPONSE" | jq -r '.attributes.unit_of_measurement // ""')
NAME=$(echo "$RESPONSE" | jq -r '.attributes.friendly_name // ""')
if [[ -n "$UNIT" && "$UNIT" != "null" ]]; then
echo "$NAME: $STATE $UNIT"
else
echo "$NAME: $STATE"
fi
else
echo "Error: Failed to fetch state for entity '$ENTITY_ID'."
echo "API Response: $RESPONSE"
exit 1
fi
Document the entity IDs in your workspace custom rules at .agents/AGENTS.md so the agent knows they exist:
### 1. Home Assistant State & Control
You can retrieve the live state of any Home Assistant entity:
* **Query sensor/device state**: `bash /home/gvoina/scripts/get_ha_sensor.sh <entity_id>`
* *Tip*: Use this to check:
* **Hidroelectrica**: `sensor.hidroelectrica_balance_894` or `sensor.hidroelectrica_0000000000_citire_permisa`
Now you can test it directly with:
agy "What is my current Hidroelectrica bill?"
agy will fetch the current template sensor state and report the exact amount!