Use switch to view specific graph lines

Hi all,

I made below apex chart to view power consumption in my house. A question that I have is if it is possible to create a switch that removes certain graphlines on the graph add adds them accordingly. For example, in this chart I pushed in the legend on two sensors so that the lines disappear, I want to create a switch to do it

Anyone has an idea how to do it ?

Kr,

Bart

Not using apexcharts myself.
If the card has an option like โ€œshow_graphโ€ (true/false) per entity & this option does not support jinja/JS templates, a possible workaround could be a wrapping the apexcharts into a custom:config-template-card like

type: custom:config-template-card
entities:
  - sensor.xxx # these 2 sensors are shown in apexcharts
  - sensor.yyy
  - switch.show_sensor_yyy #switch or input_boolean to control
card:
  type: custom:...apexcharts...
  ...
  show_graph: >-
    ${states['switch.show_sensor_yyy'].state === 'on' ? 'true' : 'false'}

Example for a similar mini-graph-card:

type: custom:config-template-card
entities:
  - sensor.xxx
  - sensor.yyy
  - switch.show_sensor_yyy
card:
  type: custom:mini-graph-card
  entities:
    - entity: sensor.xxx
    - entity: sensor.yyy
      show_graph: >-
        ${states['switch.show_sensor_yyy'].state === 'on' ? 'true' : 'false'}
1 Like

I did something similar a while back with config template card and a dropdown which changes which sensor is shown in a graph.

1 Like