Is there a pie-graph available somehow?

Hi All

I’ve built a ‘security overview’ that just lists if doors and windows are closed and the frontdoor is locked.
It’s nice to have a list, but I would love to have it shown as a pie-chart, so that each entity provides a piece of the pie in a color for unsafe and safe, and then a full ‘green’ circle would indicate all is secured.

That isn’t really a pie graph. I pie graph the size of the slices depend on the numerical data associated with slice.

You perhaps need a custom lovelace card where you can specify the number of segments, and control their colour per segment.

1 Like

I see your point, true, that is correctly a pie-chart, but you got the picture and in lack of better terms… :slight_smile:
Do you know of any card that provides this?

Did you ever found a solution?

Nope, nothing available :frowning:

You can do pie-charts (and radial-bar charts and much, much more) with the fabulous ApexCharts card - A highly customizable graph card

image image image

take a look here: JavaScript Chart Examples & Samples Demo – ApexCharts.js

2 Likes

Yup, I found that one, forgot to update the thread, it’s quite good.

i have a sensor that has 5 possible string values. WOuld it be possible to use this card to do a pie chart of the % of time in that state for the last 24 hours? can anyone help with an example?

Yes, the way I would start is making 5 history stat sensors (History Stats - Home Assistant) - each one will be for one of the states. Then chart it.

hey im interested in something like this as well? did you manage to get some working??
Any chance you could supply the code??

Hi, I’ve got this working, so I’ll share the code for anyone looking in the future like me.

Firstly, I’ve installed ApexCharts using HACS

Then, in home assistant’s configuration.yaml I’ve added a history_stats sensor for every state that my input could be in, so as I’m tracking my PC’s state, it’s Windows, Linux and Off:

sensor:
  - platform: history_stats
    name: Linux time
    entity_id: input_select.pc
    state: "Linux"
    type: time
    duration:
      days: 31
    end: "{{ now() }}"
  - platform: history_stats
    name: Windows time
    entity_id: input_select.pc
    state: "Windows"
    type: time
    duration:
      days: 31
    end: "{{ now() }}"
  - platform: history_stats
    name: Off time
    entity_id: input_select.pc
    state: "Off"
    type: time
    duration:
      days: 31
    end: "{{ now() }}"

Then, I’ve added the ApexCharts card with the following code:

type: custom:apexcharts-card
header:
  show: true
  title: PC Time
  show_states: true
  colorize_states: true
chart_type: pie
series:
  - entity: sensor.linux_time
  - entity: sensor.windows_time
  - entity: sensor.off_time

And now I can see the percentage of time that my PC spends in each state :slight_smile:

1 Like

Very cute :slight_smile: