Skip to content

Latest commit

 

History

History
440 lines (321 loc) · 20.3 KB

README.md

File metadata and controls

440 lines (321 loc) · 20.3 KB

Pila + Home Assistant

Monitor and control your Pila battery from Home Assistant over MQTT.

Contents

Compatibility

Requirement Notes
Pila firmware 1.2 or newer
Home Assistant 2024.x or newer (MQTT discovery v2 schema)
MQTT broker Any MQTT 3.1.1 broker. Mosquitto add-on recommended.
Network Pila and Home Assistant must be on the same local network
TLS Plaintext on port 1883 only today. TLS support is planned.

Setup

Total time: about 5 minutes.

1. Install an MQTT broker in Home Assistant

If you already have one, skip to step 2. For deeper detail, see Home Assistant's MQTT integration docs.

  1. Settings → Add-ons → Add-on Store (sometimes called Apps)
  2. Install Mosquitto broker
  3. Start the add-on; enable "Start on boot" and "Watchdog"
  4. Settings → Devices & services → Add Integration → MQTT. Home Assistant auto-detects the broker.

MQTT integration with Mosquitto

2. Connect on the Pila screen

On your Pila:

  1. Open Settings → Home Assistant

  2. The IP Address field is pre-populated — Pila does an mDNS sweep for homeassistant.local on boot and fills in what it finds. If the address looks right, use it. Otherwise, find it manually in HA under Settings → System → Network and overwrite.

    Finding HA IP under Settings → System → Network
  3. Enter your Home Assistant username and password

  4. Tap Save & Connect

Pila Home Assistant screen

The status indicator turns green when connected. The connection persists across reboots.

Have more than one Pila? You only need to do this once, on any Pila. It securely shares your Home Assistant settings with every other Pila in your home, and they all connect right away. Each Pila shows up in Home Assistant as its own device. A Pila you add later picks up the settings as soon as it joins your other Pilas.

💡 Optional: dedicated HA user. For tighter security, create a non-admin HA user just for Pila (Settings → People → Users → Add User) and use those credentials in step 3. Your normal credentials work fine otherwise.

3. Verify

In Home Assistant, Settings → Devices & services → MQTT should show your Pila with all entities listed below.

Entities

Home Assistant generates entity IDs from your Pila's device name. If your Pila is called Kitchen Pila, entities show up as sensor.kitchen_pila_battery_soc, switch.kitchen_pila_back_lower_outlet, and so on. The examples below use your_pila as a placeholder — replace it with your Pila's slug.

⚠️ The slug is sticky. Home Assistant bakes your Pila's name into entity IDs the first time it connects. If you rename the Pila later in the app, the friendly name updates in HA but the entity IDs stay the same. The fastest fix: in HA, go to Settings → Devices & services → MQTT → your Pila, open the ⋮ menu, and choose Recreate entity IDs. HA will regenerate every entity_id from the current device name in one click (requires HA 2025.6 or newer).

Power (instantaneous)

Name Unit Description
Total Usage W Total load currently being powered by the Pila (battery + grid + solar combined).
Battery Charge / Discharge Rate W Signed power into/out of the battery pack. Positive = charging, negative = discharging.
Total Solar Input W Power currently arriving from solar.
Total AC Input W Power currently flowing in from the grid.

Battery

Name Unit Description
Battery SOC % State of charge, 0–100.
Battery energy remaining Wh Energy left in the pack at the current state of charge.
Backup Forecast h Estimated hours of backup runtime at current load.
Pila Status — Human-readable summary. One of: Solar powering devices, Battery powering devices, Charging from solar, Charging from utility, Utility powering devices, Idle.

Grid

Name Unit Description
Grid Status — One of: on_grid (connected to and using utility), off_grid (islanded — running on battery/solar), idle_off_grid (no grid and no AC output), unknown.

Lifetime energy totals

Cumulative total_increasing counters designed for the Energy Dashboard.

Name Unit Description
Pila Lifetime Import Wh Total energy imported from the grid through Pila over the device's lifetime.
Battery Lifetime Charge Wh Total energy charged into the battery pack over its lifetime.
Battery Lifetime Discharge Wh Total energy discharged from the battery pack over its lifetime.

