Custom history graph scales (logarithmic, fixed intervals...)

Hi,

Not sure if this is the correct place to post this, if not, please someone move it to somewhere more appropriate on the forums. Thank you.

I would be very interested in custom graph scales, especially a logarithmic y-axis.

My (first) use case would be my smart meter reading (household power consumption): Typically it is in the range between 0 to 500W or maybe up to 1.000W. However it sometimes spikes when greedy appliances are used, e.g. electric stove, electric water boilers and so on. Now with a peak value at say 10.000W, the history graph becomes pretty useless for the everything else that happens during 90% or more of the time, that is way below 1.000. It is just not distinguishable any more. This should be easily solved using a log y-scale, if only a log scale were available…

On the forums I found 2 questions in very similar directions:

I believe there are a lot more use cases like these where custom graph scales would be handy.
Soo… Is this possible at all in history graphs? I know about all the possibilities of displaying database data, Jupyter Notebooks and so on, and of course I can use log scales there, but an integration into the beautiful native Home Assistant interface would be great.

Sounds like a great Idea!

I am taking the risk of bumping up an old Feature Request as it seems it may still be needed.

Logarithmic scaling would help tremendously with visualizing sensors for lux (illuminance), where in a day values can vary broadly, yet small differences at the lower end of the scale remain very important.

Anyone have any news or new ideas on this?

4 Likes

Thanks for bumping this up. I neither have a solution yet and am also still very much interested in this!

I dont have a solution yet and am not needing one right now, but I’ve decided to use Node-RED with the Dashboard module installed for things I cannot do with Home Assistant.
And reading from this it seems Node-RED can take a custom expression to maybe it this:

I cannot test this wether this works adequately for a Lux sensor at the moment, but I just wired up something else and it looks like I can use a function block with:

msg.payload = Math.log(msg.payload);

to modify the value before plotting. Maybe HA can do something similar but afaik it would require hacking code.

Bumping this up.

I am graphing my instantaneous consumption, and short time important usages like hot water boiler consumption is making the visualisation unuseable for the nominal case.

A logarithmitic scale with upper and lower bounds would surely help to still see the minor variations (20W) on a low level (100 - 200W) that are now “invisible” due the 2kW scale.

A more recent reply on a related question suggests to create a new sensor and defining the unit_of_measurement as “log(lx)” (for lux). That does generate a new series of data to store and extra computations on the HA instance, while this could be managed in JavaScript on the client side.

So I added this to my sensors, and “sensor.current_summation_log” to the history graph:

- platform: template
  sensors: 
    current_demand:
      friendly_name: "log(⚡ Conso (W))"
      entity_id: sensor.current_demand
      value_template: "{{ (log( [states('sensor.current_demand') | float, 0.001 ] | max, 10)+3) | round(3) }}
"
      unit_of_measurement: "log(W)"

Unfortunately the graph has a vertical axis that is not very appropriate for a logarithmic scale:
image

So, I’m in favor of something better !

Yeah, not a good workaround. I ended up using Grafana for my log plots.

Using Grafana implies installing influxdb or not?

Yes it does.

Thanks for your feedback. I did insist on looking for a sqlite3 solution, and it’s possible apparently.
I added the required plugin in the grafana configuration:

plugins:
  - frser-sqlite-datasource
env_vars: []
ssl: true
certfile: fullchain.pem
keyfile: privkey.pem

After being somewhat patient, I could access the grafana web interface.
I was able to add home-assistant_v2.db as a data source.

Now the next step is to check the db organisation to determine the query, and learn grafana enough to integrate a log graph.
That will probably be for another day.
At least I can put off learning InfluxDB a bit.

1 Like

Still seems to be an issue.

in Home Assistant vs. in Grafana using a log_10 scale.

Hi,
I just went through the sources of the frontend.
Visualization is done using “chart.js”.
Chart.js actually supports logarithmic scales, it just needs to be enabled.

frontend/statistics-chart.ts at ecdd07ff4d0724715b71b48a34fc785ea09bf177 · home-assistant/frontend · GitHub, line 159
You’d just need to add y.type= "logarithmic";

Unfortunately, modifying the ts files does not suffice. I guess some parsing and building needs to be done with the ts files.
And finally, this change should be configurable, as not everyone wants it logarithmic.

1 Like

I’d also love to see this feature as an option for the history graph card. Having an option, even if only in the code editor view, would make many data sources much more intelligible.

1 Like

I also would like to see this feature added to history and statistics graph cards. Especially if these cards support this features basically, but need enabling.
It would only be useful though, as mentioned above, if this is configurable in the card.

A very important topic.
And it is very strange that in 5 years there is no solution from HA …

“HA” is still very much “us.”

Hi, I’ve created a pull request to add logarithmic scales to the History and Statistics cards:

Thank you @Nippey for the pointer to the code.

Now available in 2023.12 :smiley:

Great work.

Any way to attach the logarithmic_scale config variable to a sensor (similar to unit_of_measurement) to allow for the History panel to also show the data with a logarithmic scale?