Apex charts. Variable horizontal line

Hi
I have tried to create a horizontal line in my apex chart. The line should vary according to the value of an attribute. I get it to work for a fixed value of y: but not for the attribute. Can anyone figure out what I’m doing wrong?

apex_config:
  annotations:
    yaxis:
      - 'y': {{ state_attr('sensor.nordpool_kwh_se3_sek_3_095_0', 'average') | float }}

Try putting it in quotes as the template is on a single line

apex_config:
  annotations:
    yaxis:
      - 'y': “{{ state_attr('sensor.nordpool_kwh_se3_sek_3_095_0', 'average') | float }}”

Thank you, but it didn’t solve the issue.

It gives no errors but no line is visible. It also autocorrects the code to

      - 'y': >-
          {{ state_attr('sensor.nordpool_kwh_se3_sek_3_095_0', 'average') |
          float }}

When in developer tools/Template, the following code works fine and returns a value.

{{ state_attr('sensor.nordpool_kwh_se3_sek_3_095_0', 'average') | float }}

Did you find a solution?
I tried to use the data_generator, but have not succeeded yet.

Hello,

I’m also trying to achieve the same… Anybody managed to do this?

I found a possible solution. Assuming that your chart shows the last 24 hrs of data you can use group_by to select the last value in the 24 hrs bucket:

  - entity: input_number.irrigation_rain_skip
    group_by:
      func: last
      duration: 24h
    type: area

This worked for my application.

Did anyone find a solution?

This does not error, but does not work either :frowning:

apex_config:
  annotations:
    yaxis:
      - 'y': '{{states("sensor.30_min_anerage_electricity_profit_cost") }}'
        borderColor: '#00E396'
        borderWidth: 4
        label:
          text: mean

Install the config-template-card card and try next:

    type: custom:config-template-card
    variables:
      - '"sensor.electricity_price_today"'
      - states["sensor.30_min_anerage_electricity_profit_cost"].state
    entities: ${vars[0]}
    card:
      type: custom:apexcharts-card
      [....]
      apex_config:
        annotations:
          position: front
          yaxis:
            - 'y': ${vars[1]}
1 Like

Perfect, thank you!

I want to have a slide value controlling a horisontal line in my apex chart and I cant get it to work. No matter the value of the slide it will always be a line at the top of the y axis. If I hard code the value it will be correct. In this case the line should be at 0.1.

type: custom:apexcharts-card
now:
  show: true
  label: NU
graph_span: 48h
apex_config:
  annotations:
    yaxis:
      - 'y': input_number.prisgrans_laddning
        borderColor: red
        label:
          borderColor: red
          style:
            color: '#fff'
            background: red
          text: Laddgräns
  plotOptions:
    bar:
      borderRadius: 2
  yaxis:
    align_to: 0
    decimalsInFloat: 2
    tickAmount: 5
    forceNiceScale: true
  xaxis:
    labels:
      datetimeFormatter:
        hour: HH
all_series_config:
  extend_to: false
  show:
    offset_in_name: true
header:
  title: Dagens & morgondagens spotpris
  show: true
  show_states: true
  colorize_states: true
span:
  start: day
  offset: +0h
series:
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    type: column
    color: green
    float_precision: 3
    stroke_width: 2
    name: Dagens timpris
    show:
      in_header: false
      legend_value: false
      extremas: true
    data_generator: |
      return entity.attributes.raw_today.map((start, index) => {
        return [new Date(start["start"]).getTime(), entity.attributes.raw_today[index]["value"]];
      });
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    type: column
    color: yellow
    float_precision: 3
    stroke_width: 2
    name: Morgondagens timpris
    show:
      in_header: false
      legend_value: false
      extremas: true
    data_generator: |
      return entity.attributes.raw_tomorrow.map((start, index) => {

        return [new Date(start["start"]).getTime(), entity.attributes.raw_tomorrow[index]["value"]];

      });
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    name: Timpris just nu
    color: green
    type: column
    show:
      in_chart: false
    float_precision: 3
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    attribute: average
    type: column
    color: pink
    float_precision: 3
    stroke_width: 2
    name: Dagens snittpris
    group_by:
      duration: 2d
    show:
      in_chart: false
      legend_value: false
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    attribute: max
    type: column
    color: orange
    float_precision: 3
    stroke_width: 2
    name: Dagens högsta pris
    group_by:
      duration: 2d
    show:
      in_chart: false
      legend_value: false
  - entity: sensor.nordpool_kwh_se3_sek_3_10_0
    attribute: min
    type: column
    color: green
    float_precision: 3
    stroke_width: 2
    name: Dagens lägsta pris
    group_by:
      duration: 2d
    show:
      in_chart: false
      legend_value: false

Skärmbild 2024-09-11 134203
Skärmbild 2024-09-11 134305

Have you found a solution?