Per-outlet (one set per outlet)

For each AC and USB-C outlet:

Entity Type Unit Description
{outlet name} switch — Turn the outlet on or off. State reflects relay state.
{outlet name} power sensor W Power currently flowing through the outlet.
{outlet name} Lifetime Energy sensor Wh Cumulative energy delivered through the outlet.

Outlet naming. If you've assigned an appliance name to an outlet in the Pila app (e.g. "Fridge"), Home Assistant uses that name. Otherwise it falls back to the orientation default ("Left USB Port", "Middle USB Port", "Right USB Port", "Front Left Outlet", "Front Right Outlet", "Back Upper Outlet", "Back Lower Outlet", etc.). The slug is derived from this name, so a default usb_1 becomes sensor.your_pila_right_usb_port_power, not sensor.your_pila_usb_1_power. Confirm the exact entity_id in Settings → Devices & services → MQTT → your Pila before referencing it in YAML.

Renaming an outlet in the Pila app updates the friendly name in HA but does not change the entity_id. Use the device's ⋮ → Recreate entity IDs menu in HA (2025.6+) to regenerate them.

Temperatures

Name Unit Description
Battery Max Temperature °C Warmest cell in the battery pack.
Battery Min Temperature °C Coolest cell in the battery pack.
Internal Max Temperature °C Warmest reading across the battery and power electronics inside your Pila.
CPU Temperature °C Your Pila's processor.

Home Assistant shows temperatures in the unit set under Settings → System → General, so you may see °F.

Fridge and freezer sensors (one set per paired sensor)

For each Pila fridge or freezer sensor paired to an appliance in the Pila app:

Entity Unit Description
{appliance name} fridge temperature °F Temperature inside the fridge.
{appliance name} fridge humidity % Humidity inside the fridge.
{appliance name} fridge light lx Light level inside the fridge. Jumps when the door opens.

A freezer sensor adds the same three entities, named {appliance name} freezer .... If a sensor stops reporting, its entities show Unknown until it comes back.

A sensor you pair after Pila connects to Home Assistant shows up the next time Pila republishes its discovery config, for example after a Home Assistant restart.

Controls

Name Type Values Description
Grid mode select on_grid, off_grid Switch Pila between on-grid and manual off-grid (island) mode.

Reliability

The integration recovers automatically from common failures. No manual reconnect needed.

  • Home Assistant Core restart (from inside the HA UI) — Pila listens for the homeassistant/status birth message and republishes its discovery config + state when HA comes back.
  • Mosquitto restart (e.g. broker add-on update) — Pila's MQTT client auto-reconnects with exponential backoff (1s → 120s).
  • Home Assistant OS reboot — both of the above apply; Pila republishes once the broker is reachable again.
  • Pila power loss or network drop — Pila reconnects on its own when it returns.

All Pila entities flip to Unavailable in HA within roughly 90 seconds of any failure (via the availability_topic and MQTT keepalive) and recover automatically when both sides are back online.

Home Assistant Energy Dashboard

Wire Pila into Settings → Dashboards → Energy:

Energy Dashboard tile Pila entity
Grid consumption Pila Lifetime Import
Battery in (charge) Battery Lifetime Charge
Battery out (discharge) Battery Lifetime Discharge

The Energy Dashboard uses cumulative counters, not instantaneous power. Don't wire Battery Charge / Discharge Rate here.

Solar readings from Home Assistant

This is how your Pila works with almost any solar or battery system. Pila connects to Enphase directly. For everything else, check whether your system is already on your network and shows up in Home Assistant. That covers inverters like SolarEdge, Fronius, or SMA, battery systems like Tesla Powerwall, EG4, or FranklinWH, and energy monitors like Sense or Shelly. If it does, Home Assistant can pass its live solar production to your Pila, so your Pila can charge from your excess solar.

Anything that reports current solar power in W or kW works. Integrations that only report daily energy in kWh won't.

Home Assistant sends the readings to Pila every 10 seconds with a blueprint. Every Pila connected to this Home Assistant receives them.

1. Import the blueprint

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or go to Settings → Automations & scenes → Blueprints → Import Blueprint and paste:

https://github.com/PilaEnergy/pila-home-assistant/blob/main/blueprints/automation/pila/send_solar_to_pila.yaml

2. Create the automation

Open Settings → Automations & scenes → Blueprints → Send solar readings to Pila → Create Automation and pick:

Input What to pick
Solar power sensor Your current solar production, in W or kW.
Grid power sensor (optional) Power flowing between your home and the grid, in W or kW. Leave empty if you don't have one.
Grid sensor reports export as positive Turn on if your grid sensor shows a positive value while you're sending power to the grid.

Without a grid sensor, Pila assumes your home uses 400 W and treats solar above that as excess it can charge from.

3. Turn it on on your Pila

Your Pila needs to be connected to Home Assistant first (see Setup). Then, on your Pila, open Settings → Solar → Home Assistant and tap Use Home Assistant. Once readings arrive, the screen shows your current solar production.

If Home Assistant stops sending readings for 30 minutes, Pila falls back to its own solar estimate until they come back.

Writing your own automation

You can also publish the readings yourself. Pila listens on pila/solar for JSON:

Key Unit Notes
site_solar_p_W W Required. Current solar production.
site_grid_p_W W Optional. Positive while importing from the grid, negative while exporting.
alias: Send solar readings to Pila
trigger:
  - platform: time_pattern
    seconds: "/10"
action:
  - service: mqtt.publish
    data:
      topic: pila/solar
      payload: >
        {"site_solar_p_W": {{ states('sensor.your_solar_power') | float(0) | round(0) | int }},
         "site_grid_p_W": {{ states('sensor.your_grid_power') | float(0) | round(0) | int }}}
mode: single

examples/automations/send-solar-to-pila.yaml

Example Lovelace cards

Drop these into a dashboard via Edit dashboard → Add card → Manual. Replace your_pila in entity IDs with your Pila's slug (e.g. kitchen_pila).

Battery SOC dial with backup forecast

Battery SOC card

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: sensor.your_pila_backup_forecast
        name: Backup Time Remaining
        icon: mdi:timer-outline
  - type: gauge
    entity: sensor.your_pila_battery_soc
    name: Battery Level
    needle: true
    severity:
      green: 50
      yellow: 15
      red: 0
  - type: sensor
    entity: sensor.your_pila_battery_soc
    graph: line
    name: 24h History
    detail: 2
    hours_to_show: 24

examples/dashboards/battery-soc-card.yaml

Power flow overview

Power flow overview card

type: vertical-stack
cards:
  - type: glance
    title: Pila Power Flow
    columns: 4
    entities:
      - entity: sensor.your_pila_total_solar_input
        name: Solar
      - entity: sensor.your_pila_total_ac_input
        name: Grid
      - entity: sensor.your_pila_battery_charge_discharge_rate
        name: Battery
      - entity: sensor.your_pila_total_usage
        name: Load
  - type: entities
    entities:
      - entity: sensor.your_pila_pila_status
        name: Status
      - entity: sensor.your_pila_grid_status
        name: Grid
      - entity: sensor.your_pila_battery_soc
        name: Battery SOC
      - entity: sensor.your_pila_backup_forecast
        name: Backup Forecast

examples/dashboards/power-flow-overview.yaml

USB-C stacked history

USB-C stacked history card

type: vertical-stack
cards:
  - type: history-graph
    title: USB Power History
    hours_to_show: 1
    entities:
      - entity: sensor.your_pila_left_usb_port_power
        name: Left
      - entity: sensor.your_pila_middle_usb_port_power
        name: Middle
      - entity: sensor.your_pila_right_usb_port_power
        name: Right
  - type: entities
    entities:
      - entity: sensor.your_pila_left_usb_port_power
        name: Left USB Power
      - entity: sensor.your_pila_middle_usb_port_power
        name: Middle USB Power
      - entity: sensor.your_pila_right_usb_port_power
        name: Right USB Power

examples/dashboards/usb-power-history.yaml

Example automations

Paste into Settings → Automations → Add → Edit in YAML.

Low-SOC notification

alias: Pila low battery notification
trigger:
  - platform: numeric_state
    entity_id: sensor.your_pila_battery_soc
    below: 20
    for:
      minutes: 1
