Plotly interactive Graph Card

many thanks!!

Last question for today…
I have two sensors that measure the state of a relay: one for daily statistics and one for monthly statistics. And the respective graphs are correct.
Can I keep only one and draw both graphs?
I have tried with various filters, but nothing seems to work.

Did you achieve this?

hours_to_show: current_day

OK, what if just want to show like 6am to 6pm only? always, fixed.

That’s trickier you can adapt it from this Show the current day from midnight to midnight · dbuezas/lovelace-plotly-graph-card · Discussion #220 · GitHub

I’m following one of the many instructions on how to plot Temperature vs Humidity, (e.g. Plotly interactive Graph Card - #386 by mateine) and I just can’t get the X-axis to show anything other than time. What am I missing? :slight_smile:

type: custom:plotly-graph
entities:
  - entity: sensor.living_room_hygrometer_temperature
    internal: true
    filters:
      - resample: 10m
      - store_var: t
  - entity: sensor.living_room_hygrometer_humidity
    internal: true
    filters:
      - resample: 10m
      - store_var: h
  - entity: ''
    x: $fn ({ vars }) => vars.t.ys
    y: $fn ({ vars }) => vars.h.ys
    #z: $fn ({ vars }) => vars.h.ys
    type: scatter

For both type scatter and histogram2dcontour I get the time on the X-axis:

Only when I switch to scatter3d does it do a proper scatter plot but… obviously in 3D rather than the desired 2D :joy:

What’s still missing?

Installed version: v.3.3.4

This happens a lot - I have a watts vs. time plot. And I’d LOVE to be able to click on a arbitrary point, and either click on a 2nd point (or drag over select), and have know (somehow) what the total w/time is. Basically kWh, but I can do that extra math on the units if necessary.
I’ve done all kinds of searches, like “graph tool select range calculation area home assistant” etc. Plotly looks awesome, but doesn’t appear to handle the math.

Any suggestions? (besides writing my own - and depending on what happens in the near future I might have some… free time to do so.)
image

Can Plotly (or another plugin) do this?

2567-07-14 01_47_19-Overview – Home Assistant
is there anyway to do barcode type graph like history explorer card?
these card seems a lots faster to load. but lack these function.

Try adding raw_plotly_config: true at the root.
I assume there’s something in the defaults that assumes time (here are the defaults)
You could also try with

layout:
  xaxis:
    type: numeric # or something like that
1 Like

You could do it with this card with $fn.
Useful hints:

  • get('visible_range') returns the current xaxis range in scren
  • there’s a filter called itself filter with which you could do filter: "+x> +get('visible_range')[0] &&+x< +get('visible_range')[1]"
  • there’s an integration filter perfect for computing kWh from Watts

I don’t think so, no. You can probably replicate it with plotly if you spend a bunch of time :slight_smile:

ahh too bad. thx for quick reply. :pray:

Hoping I am ok to post here for help with plotly-graph-card. I have used it quite a bit in my HA and I love it. Mindblowing how flexible it is.

I have a utility meter with 12 tariffs. Each one saves the electric bill amount for a given month. So I have sensor.elec_bill_utilmeter_1 with January’s value, sensor.elec_bill_utilmeter_2 with Feb’s value, and so on.

I want to show a bar graph with these values lined up, with months Jan thru Dec along the x axis. I have gone through many many googles and even tried asking Copilot (surprisingly helpful sometimes, but often not great). Been through lots of failed attempts and can’t seem to figure this one out. I believe I need to assign each sensor an x value corresponding to the month.
Most examples that I find have the historical values of a sensor against timeline. This is a bit different.
Appreciate any help you can share!
Thank you!

Yes, flexibility was my ambition with it! :slight_smile:
I find that chatgpt can be good at the yaml for this if one tells it it uses plotlyjs and paste a bunch of examples too.

Anyway, try with something like this:

hours_to_show: current_year
entities:
 - entity: ''
   name: Electric amounts
   x: |
     $ex Array.from({length: 12}).map((_,month)=> new Date(new Date().getFullYear(), month, 1)) 
   y: |
     $ex Array.from({length: 12}).map((_,month)=> hass.states[`sensor. elec_bill_utilmeter_${month+1}`].state)

if the entity for e.g August has that of last month YEAR you’ll need to adapt it a bit. I bet that if you paste this example and your original question, ChatGPT or similar will nail it :slight_smile:

1 Like

Thank you so much, it’s exactly what I needed!

1 Like

THIS :point_up: worked, thanks!

FYI I tried a variety of types, as per the options listed in Layout.xaxis in JavaScript. Although the appearance of the axis changed, the plot/line itself did not appear. So it’s probably a deeper thing. (?)

I thought it would be interesting to generate Psychrometric charts on the fly, so after adding psychrolib.js as a resource you can do:

type: custom:plotly-graph
entities:
  - entity: ''
    internal: true
    fn: |
      $fn ({vars}) => {
        psychrolib.SetUnitSystem(psychrolib.SI);
        var f = rh => t => 1000 * psychrolib.GetHumRatioFromRelHum(t, rh, 101325);
        xarr = Array.from({ length: 50 }, (x, i) => i - 10);
        vars.xs = xarr;
        vars.hr100 = xarr.map(f(1));
        vars.hr80 = xarr.map(f(0.8));
        vars.hr60 = xarr.map(f(0.6));
        vars.hr40 = xarr.map(f(0.4));
        vars.hr20 = xarr.map(f(0.2));
      }
  - entity: ''
    x: $fn({vars}) => vars.xs
    'y': $fn({vars}) => vars.hr100
    line:
      color: gray
      width: 1
  - entity: ''
    x: $fn({vars}) => vars.xs
    'y': $fn({vars}) => vars.hr80
    line:
      color: gray
      width: 1
      dash: dot
  - entity: ''
    x: $fn({vars}) => vars.xs
    'y': $fn({vars}) => vars.hr60
    line:
      color: gray
      width: 1
      dash: dot
  - entity: ''
    x: $fn({vars}) => vars.xs
    'y': $fn({vars}) => vars.hr40
    line:
      color: gray
      width: 1
      dash: dot
  - entity: ''
    x: $fn({vars}) => vars.xs
    'y': $fn({vars}) => vars.hr20
    line:
      color: gray
      width: 1
      dash: dot
defaults:
  entity:
    showlegend: false
    type: scatter
    mode: lines
layout:
  title: Psychrometric Chart
  xaxis:
    title: Dry Bulb Temperature (°C)
  yaxis:
    range:
      - 0
      - 30.2
    title: Humidity Ratio (g/kg)
hours_to_show: 24
refresh_interval: 10
raw_plotly_config: true

newplot

Still has a way to go, but the goal is to then plot the actual value on top of this.

1 Like

Wow that’s cool! I never thought of using third party Js libraries like that!

I notice that in mode: text, at least the textposition is passed to plotly. Is there a way to specify the text color (textcolor?) and angle (textangle?) in a similar way?

Edit: there is an option to add

    textfont:
      color: green

Anything like that for textangle?

Everything is passed to plotly, if anything seems to not work it is most likely because of the defaults