I recover the balance of his bank account and the last operations (in test)

Objective

My goal was to connect my bank account to Home Assistant to track my balance and transactions in real time. To do this, I used the Powens API (formerly Budget Insight), a platform that provides free access to bank data in a secure and PSD2 compliant manner.

I have created a Powens account

I registered on the Powens website to create an account. Powens offers a banking aggregation solution that allows financial information to be retrieved via APIs. This is perfect for my home automation project.

Who is Powens?

Powens (formerly Budget Insight) is a leading platform in the field ofbanking aggregation andOpen Banking. With PSD2 compliant APIs (Payment Services Directive), Powens enables developers and businesses to securely access users’ banking data (with their consent). Their technology is used by fintechs, banks and financial management applications to offer innovative services such as expenditure analysis, transaction categorisation or budget management.

In my case, I use a small part Powens' potential via their sandbox, a test environment that allows me to log in to my bank account to retrieve information like balance and latest transactions. This use generates very little traffic and stays within the framework of the free offers offered by Powens for developers and small projects. This allows me to integrate this data into my home automation system at no additional cost, while benefiting from the power and reliability of their platform.

I think it is a very good initiative from Powens to allow that. By offering free access to their sandbox, they enable home automation hackers like me to experiment and create customised solutions. These hackers, often passionate and influential in their professional or personal circles, can then recommend solid and serious platforms like Powens to wider services or companies. It is a win-win strategy: Powens gains visibility and credibility, while users benefit from a reliable and efficient tool.

I added a workspace

Once connected, I created a new workspace. A workspace is a workspace that brings together my configurations and applications. I named mine Sigalou-Domotics to keep a clear record of my project.

I have added an area

Then I added a domain to my workspace. This allows configuring the environment for API queries. I chose the domain sigalou.

The setup took a few minutes. Once completed, I noted that API commands had to be sent to the following address: https://sigalou-sandbox.biapi.pro.

I added an app

The addition of an app is mandatory to establish the connection with my bank account. This application generates unique identifiers (client ID and secret client) that will be used to authenticate API requests.

This application has provided me with a Client ID and one secret client. I have noted them carefully, as they will be needed to create an API user.

I installed Postman for Windows

To interact with the Powens API, I used Postman, a very handy tool for sending and testing API queries. Postman allows you to simulate API calls and view responses in real time.

I added a user via the API

To create a user, I sent a POST command to the following URL: https://sigalou-sandbox.biapi.pro/2.0/auth/init. I used the previously retrieved ID client and secret client.

In the body of the application (Body / raw / JSON), I added:

{
"_id customer": "herethe _id_clientrecovered_plus_haut",
"_secret customer": herethe _secret _clientrecovered _plus _haut
}

In the reply, I noted the id_user and auth _token, which will be used for the next steps.

I got a temporary code

This temporary code is necessary to establish the connection with my bank account. To obtain it, I sent a GET command to the following URL: https://sigalou-sandbox.biapi.pro/2.0/auth/token/code?type=singleAccess.

I used the auth _token previously retrieved from Authorization / Bearer Token. In the reply, I noted the code temporary.

I launched the Webview to connect my bank account

To establish the connection with my bank account, I built the Webview URL in Link Builder and started the connection by clicking on Open and Test

 

 

I tested the recovery of the account balance

To recover the balance of my account, I sent a GET order to the following URL: https://sigalou-sandbox.biapi.pro/2.0/users/1/accounts, where 1 is my id _user.

In the reply, I recovered the balance of my account, which was 599.84€ during my test.

I tested the recovery of the last transactions

To retrieve the latest transactions, I sent a GET command to the following URL: https://sigalou-sandbox.biapi.pro/2.0/users/1/transactions?limit=10, where 1 is my id _user.

The answer contained a JSON with my last 10 transactions.

I turned API queries into Home Assistant sensors

To integrate this data into Home Assistant, I created two REST sensors: _bank transactions and _bank balance. Here is the code used:

- platform: rest name: "_bank transactions" resource: https://sigalou-sandbox.biapi.pro/2.0/users/1/transactions params: limit: 25 headers: Authorization: !secret token_bank scan_interval: 31536000 # Disables automatic updates (1 year) json_attributes: - first_date - last_date - transactions - total value_template: "{{ now().strftime('%d/%m/%Y %H:%M:%S') }}" - platform: rest name: "_bank balance" resource: https://sigalou-sandbox.biapi.pro/2.0/users/1/accounts headers: Authorization: !secret token_bank scan_interval: 31536000 # Disables automatic updates value_template: "{{value_json.balance }}" unit_of _measurement: "€"

These sensors are to be placed in the file sensors.yaml.

In order for the token to be sent correctly, I added this line to the file secrets.yaml :

token_bank: Bearer a8N5q1aUVEa33wl0dCJM...

Once configured, the sensors appeared in Home Assistant:

Observations on these sensors:

  • The refresh is set to 3153600 seconds (approximately 1 year), as I have planned to update the data via daily automation at noon. This will allow me to receive notifications based on the balance or the latest transactions.
  • Sensors can be simplified. I had initially included data like first_date and last_date, but I finally withdrew them because they were not useful in production.
  • The parameter limit: 25 can be adjusted according to the size of the screen and the card chosen on the dashboard.

I added templates to calculate what I need

In the file templates.yaml, under sensor, I added these templates:

- name: "_a _venir _montant transactions" state: >- {% set transactions = state_attr('sensor.transactions_bank', 'transactions') %} {% set total = namespace(amount=0) %} {% for transaction in transactions if transaction.coming %} {% set total.amount = total.amount + transaction.value %} {% endfor %} {{ total.amount }} unit _of _measurement: "€" - name: _id single "available _ balance": sensor.balance _available unit _of _measurement: "€" state: >- {% set balance = states('sensor.solde _banque') | float %} {% set depenses = states('sensor.transactions _a _venir _montant') | float %} {{ (balance + expenditure) | round(2) }}
  • The sensor _a _venir _montant Transactions calculates the total amount of future transactions (such as scheduled drawdowns).
  • The sensor _ balanceavailable calculates the actual balance by subtracting future transactions from the current balance.

I add automation to refresh the data

As I explained earlier, I voluntarily deactivated the automatic refresh of the REST sensors by assigning them a very high scan_interval value (31536000 seconds, i.e. about 1 year). This allows me to manually control when data is refreshed, rather than refreshing it every x minutes. This approach is more tailored to my needs, as I plan to use this data to trigger notifications based on my balance or the latest important transactions.

To manage this, I added an automation in Home Assistant that updates my two sensors (_bank balance and _bank transactions) every day at noon. Here is the code for this automation:

alias: Update Bank account description: "" Triggers: - trigger: time at: "12:00:00" conditions: [] actions: - action: homeassistant.update _entity data: entity_id: - sensor.balance _bank - sensor.transactions _bank mode: single

This automation is simple but effective: it triggers an update of the sensors at noon each day. This allows me to keep my data up to date without overloading the API or my system with unnecessary queries. In addition, it gives me the ability to add other actions later, such as sending notifications or running scripts based on the recovered data.

I realize the maps and the screen of the dashboard

After configuring the sensors and automations, I designed a dashboard in Home Assistant to visualise my banking data in a clear and organised way. Here is the final result of my tests:

Here is the complete code of the page, which I will break down to explain each part:

Type: max _columns sections: 4 path: ss sections: - type: grid cards: - type: entity entity: sensor.solde _bank name: Bank balance icon: mdi:bank-transfer grid_options: columns: full card_mod: style: | ha-card { padding: 4px; border-radius: 15px; } .icon ha-state-icon { --mdc-icon-size: 50px!important; /* Icon size */ margin-bottom: 10px; } - type: markdown content: > {% set transactions = state_attr('sensor.transactions_bank', 'transactions') %} ## TODAY {% for transaction in transactions %} {% if not transaction.coming %} {% if transaction.date %} {% set date_obj = transaction.date | as_datetime %} {% set formatted _date = date_obj.strftime('%d/%m/%Y') %} {% else %} {% set formatted _date = 'Date unknown' %} {% endif %} {% if transaction.type == 'card' %💳 {{ formatted _date }} {% elif transaction.type == 'bank' %} 🏦 {{ formatted _date }} {% elif transaction.type == 'check' %} 📝 {{ formatted _date }} {% elif transaction.type == 'transfer' %💸 {{ formatted _date }} {% else %⚪ {{ formatted _date }} {% endif %}
              <strong>
                {% if transaction.value &gt; 0 %} 🟢 {{ transaction.formatted _value }} {% else %} 🔴 {{ transaction.formatted _value }} {% endif %}
              </strong>
              <small>{{transaction.wording }}</small>
            {% endif %} {% endfor %} grid _options: columns: 24 rows: auto - type: vertical-stack cards: - type: markdown content: &gt; {% set transactions = state_attr('sensor.transactions_bank', 'transactions') %} ## FUTURE {{ states('sensor.transactions _a_venir _montant') |float |round(2) }} € {% for transaction in transactions %} {% if transaction.coming %} {% if transaction.date %} {% set date_obj = transaction.date | as_datetime %} {% set formatted _date = date_obj.strftime('%d/%m/%Y') %} {% else %} {% set formatted _date = 'Date unknown' %} {% endif %} {% if transaction.type == 'card' %💳 {{ formatted _date }} {% elif transaction.type == 'bank' %} 🏦 {{ formatted _date }} {% elif transaction.type == 'check' %} 📝 {{ formatted _date }} {% elif transaction.type == 'transfer' %💸 {{ formatted _date }} {% else %⚪ {{ formatted _date }} {% endif %} {% if transaction.value &gt; 0 %} 🟢 {{ transaction.formatted _value }} - {{ transaction.wording }} {% else %} 🔴 {{ transaction.formatted _value }} - {{ transaction.wording }} {% endif %} {% endif %} {% endfor %} grid _options: columns: 12 rows: auto - type: entity entity: sensor.solde _available name: Available balance icon: mdi:bank-transfer grid_options: columns: full card_mod: style: | ha-card { padding: 4px; border-radius: 15px; } .icon ha-state-icon { --mdc-icon-size: 50px!important; /* Icon size */ margin-bottom: 10px; } - type: entities entities: - entity: sensor.transactions _bank name: Last update of data format: datetime column _span: 3 cards: [] icon: mdi:currency-eur

Decomposition of the dashboard

My dashboard is structured in several sections and maps to display information in a clear and intuitive way. Here's what each card does:

1. "Bank balance" card

This card shows the current balance of my bank account. It uses the sensor sensor.balance _bank and includes a stylized icon (mdi:bank-transfer) for better visibility. I added a custom style to round the corners of the map and enlarge the icon.

2. ‘AUJOURD’HUI’ card

This card shows the transactions made today. It uses a Markdown template to format the data:

  • Transactions are classified by type (💳 for cards, 🏦 for transfers, etc.).
  • The amounts are displayed in green (🟢) for credits and in red (🔴) for debits.
  • The date of each transaction is formatted in the format dd/mm/yyyy.

3. "FUTURE" card

This card shows upcoming transactions (such as scheduled direct debits). It also uses a Markdown template:

  • The total amount of future transactions is displayed at the top of the card.
  • Each transaction is listed with its type, date and amount.

4. "Available balance" card

This card shows the available balance after deduction of future transactions. It uses the sensor sensor.balance _available and shares the same style as the "Bank Balance" card.

5. Map "Last data update"

This card shows the date and time of the last update of the bank details. It uses the sensor sensor.transactions _bank and format the date in format datetime.