Custom Home Assistant integration that estimates your electricity bill based on:
- a monthly energy consumption sensor,
- PUN price calculation (either calculated from GME hourly prices or a fixed value),
- ARERA tariff parameters (automatically retrieved),
- Portale delle Offerte tax parameters (automatically retrieved),
- and a set of configurable parameters (fees, fixed charges, taxes, discounts, TV license, etc.).
Repository: https://github.com/Sanji78/bolletta
Author / Codeowner: @Sanji78
- Exposes several sensor entities representing bill items (energy fixed fee, energy consumption cost, transport fees, system charges, excise, VAT, total).
- Automatic parameter retrieval from ARERA (monthly tariff parameters) and Portale delle Offerte (tax rates and system charges).
- Flexible billing periods with configurable monthly/bimonthly billing and invoice shift options.
- PUN integration with two modes: calculated from GME market data or fixed value.
- Precise calculations that match actual utility bills to the cent.
- Grouped devices for better organization in Home Assistant (PUN, ARERA, Bolletta, PortaleOfferte).
- Built with a coordinator (
PUNDataUpdateCoordinator) and sensors that compute values on update/poll. - Compatible with Home Assistant via a Config Flow (no YAML configuration required).
- Automatic ARERA parameter retrieval: No more manual entry of energy quotas, transport fees, ASOS/ARIM values
- Automatic Portale delle Offerte integration: Automatic retrieval of tax rates (IVA, accisa), network loss percentages
- Enhanced billing flexibility: Configurable monthly/bimonthly billing with invoice shift options
- Improved sensor organization: Sensors grouped into logical devices for better HA interface management
- Precision calculations: Fixed rounding issues - now matches actual utility bills exactly
- Tested and validated: Calculations verified against real utility bills with cent-level accuracy
- House type selection: Residential vs Non-residential properties
- Billing period switches: Monthly billing and invoice shift toggles
- Power contract level: Differentiated parameters based on contract power (≤3kW vs >3kW)
- ARERA Excel files: Quarterly updated tariff parameters automatically downloaded and parsed
- Portale delle Offerte CSV: Daily updated tax parameters and system charges
- GME market data: Hourly PUN prices for accurate calculations
The integration supports a PUN mode option (selected during config flow or from the integration Options):
- Calculated (default) — PUN is retrieved/averaged by the integration from hourly GSE zonal prices and used to compute the bill (this is the original behavior).
- Fixed — PUN is taken from a fixed numeric value entered by the user (option
fixed_pun_value, expressed in€/kWh). When set, the integration uses that fixed value for all PUN-dependent calculations.
- Home Assistant (modern versions; integration tested with 2025 era compatibility).
- Python libraries:
holidays,bs4(BeautifulSoup4),openpyxl
- Make sure you have HACS installed.
- Go to HACS → Integrations → ⋮ → Custom repositories.
- Add
https://github.com/Sanji78/bollettawith Category: Integration. - Install Bolletta from HACS and restart Home Assistant.
- Copy the folder
custom_components/bollettainto your Home Assistant configuration directory:<config>/custom_components/bolletta - Restart Home Assistant.
- In Home Assistant: Settings → Devices & Services → Add Integration.
- Search for Bolletta and follow the configuration flow.
- Fixed quota - Aggregation measures (€/month)
- Monthly fee (€/month)
- PUN Mode: Choose between calculated (from GME) or fixed value
- Other fees - Dispatching (€/kWh)
- House type: Residential or Non-residential
- Monthly consumption sensor: Select your energy consumption sensor
- Zone (for PUN calculations) if using calculated mode
- Scan hour for data updates
- Power in use (kW) - Your contracted power level
- Discount (€/month)
- TV Tax (€/month)
- ARERA and Portale delle Offerte parameters are now automatically retrieved - no manual entry needed
- The integration will automatically download and update tariff parameters monthly
- Monthly consumption sensor must provide
last_periodattribute for bimonthly billing calculations
sensor.bill_energy_fix_quote- Energy fixed quotasensor.bill_energy_energy_quote- Energy variable quotasensor.bill_transport_fix_quote- Transport fixed quotasensor.bill_transport_power_quote- Transport power quotasensor.bill_transport_energy_quote- Transport energy quotasensor.bill_asos_arim_quote- System charges (ASOS/ARIM)sensor.bill_accisa_tax- Excise taxsensor.bill_iva- VAT totalsensor.bill_total- Total bill amountsensor.bill_kwh_price- Effective price per kWh
sensor.pun_mono_orario- Current month hourly averagesensor.pun_mono_orario_mp- Previous month hourly averagesensor.pun_fascia_f1/sensor.pun_fascia_f2/sensor.pun_fascia_f3- Current month by tariff bandsensor.pun_fascia_f1_mp/ etc. - Previous month by tariff bandsensor.pun_fascia_corrente- Current active tariff bandsensor.pun_prezzo_fascia_corrente- Price for current tariff bandsensor.pun_prezzo_zonale- Zonal price (current hour)sensor.pun_orario- Hourly PUN price
sensor.arera_energy_sc1- Energy quota Scaglione 1sensor.arera_fix_quota_transport- Transport fixed quotasensor.arera_quota_power- Power quotasensor.arera_asos_sc1- ASOS variable quotasensor.arera_arim_sc1- ARIM variable quota- (Plus previous month variants for all parameters)
sensor.portaleofferte_accisa_tax- Excise tax ratesensor.portaleofferte_iva- VAT ratesensor.portaleofferte_nw_loss_percentage- Network loss percentagesensor.portaleofferte_port_asos_sc1- Portale ASOS ratesensor.portaleofferte_port_arim_sc1- Portale ARIM rate- (Plus previous month variants for all parameters)
switch.invoice_shift- Toggle for shifting invoice cutoffswitch.invoice_monthly- Toggle for monthly billing (vs bimonthly)
The integration now supports flexible billing periods:
- Enable the
invoice_monthlyswitch - Calculations use only current month consumption
- Disable the
invoice_monthlyswitch - Calculations include current and previous month consumption
- Use
invoice_shiftto adjust which months are grouped together
- The
invoice_shiftswitch controls month pairing for bimonthly bills - Shifted: Feb/Mar, Apr/May, etc.
- Non-shifted: Jan/Feb, Mar/Apr, etc.
This integration has been tested against actual utility bills and matches calculations to the cent. The improvements include:
- Proper rounding at each calculation step
- Accurate handling of bimonthly billing periods
- Correct application of tax rates and discounts
- Precise energy quota calculations based on real consumption data
- If sensors show
unknownor errors: - Check that
monthly_entity_sensorexists and has numeric value and thelast_periodattribute. - Check logs (Settings → System → Logs) for entries under
custom_components.bolletta. - If
last_periodis not present on the consumption sensor, the bi-monthly logic will not work—ensure the source sensor provideslast_period. - If ARERA or Portale delle Offerte data fails to download:
- The integration will retry automatically with exponential backoff
- Check your internet connection and firewall settings
- Parameters will use cached values until new data is available
If you currently have a sensor that provides daily consumed kWh (for example sensor.daily_consumed_kwh) you can create a monthly consumption sensor that stores the previous month's value (last_period) using Home Assistant's Utility Meter helper. The integration uses the last_period attribute to include the previous billing period when needed (bi-monthly billing).
Follow these steps (UI method):
- In Home Assistant go to Settings → Devices & Services → Helpers.
- Click Add Helper (bottom right).
- Choose Utility meter.
- Fill the helper form:
- Name: e.g.
Monthly energy (from daily)(this will create an entity likesensor.monthly_energy_from_daily). - Source: select your daily consumed kWh sensor (e.g.
sensor.daily_consumed_kwh). - Meter reset cycle: choose Monthly.
- Leave tariffs (if present) empty unless you need separate tariff meters.
- Name: e.g.
- Save the helper.
What you get:
- A new entity (e.g.
sensor.monthly_energy_from_daily) that accumulates and resets on a monthly cycle. - The helper exposes an attribute
last_periodwhich contains the total consumption of the previous cycle (the previous month). You can access it in templates with:{{ state_attr('sensor.monthly_energy_from_daily', 'last_period') }} - Use the new helper entity as the
monthly_entity_sensorin the Bolletta integration configuration.
YAML example (alternative to UI):
If you prefer YAML-based configuration (for installations that still use YAML for helpers), you can add to your configuration.yaml (or include file) something along these lines:
utility_meter:
monthly_energy_from_daily:
source: sensor.daily_consumed_kwh
cycle: monthlyNotes & tips:
- The Utility Meter helper stores the
last_periodattribute automatically. You can use this attribute in templates or set your integration to read it. - Be aware of timezone / daylight-saving quirks: some users reported the monthly reset happening slightly earlier or later depending on timezone and DST transitions; if your reset appears off by some hours, double-check Home Assistant's timezone setting and the recorder settings. If you need custom reset times, consider using automations to snapshot the current value before reset. (See Home Assistant Utility Meter docs for behavior details.)
- If you need the entity to appear as an energy-type sensor for the Energy Dashboard, make sure the source sensor has appropriate
device_class: energyandstate_class: total_increasingmetadata where applicable.
References and further reading:
- Official Utility Meter integration documentation.
- Community threads discussing the
last_periodattribute and reset timing.
(See links in this README response for the docs referenced.)
PRs and bug reports are welcome. Open issues or PRs at:
https://github.com/Sanji78/bolletta
If this project helps you, consider buying me a coffee:
PayPal
..and yes... 😊 the paypal account is correct. Thank you so much!
Distributed under the MIT license. See LICENSE in the repository.
- Repository:
https://github.com/Sanji78/bolletta - Issue tracker:
https://github.com/Sanji78/bolletta/issues