Grid-Aware Energy Load Shifter
Shift heavy residential loads to the cheapest electricity hours using Home Assistant energy data.
Quick Start
CODEBLOCK0
Connection
Two paths to reach Home Assistant:
- 1. MCP (preferred): If the HA MCP server is configured, use
mcporter call homeassistant.<tool> directly. - REST API: Use
python3 {baseDir}/scripts/ha_bridge.py. Requires HA_URL and HA_TOKEN environment variables.
Security
Required credentials:
| Variable | Description |
|---|
| INLINECODE4 | Home Assistant base URL (e.g. http://homeassistant.local:8123) |
| INLINECODE6 |
Home Assistant Long-Lived Access Token |
Least-privilege recommendations:
- - Create a dedicated Home Assistant user account for this skill (e.g.
openclaw-energy) - Generate a Long-Lived Access Token from that account only
- Limit the account's entity access to energy-related entities if your HA setup supports entity-level permissions
- Test with read-only commands first (
discover, energy-summary) before enabling device control
Domain allowlist: The call-service command restricts actions to energy-related domains only: switch, automation, script, climate, water_heater, input_boolean, input_number, number. All other domains (e.g. lock, alarm_control_panel) are blocked with exit code 2.
Commands
| Command | What it does | Example |
|---|
| INLINECODE21 | List all energy entities | INLINECODE22 |
| INLINECODE23 |
One-shot dashboard (prices + consumption + solar + storage) |
ha_bridge.py energy-summary |
|
status <entity> | Read a single entity's state and attributes |
ha_bridge.py status sensor.electricity_price |
|
call-service <d/s> | Call an energy-related HA service (restricted to allowed domains) |
ha_bridge.py call-service switch/turn_on --entity-id switch.ev_charger |
|
history <entity> | Get state changes over last N hours |
ha_bridge.py history sensor.grid_import --hours 24 |
All commands output JSON to stdout.
Load-Shifting Workflow
Follow these steps when asked about energy optimization:
- 1. Discover available energy entities: run
discover or INLINECODE32 - Read prices: Check pricing entities' state and attributes — look for:
- Hourly price arrays in
today /
tomorrow /
prices_today /
rates attributes
-
price_level attribute (CHEAP / NORMAL / EXPENSIVE)
- Current vs. average price comparison
- 3. Identify deferrable loads: Find
switch.* entities for schedulable devices (EV charger, pool pump, dishwasher, washer/dryer, water heater) - Find the cheapest window: Scan hourly prices for the contiguous N-hour block with the lowest sum (N = estimated run time of device)
- Execute: Call
switch/turn_on at the optimal time, or automation/trigger if the user has an existing automation
Interpreting Price Data
Different integrations expose prices differently:
- - Hourly arrays (Nordpool, ENTSO-e, Octopus): Read
today/tomorrow attributes → find cheapest hours - Price level (Tibber): Read
price_level → act when CHEAP or VERY_CHEAP - Real-time (Amber Electric): Read 5-minute pricing → shift loads immediately when cheap
- Utility meter tariffs: Read
sensor.*_peak vs sensor.*_offpeak → user's HA automations switch tariffs at configured times - Static TOU: Read
current_price attribute → compare against historical average
Cost Savings Estimate
When recommending a shift, show estimated savings:
CODEBLOCK1
Solar Self-Consumption
If solar sensors exist, align loads with peak production:
- - Read
sensor.forecast_solar_* or sensor.solcast_* for today's forecast - Shift loads to hours with highest expected production
- This avoids grid import entirely — savings = full retail rate × kWh shifted
HVAC Pre-Conditioning
HVAC is the largest residential load (40-50% of electricity). Pre-cool or pre-heat during cheap/solar hours so the home coasts through expensive peak periods:
- 1. Read
climate.* entities for current HVAC mode and setpoint - During cheapest window: lower cooling setpoint by 2-3F (pre-cool) or raise heating setpoint by 2-3F (pre-heat)
- During peak window: raise cooling setpoint by 2-3F to coast on thermal mass
- Savings estimate: 1.5-3 kW shifted × price differential × hours
Water Heater Scheduling
Electric water heaters (4.5 kW typical) are ideal deferrable loads:
- 1. Find
switch.water_heater or water_heater.* entities - Heat during cheapest/solar window to full temperature
- Turn off during peak hours (tank maintains temperature for 4-6 hours)
- Savings estimate: 4.5 kW × price differential × 3-4 hours/day
Battery Arbitrage
If home battery entities exist (sensor.battery_soc, sensor.powerwall_*, sensor.enphase_*):
- 1. Read current state of charge and charge/discharge rate limits
- Charge from grid during cheapest hours (or from solar)
- Discharge to home during peak price hours to avoid grid import
- Advanced: If battery supports grid export and VPP enrollment, discharge to grid during extreme price events ($2,000+/MWh)
- Savings estimate: batterycapacitykwh × (peakrate - valleyrate)
Demand Response / VPP Integration
For homes enrolled in utility demand response or virtual power plant programs:
- 1. Read demand response signal entities (if available via HA integration)
- When DR event active: shed non-critical loads, pre-cool/pre-heat, discharge battery
- Estimate DR payment: kW reduced × event duration × program rate
Entity Reference
For detailed entity patterns across providers, read: energy_entities.md
技能名称: grid-aware-energy-load-shifter
详细描述:
电网感知型能源负荷转移器
利用Home Assistant能源数据,将家庭重负荷转移至电价最低的时段。
快速开始
bash
查找HA中所有与能源相关的实体
python3 {baseDir}/scripts/ha_bridge.py discover
获取完整的能源仪表盘快照(电价、太阳能、消耗、电池)
python3 {baseDir}/scripts/ha_bridge.py energy-summary
开启电动汽车充电器
python3 {baseDir}/scripts/ha
bridge.py call-service switch/turnon --entity-id switch.ev_charger
连接方式
有两种方式连接Home Assistant:
- 1. MCP(推荐): 如果已配置HA MCP服务器,可直接使用 mcporter call homeassistant.。
- REST API: 使用 python3 {baseDir}/scripts/habridge.py。需要设置 HAURL 和 HA_TOKEN 环境变量。
安全设置
必需凭证:
| 变量 | 描述 |
|---|
| HAURL | Home Assistant基础URL(例如 http://homeassistant.local:8123) |
| HATOKEN |
Home Assistant长期访问令牌 |
最小权限建议:
- - 为此技能创建一个专用的Home Assistant用户账户(例如 openclaw-energy)
- 仅从该账户生成一个长期访问令牌
- 如果您的HA设置支持实体级权限,请将该账户的实体访问权限限制为仅与能源相关的实体
- 在启用设备控制之前,先用只读命令(discover、energy-summary)进行测试
域名白名单: call-service 命令仅允许操作与能源相关的域名:switch、automation、script、climate、waterheater、inputboolean、inputnumber、number。所有其他域名(例如 lock、alarmcontrol_panel)将被阻止,并返回退出代码2。
命令
| 命令 | 功能 | 示例 |
|---|
| discover | 列出所有能源实体 | habridge.py discover |
| energy-summary |
一次性仪表盘(电价 + 消耗 + 太阳能 + 储能) | habridge.py energy-summary |
| status
| 读取单个实体的状态和属性 | habridge.py status sensor.electricityprice |
| call-service | 调用与能源相关的HA服务(仅限于允许的域名) | habridge.py call-service switch/turnon --entity-id switch.ev_charger |
| history | 获取过去N小时内的状态变化 | habridge.py history sensor.gridimport --hours 24 |
所有命令均以JSON格式输出到标准输出。
负荷转移工作流程
当被问及能源优化时,请遵循以下步骤:
- 1. 发现可用的能源实体:运行 discover 或 energy-summary
- 读取电价:检查定价实体的状态和属性——查找:
- today / tomorrow / prices_today / rates 属性中的小时电价数组
- price_level 属性(CHEAP / NORMAL / EXPENSIVE)
- 当前电价与平均电价的比较
- 3. 识别可延迟负荷:查找可调度设备的 switch.* 实体(电动汽车充电器、泳池泵、洗碗机、洗衣机/烘干机、热水器)
- 找到最便宜的时段:扫描小时电价,找到总和最低的连续N小时时段(N = 设备的预估运行时间)
- 执行:在最佳时间调用 switch/turn_on,或者如果用户已有自动化规则,则调用 automation/trigger
解读电价数据
不同的集成以不同方式展示电价:
- - 小时数组(Nordpool、ENTSO-e、Octopus):读取 today/tomorrow 属性 → 找到最便宜的小时
- 电价等级(Tibber):读取 pricelevel → 当为CHEAP或VERYCHEAP时执行操作
- 实时电价(Amber Electric):读取5分钟定价 → 在电价便宜时立即转移负荷
- 电表费率:读取 sensor.peak 与 sensor.offpeak → 用户的HA自动化规则在配置的时间切换费率
- 静态分时电价:读取 current_price 属性 → 与历史平均值进行比较
成本节省估算
在建议转移负荷时,显示预估节省:
节省金额 = (当前电价 - 最便宜电价) × 设备功率(千瓦) × 运行时长(小时)
太阳能自发自用
如果存在太阳能传感器,将负荷与峰值发电时段对齐:
- - 读取 sensor.forecastsolar 或 sensor.solcast_ 获取今日预测
- 将负荷转移至预期发电量最高的时段
- 这可以完全避免从电网取电——节省金额 = 全额零售电价 × 转移的电量(千瓦时)
HVAC预调节
HVAC是最大的家庭负荷(占电力的40-50%)。在电价便宜/太阳能充足的时段进行预冷或预热,使房屋在昂贵的峰值时段依靠热惯性维持温度:
- 1. 读取 climate.* 实体,获取当前HVAC模式和设定温度
- 在最便宜时段:将制冷设定温度降低2-3华氏度(预冷)或将制热设定温度提高2-3华氏度(预热)
- 在峰值时段:将制冷设定温度提高2-3华氏度,依靠热惯性维持
- 节省估算:转移的1.5-3千瓦 × 电价差 × 小时数
热水器调度
电热水器(典型功率4.5千瓦)是理想的可延迟负荷:
- 1. 查找 switch.waterheater 或 waterheater.* 实体
- 在最便宜/太阳能充足的时段加热至满温度
- 在峰值时段关闭(水箱可维持温度4-6小时)
- 节省估算:4.5千瓦 × 电价差 × 每天3-4小时
电池套利
如果存在家庭电池实体(sensor.batterysoc、sensor.powerwall、sensor.enphase_):
- 1. 读取当前荷电状态和充放电速率限制
- 在最便宜时段(或利用太阳能)从电网充电
- 在电价峰值时段向家庭放电,避免从电网取电
- 高级操作:如果电池支持向电网放电并已加入虚拟电厂计划,在极端电价事件(每兆瓦时超过2000美元)时向电网放电
- 节省估算:电池容量(千瓦时) × (峰值电价 - 谷值电价)
需求响应 / 虚拟电厂集成
对于已加入公用事业需求响应或虚拟电厂计划的家庭:
- 1. 读取需求响应信号实体(如果通过HA集成可用)
- 当需求响应事件激活时:切断非关键负荷、预冷/预热、放电电池
- 估算需求响应收益:减少的功率(千瓦) × 事件持续时间 × 项目费率
实体参考
有关各供应商的详细实体模式,请阅读:energy_entities.md