# balgerion/ha_pstryk architecture

> Architecture diagram of the GitHub repository balgerion/ha_pstryk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/balgerion/ha_pstryk
- Repository: https://github.com/balgerion/ha_pstryk

## Overview

Pstryk is a Home Assistant integration for monitoring electricity prices and energy costs. Users configure an API key and price options, then Home Assistant exposes price and financial-balance sensors; optional MQTT publishing provides EVCC-compatible forecasts. The README also documents 24-hour API forecasts, 48-hour MQTT/JSON data, best/worst hours, averages, and UTC-to-local conversion. The excerpts show setup and MQTT publishing, but not all coordinator-to-client or coordinator-to-entity calls, so those internal links are omitted where unverified.

Main entry points: [`custom_components/pstryk/__init__.py`](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/__init__.py) (Entry setup), [`custom_components/pstryk/mqtt_common.py`](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_common.py) (MQTT publishing), [`custom_components/pstryk/config_flow.py`](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/config_flow.py) (Config flow), [`custom_components/pstryk/mqtt_publisher.py`](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_publisher.py) (EVCC formatter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Setup &amp; configuration"]
  node_config["Config flow<br/>[config_flow.py]"]
  node_integration["Entry setup<br/>[__init__.py]"]
  node_constants["Integration settings<br/>[const.py]"]
end

subgraph group_data["Price and cost data"]
  node_api_client["API client<br/>[api_client.py]"]
  node_price_coordinator["Price updates"]
  node_cost_coordinator["Energy cost updates"]
end

subgraph group_entities["Home Assistant entities"]
  node_price_sensors["Price sensors<br/>[sensor.py]"]
  node_cost_sensors["Cost and balance sensors<br/>[sensor.py]"]
  node_json_sensors["JSON price sensors<br/>[sensor.py]"]
  node_diagnostics["Diagnostics<br/>[diagnostics.py]"]
end

subgraph group_mqtt["MQTT publishing"]
  node_mqtt_publisher["EVCC formatter<br/>[mqtt_publisher.py]"]
  node_mqtt_common["MQTT publishing<br/>[mqtt_common.py]"]
end

node_user(("Home Assistant user"))
node_pstryk_api{{"Pstryk API"}}
node_ha_mqtt{{"Home Assistant MQTT"}}

node_user -->|"configures"| node_config
node_config -->|"validates key"| node_pstryk_api
node_integration -->|"forwards setup"| node_price_sensors
node_integration -->|"creates publisher"| node_mqtt_publisher
node_integration -->|"starts publishing"| node_mqtt_common
node_mqtt_common -->|"formats prices"| node_mqtt_publisher
node_mqtt_common -->|"publishes forecasts"| node_ha_mqtt
node_price_coordinator -.->|"fetches forecasts"| node_pstryk_api
node_cost_coordinator -.->|"fetches cost data"| node_pstryk_api

click node_config "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/config_flow.py"
click node_integration "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/__init__.py"
click node_constants "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/const.py"
click node_api_client "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/api_client.py"
click node_price_coordinator "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/update_coordinator.py"
click node_cost_coordinator "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/energy_cost_coordinator.py"
click node_price_sensors "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py"
click node_cost_sensors "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py"
click node_json_sensors "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py"
click node_diagnostics "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/diagnostics.py"
click node_mqtt_publisher "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_publisher.py"
click node_mqtt_common "https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_common.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_integration,node_constants,node_user toneBlue
class node_api_client,node_price_coordinator,node_cost_coordinator toneAmber
class node_price_sensors,node_cost_sensors,node_json_sensors,node_diagnostics,node_pstryk_api toneMint
class node_mqtt_publisher,node_mqtt_common toneRose
class node_ha_mqtt toneIndigo
```

## Components

### Setup & configuration

- [Config flow](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/config_flow.py): `custom_components/pstryk/config_flow.py`
- [Entry setup](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/__init__.py): `custom_components/pstryk/__init__.py`
- [Integration settings](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/const.py): `custom_components/pstryk/const.py`

### Price and cost data

- [API client](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/api_client.py): `custom_components/pstryk/api_client.py`
- [Price updates](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/update_coordinator.py): `custom_components/pstryk/update_coordinator.py`
- [Energy cost updates](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/energy_cost_coordinator.py): `custom_components/pstryk/energy_cost_coordinator.py`

### Home Assistant entities

- [Price sensors](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py): `custom_components/pstryk/sensor.py`
- [Cost and balance sensors](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py): `custom_components/pstryk/sensor.py`
- [JSON price sensors](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/sensor.py): `custom_components/pstryk/sensor.py`
- [Diagnostics](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/diagnostics.py): `custom_components/pstryk/diagnostics.py`

### MQTT publishing

- [EVCC formatter](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_publisher.py): `custom_components/pstryk/mqtt_publisher.py`
- [MQTT publishing](https://github.com/balgerion/ha_pstryk/blob/main/custom_components/pstryk/mqtt_common.py): `custom_components/pstryk/mqtt_common.py`

### Other components

- **Home Assistant user**
- **Pstryk API**
- **Home Assistant MQTT**

## Connections

- Home Assistant user → Config flow: configures (evidence: `README.md`)
- Config flow → Pstryk API: validates key (evidence: `custom_components/pstryk/config_flow.py`)
- Entry setup → Price sensors: forwards setup (evidence: `custom_components/pstryk/__init__.py`)
- Entry setup → EVCC formatter: creates publisher (evidence: `custom_components/pstryk/__init__.py`)
- Entry setup → MQTT publishing: starts publishing (evidence: `custom_components/pstryk/__init__.py`)
- MQTT publishing → EVCC formatter: formats prices (evidence: `custom_components/pstryk/mqtt_common.py`)
- MQTT publishing → Home Assistant MQTT: publishes forecasts (evidence: `custom_components/pstryk/mqtt_common.py`)
- Price updates → Pstryk API: fetches forecasts
- Energy cost updates → Pstryk API: fetches cost data
