Calculate costs of energy in Apexcharts dynamically

I think it is best to descibe my question by an example:

type: custom:apexcharts-card
apex_config:
  chart:
    height: 300px
graph_span: 1year
locale: nl
span:
  start: year
show:
  last_updated: false
header:
  show: true
  show_states: false
  colorize_states: true
  title: Monthly usage
  floating: false
yaxis:
  - min: 0
    max: ~15
    decimals: 0
    apex_config:
      tickAmount: 3
series:
  - entity: sensor.honda_energy
    show:
      header_color_threshold: true
      extremas: true
    type: column
    name: HondaE
    statistics:
      period: month
      align: start
      type: state
    group_by:
      duration: 1Month
      start_with_last: true
      func: diff

This is given me a nice graph of monthly energy usage.
What I also want is the total costs per month. Is there an option to calculate the outcome based on a static price and the same kWh results?

I do not have history of calculated prices I can use (only the used energy). It would be nice to solve this by just adding a simple calculation of kWh (monthly) * € (fixed cost for every month).

Cannot get my vinger arround how to get this to work.

Thanks

Create a monthly utility_meter on sensor.honda_energy and a sensor template based on it which calculates the cost.
If you want history, set the appropriate device_class, state_class and unit_of_measurement.

You can use the scale transform option. See the example here: GitHub - RomRider/apexcharts-card: 📈 A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant

e.g.

series:
  - entity: sensor.honda_energy
    show:
      header_color_threshold: true
      extremas: true
    type: column
    name: HondaE
    statistics:
      period: month
      align: start
      type: state
    group_by:
      duration: 1Month
      start_with_last: true
      func: diff
    transform: "return x * 0.42

That assumes the same fixed price forever, which tends to not be the case for anything.
Having a sensor allows me to have the actual cost at any given moment saved in history (I know, I know, you don’t use HA history :wink: )

Exacly what I was looking for. Thanks!!

You are right. And I will look into this for the future. For the past it is too late.

Hi, how did you manage to place the marker on the zero values?
I can’t seem to get it right unless I also make them appear on top of the other values.