action:
  - service: notify.notify
    data:
      title: Pila battery low
      message: >
        Pila is at {{ states('sensor.your_pila_battery_soc') }}%.
        Estimated {{ states('sensor.your_pila_backup_forecast') }} hours of backup remaining.
mode: single

examples/automations/low-soc-notification.yaml

Grid outage notification

alias: Pila grid outage notification
trigger:
  - platform: state
    entity_id: sensor.your_pila_grid_status
    to: off_grid
action:
  - service: notify.notify
    data:
      title: Pila is off-grid
      message: >
        Pila switched to off-grid mode. Currently {{ states('sensor.your_pila_pila_status') | lower }}.
        Battery at {{ states('sensor.your_pila_battery_soc') }}%.
mode: single

examples/automations/grid-outage-notification.yaml

Shed non-essential load on low battery

Turn off a non-essential outlet when battery drops below 30 % during a grid outage.

alias: Pila shed non-essential load on low battery
trigger:
  - platform: numeric_state
    entity_id: sensor.your_pila_battery_soc
    below: 30
condition:
  - condition: state
    entity_id: sensor.your_pila_grid_status
    state: off_grid
action:
  - service: switch.turn_off
    target:
      entity_id: switch.your_pila_front_right_outlet
mode: single

examples/automations/turn-off-outlet-on-low-soc.yaml

Troubleshooting

Status stuck on "Disconnected" on the Pila screen. Check that (a) the HA IP is correct and stable (set a DHCP reservation if needed), (b) the username/password work in a browser, (c) the Mosquitto add-on is running, and (d) port 1883 is reachable from the local network (nc -vz <HA_IP> 1883). Reboot Pila and watch the indicator.

Pila is connected but no entities appear. In Home Assistant: Settings → Devices & services → MQTT → Configure → Listen to a topic, subscribe to homeassistant/device/pila/#. You should see a config payload shortly after Pila connects. If you see the payload but no device, restart HA once — discovery occasionally fails to register on first push.

Entities show "Unavailable" forever. On Pila 1.2+, this means Pila has genuinely lost its broker connection or the credentials are bad — recovery is automatic when both sides return, so persistent Unavailable is real. Subscribe to pila/availability/# on the HA broker: if the retained payload is offline, Pila isn't talking to the broker (check the Pila screen for status, verify credentials, check the broker is running). If it's online but entities are still Unavailable, open an issue with the raw pila/state/# payload.

Entities show "Unknown" forever. Subscribe to pila/state/# to confirm state messages are flowing. If they are, the value template may not be finding the key — open an issue with the raw payload.

Outlet switch doesn't change state when I toggle it. Relay commands are fire-and-forget; state reflects what Pila reports back. Give it 2–3 seconds. If it never changes, check whether a Pila-side schedule or timer is fighting your command.

Pila says "Waiting for solar data from Home Assistant." Check that the solar automation is turned on and that your solar sensor has a number, not unavailable. In Home Assistant, Settings → Devices & services → MQTT → Configure → Listen to a topic, subscribe to pila/solar. You should see a reading every 10 seconds.

Disconnecting from Home Assistant. Tap Disconnect on the Pila Home Assistant screen. The MQTT device goes offline in HA; the entities remain in HA's registry until you delete the device manually under Settings → Devices & services → MQTT.

Disconnecting with more than one Pila. Disconnect on any Pila disconnects all the Pilas in your home, and Forget Home Assistant clears the settings from all of them.

For anything else, open an issue with your Pila firmware version, Home Assistant version, broker, and what you've tried.

Advanced: MQTT topics

For users who want to bypass HA discovery and consume topics directly.

Purpose Topic Retained
Discovery config (published by Pila) homeassistant/device/pila/{device_id}/config no
State (published by Pila) pila/state/{device_id} no
Availability (published by Pila, also the LWT) pila/availability/{device_id} (online / offline) yes
HA Core birth/will (subscribed by Pila) homeassistant/status —
Commands (subscribed by Pila) pila/switch/outlet/{device_id} —
Solar readings (subscribed by Pila) pila/solar no

State messages are published at QoS 2. The discovery config is re-published every time Pila connects to the broker AND every time Home Assistant Core publishes online on homeassistant/status, so HA Core restarts auto-recover without any user action.

License

See LICENSE.