# Connect pvnode with Home Assistant

This guide shows how to integrate the pvnode Forecast API via the built-in
[RESTful Sensor](https://www.home-assistant.io/integrations/rest/) in
Home Assistant — without any custom component.

:::note
The guide below currently still uses the V1 API. We will update it once the migration to
V2 is complete.
:::

## Prerequisites

- A running Home Assistant installation
- A pvnode API key ([create a key here](https://pvnode.com/settings/api-keys))
- Access to `configuration.yaml` (File editor add-on or SSH)

## 1. Store the API key securely

Open `secrets.yaml` in the `config/` directory (create it if it doesn't exist):

```yaml
pvnode_api_key: "Bearer YOUR_API_KEY"
```

## 2. REST sensor in `configuration.yaml`

Add the following block to your `configuration.yaml` and adjust the
location and PV configuration:

```yaml
rest:
  - resource: https://api.pvnode.com/v1/forecast/
    method: GET
    headers:
      Authorization: !secret pvnode_api_key
    params:
      latitude: 48.27564
      longitude: 11.83972
      slope: 30
      orientation: 180
      pv_power_kw: 10
      forecast_days: 2                 # number of forecast days
      required_data: "pv_watts,temp"   # power and temperature are returned
    scan_interval: 3600                # update every 60 minutes
    sensor:
      - name: "pvnode Power Now"
        unique_id: pvnode_power_now
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        value_template: >
          {% set rounded = now().replace(second=0, microsecond=0, minute=(now().minute // 15) * 15) %}
          {% set target = rounded.astimezone(timezone('UTC')).strftime('%Y-%m-%d %H:%M:%S') %}
          {% set match = value_json.values | selectattr('dtm', 'eq', target) | list %}
          {{ match[0].pv_watts | round(0) if match else 0 }}
        json_attributes:
          - values
          - latitude
          - longitude
          - slope
          - orientation
          - elevation
```

### Parameters at a glance

| Parameter                | Description                                                                                              |
|--------------------------|-----------------------------------------------------------------------------------------------------------|
| `latitude` / `longitude` | Location of the PV system                                                                                |
| `slope`                  | Tilt of the modules in degrees (0 = flat, 90 = vertical)                                                 |
| `orientation`            | Orientation in degrees (0 = north, 90 = east, 180 = south, 270 = west)                                   |
| `pv_power_kw`            | Installed power in kWp                                                                                   |
| `forecast_days`          | Number of forecast days (0–7)                                                                            |
| `required_data`          | Which fields the API should return - find all data fields [here](/docs/en/guides/data-columns)           |

A complete overview of all parameters and data fields is in
the [Forecast API documentation](/docs/en/endpoints/forecast).

## 3. Reload the configuration

After saving, in Home Assistant go to: **Developer Tools → YAML →
Reload all YAML configuration**. On first setup, a
restart is required.

Under **Developer Tools → States**, search for the sensor `sensor.pvnode_power_now`
— the state shows the current power in watts, and in the attributes
you'll find the full 15-minute forecast.

## 4. Visualize the forecast as a chart

With the [ApexCharts Card](https://github.com/RomRider/apexcharts-card) (installable via
HACS) you can plot the full forecast series as a curve:

```yaml
type: custom:apexcharts-card
header:
  show: true
  title: PV Forecast
graph_span: 48h
span:
  start: day
series:
  - entity: sensor.pvnode_power_now
    name: pvnode Forecast
    type: line
    stroke_width: 2
    extend_to: false
    data_generator: |
      return entity.attributes.values.map(point => {
        const utcTime = new Date(point.dtm + 'Z').getTime();
        return [utcTime, point.pv_watts];
      });
```

## Use cases

With the pvnode forecast in Home Assistant you can, for example:

- **Control a wallbox:** charge the EV when sufficient solar production is expected
- **Schedule a heat pump:** run hot water preparation during surplus periods
- **Optimize a battery:** fully charge before expected periods of bad weather
- **Load shifting:** start the washing machine, dryer or dishwasher at peak times

## Tips

- **Higher resolution with Nowcasting:** with the Nowcasting add-on, the forecast
  updates every 10 minutes based on live satellite data. Then set
  `scan_interval: 600`.
- **Multiple systems:** for east/west roofs or multiple strings, simply create
  several REST sensors with different `unique_id` values.
