Skip to content

Cost sensors

Powercalc can create cost sensors which track how much the consumed energy costs. A cost sensor multiplies the energy consumed by an energy price and accumulates the result over time. The created sensor has device class monetary and uses your Home Assistant currency as unit of measurement, so it can be used on dashboards and in the energy dashboard.

The energy price is configured globally, either as a fixed price or by pointing to a sensor which provides the current price per kWh (for example a dynamic tariff integration such as Nordpool, Tibber or Frank Energie). Individual sensors can override that price.

Configuring the energy price

Define the price once in the global configuration. Provide either a fixed price or a price sensor.

Fixed price (per kWh, in your local currency):

powercalc:
  energy_price: 0.25

Price from an existing sensor:

powercalc:
  energy_price_sensor: sensor.current_energy_price

When both are set, the fixed price is ignored and the price sensor is used.

You can also add a fixed per-kWh surcharge to either price source. This is useful for taxes, grid fees, provider markup, or other usage-based charges that should be added to the base energy price:

powercalc:
  energy_price: 0.25
  energy_price_surcharge: 0.05

With this configuration, each consumed kWh is charged at 0.30 in your Home Assistant currency.

For percentage-based taxes or fees, use energy_price_multiplier. For example, use 1.21 to add 21% tax:

powercalc:
  energy_price: 0.25
  energy_price_surcharge: 0.05
  energy_price_multiplier: 1.21

The effective price is calculated as:

(energy_price or energy_price_sensor + energy_price_surcharge) * energy_price_multiplier

Per sensor energy price

Every pricing option can also be set on an individual sensor, overriding the global configuration for that sensor only. This is useful when part of your consumption is billed differently, for example an EV charger on a separate tariff or a device running on self-produced solar power.

powercalc:
  energy_price: 0.25
sensor:
  - platform: powercalc
    entity_id: switch.ev_charger
    create_cost_sensor: true
    energy_price: 0.15

The following keys are supported per sensor: energy_price, energy_price_sensor, energy_price_surcharge and energy_price_multiplier.

The price source is resolved as a whole: as soon as a sensor defines energy_price or energy_price_sensor, it fully replaces the globally configured price source. So a sensor with a fixed energy_price ignores a global energy_price_sensor, and vice versa. energy_price_surcharge and energy_price_multiplier are independent and fall back to the global value individually when not set on the sensor.

A price only configured on the sensor also works when no global price is set at all:

sensor:
  - platform: powercalc
    entity_id: switch.ev_charger
    create_cost_sensor: true
    energy_price_sensor: sensor.ev_tariff

In the GUI the same options are available under Cost options in the options flow of a sensor which has cost sensors enabled, and directly on the creation form of a standalone cost sensor.

Enabling cost sensors

Similar to energy sensors and utility meters, cost sensor creation can be toggled globally and per powercalc sensor.

To create cost sensors for all powercalc sensors:

powercalc:
  energy_price: 0.25
  create_cost_sensors: true

To enable/disable per sensor (this overrides the global setting for that sensor):

sensor:
  - platform: powercalc
    entity_id: light.floorlamp_livingroom
    create_cost_sensor: true

Toggling cost sensor creation can also be done when creating sensors with the GUI, both in the global configuration and on a per sensor basis.

Note

Toggling create_cost_sensors in the global GUI configuration does not automatically change the per-sensor toggle for sensors you already created through the GUI. Therefore, whenever you flip this toggle (on or off), an extra step is shown that lets you enable the Apply to existing sensors option. When enabled, every existing GUI powercalc sensor is updated to match the new setting.

Cost sensor for an existing energy sensor

You can also create a standalone cost sensor for an energy sensor that was not created by Powercalc, for example an energy sensor from a smart plug or utility integration. In the GUI, add a new Powercalc sensor and choose Cost sensor (from existing energy sensor), then select the energy sensor and give it a name.

The price comes from the global configuration, unless you fill in the Price override section on the form. When neither is set, the form asks you to supply a price before continuing.

The same can be configured in YAML with a cost block. The name is optional; when omitted it is derived from the tracked energy sensor:

powercalc:
  sensors:
    - name: Fridge
      cost:
        energy_sensor_id: sensor.fridge_energy

A per sensor price can be set alongside the cost block:

powercalc:
  sensors:
    - name: Fridge
      energy_price: 0.15
      cost:
        energy_sensor_id: sensor.fridge_energy

Naming

By default a cost sensor is named {appliance} cost (for example Floorlamp cost). You can change this globally with cost_sensor_naming, similar to energy_sensor_naming and power_sensor_naming. Use the {} placeholder for the name of your appliance. This also changes the entity id of the sensor.

powercalc:
  energy_price: 0.25
  cost_sensor_naming: "{} energy costs"

To only change the friendly name (and keep the entity id), use cost_sensor_friendly_naming:

powercalc:
  energy_price: 0.25
  cost_sensor_friendly_naming: "Costs of {}"

Both settings can also be configured in the GUI under the cost options step of the global configuration.

Note

A cost sensor is derived from the energy sensor, so an energy sensor must be created as well. Assume you have a light light.floorlamp_livingroom, then you would get:

  • sensor.floorlamp_livingroom_power
  • sensor.floorlamp_livingroom_energy
  • sensor.floorlamp_livingroom_cost

Cost per utility meter

When you also enable utility meters, Powercalc creates an additional cost sensor for every utility meter, next to the cost sensor for the energy sensor. This lets you track the cost per cycle (daily, weekly, monthly, ...) just like the energy utility meters track consumption per cycle.

For example, with create_cost_sensors, create_utility_meters and a daily and monthly meter enabled, a light light.floorlamp_livingroom would get:

  • sensor.floorlamp_livingroom_cost (total cost)
  • sensor.floorlamp_livingroom_energy_daily_cost
  • sensor.floorlamp_livingroom_energy_monthly_cost

The per-meter cost sensors reset together with their utility meter, so they always reflect the cost accumulated during the current cycle. They are only created when both cost sensors and utility meters are enabled.

How the cost is calculated

The cost sensor reacts to changes of the energy sensor. On every update it takes the amount of energy consumed since the previous update and multiplies it by the price that is valid at that moment, using the sensor's own price when it has one and the global price otherwise. When energy_price_surcharge is configured, it is added to the fixed price or dynamic price sensor value. When energy_price_multiplier is configured, it is applied after the surcharge. When you use a dynamic price sensor, a price change settles the energy consumed up to that point at the previous price before the new price takes effect. This way energy is always priced against the tariff that was active while it was consumed, and the accumulated cost stays correct even when the price changes over time.

The energy price is interpreted per kWh. If the source energy sensor reports in a different unit (for example Wh or MWh), the consumed energy is converted to kWh based on the sensor's unit of measurement before it is priced. When the sensor has no recognizable energy unit, it is assumed to already be in kWh.

The same applies to a price sensor: when its unit is expressed per another energy unit (for example EUR/MWh, as some dynamic tariff integrations report), the price is converted to a per-kWh price before it is applied. The cost sensor also adopts the currency from the price sensor's unit (for example €/kWh results in a cost sensor), falling back to the Home Assistant currency when the price sensor has no unit.

Peak and off-peak tariffs

Powercalc does not yet have native fields for separate fixed peak and offpeak prices. See the peak and off-peak tariff cookbook to implement this with a Home Assistant template sensor. Native support for fixed per-tariff prices is planned for a future release.