Lovelace - sensor card, does it work?

Does the Lovelace sensor card work?

I am experimenting with it using two sensors but the graph that the card shows seems to bear no relation to the graph shown in the ‘more info’ pop-up. Please see below for examples (I keep 24 hours of history).

Furthermore irrespective of how I configure the card I always get a flat line for the first half of the graph. Is that by design (if so why?) because the image in the docs shows this too.


My illuminance sensor card:

              - type: sensor
                entity: sensor.illuminance
                name: Illuminance
                line_color: '#3498db'
                line_width: 3
                accuracy: 500

image

image


My brightness sensor card:

              - type: sensor
                entity: sensor.brightness
                name: Brightness
                line_color: '#e74c3c'
                line_width: 3
                accuracy: 500

image

image


Example from the docs showing flat line

image

it works:
image

Just remember that by default it’ll show the last 24h (hours_to_show). Do you have data for the last 24h?
Also by default it displays only 10 data points (accuracy)

1 Like

@lolouk44
Yes, I have 24 hours of data as can be seen by the ‘more info’ graph and I have experimented with all sorts of number of data points right up to 5000.

I don’t understand why the graphs bear no relation to each other.

EDIT: I just found out that the accuracy: isn’t really well named. It is better described by the description(!) in that it is simply the number of points displayed. If it doesn’t have enough points it does the flat line rather than graphing as many as it can up to the number defined in accuracy: Not that useful when you don’t know how many data points there will be in a given time.


[And as an aside, do you have a gauge and a sensor on the same card there? If so how do you do that?]

the gauge and sensor cards are 2 cards in a vertical stack, but I use the custom vertical stack to remove the frames to make it look like a single card:

3 Likes

So how do you get the most ‘accurate’ representation of the ‘more info’ graph on the sensor card? I already tested various accuray: values from 10 up to 500, but none of it seems to fit very well. At some point, half of the graph is always a straight line when increasing accuracy.

What exactly is the hours_to_show: setting for when it doesn’t show the configured timespan over the whole width of card, but just half of it? Also, 3 of my 4 sensor cards always show a ‘spike’ at the end of the line, even if there isn’t any increase at the end of the ‘more info’ history graph. Can’t really figure this out.

Yeah, the current implementation makes no sense. It will indeed draw a flat line if the source sensor has less samples than the “accuracy”.

This function appears to use a method called moving average. Lower the number, the more accurate graph. I.E. 1 will be 1 point to 1. 10 will be 10 points to 1. I.E the graph will use 5 points before and after to make a single point in the simple graph.

The side affect of a moving average filter is rounded corners when they should be sharp.

EDIT: Actually, the input is not as smart. It is using moving average but you can’t specify it by lowering the number.

If you want to get 1 to 1, you need to find out the number of data points over 24 hours and place that number into the accuracy spot.

1 Like

Yeah, accuracy: 1 gives you a straight line, accuracy: 2 a line between 2 points and so on.

Counting the data points over the time period seems to work best, the only problem is that some sensors like the Xiaomi Temperature & Humidity sensor only report a new value if there is a significant change, which means that the amount of data points isn’t always the same within the last 24 hours.

EDIT: I think it would be a lot more useful if the line just showed the exact graph over the set period of time, with the possibility to configure the level of ‘smoothness’ via the accuracy setting.

+1 for this

Well that’s how moving average should work. I’m not sure why the guy built it that way. Typically you specify how many points you want to be averaging. The way he wrote it was ‘this is the desired number of points I want’. Counter intuitive to be honest.

Yes, but still : accuracy 1 gives a flat line, accuracy 500 (or 5000 or 50000) still shows a flat line in the first part. See the example, red sensor with details opened, green sensor behaves the same.

You can see that I have data for this sensor over the whole 24 hours.

Your full sensor data is there. Take a look at the peaks. Your big graph has 4 big peaks and 1 little peak at the end.

Your flatline graph has 4 big peaks and 1 little peak. But it has a flat line in front. Are you showing 48 hours of data or 24 in the small graph?

24 hours (default) in the sensor configuration, 24h in the detail view !

        - type: sensor
            entity: sensor.temperature_maison
            height: 68
            line_width: 2
            line_color: "#ff0000"
            accuracy: 5000

How many points of data does your sensor have?

Once per minute is: 1440
Twice per minute is: 2880

Have you tried either of those numbers?

It’s possible that if you specify 5000 data points that it will give you 5000 no matter what. It can’t make up data so it probably places the data in front.

This is why I said ‘accuracy’ is poorly implemented. It should be x number of points = x number of points. I.e if you place a 1 in accuracy it maintains a 1 to 1 ratio.

Can’t know, it’s the xiaomi sensor, so they push data when needed not on a regular basis…

If I play with accuracy, I can even get false results. See here, with a value of 150 :

There are bugs in it I guess. But lovelace is beta no ? I’ve only tried it or a few days, trying to achieve the same interface I have with legacy + customUI. Or even better, which the sensor card was supposed to be.

Yeah, it’s in beta. You can always use a history graph card instead of the sensor card.

I use it in the “technical information” screen, it’s nice because you can put several sensors in the same graph, but way less pretty ! And doesn’t display the current value. Here I’m using it for my main screen, that I’d like to see on a wall-mounted tablet.

image

OK, so I debugged into the algorithm for the sensor card. Here are a few things to note:

  • You cannot supply more resolution than the number of data points collected. For example, If I have 4300 data points, and you put an accuracy of 5000, you will only get 4300 data points.

  • This is NOT averaging at all. This is filtering points out. Example: You have 600 datapoints, you have an accuracy of 6, you will get every 100th point. If that point happens to be a flier, so be it. It’s in your data. (not good practice for data analysis). EDIT: This will make the graph look NOTHING like your actual history. This is what @klogg, @sebastian_p are seeing.

  • If you have a lot of data points and you hit the max resolution you will encounter a bug. This is that flat line you see. Basically they try to find an increment to use and they end up doing math similar to 1000/999, which returns 1.0000x. They then ceiling this number, getting a result of 2 exactly. So later on in the function, they iterate over the whole list. Normally, they should be choosing every item. But because ceiling returned 2, they are choosing every second item. This then results in them choosing a default value for HALF of the data points that are beyond the length of the array, which results in a flat line in the beginning. This is what @klogg, @abmantis, and @Mister_Slowhand is seeing.

1 Like

Thanks for looking into the code! By the way, can you submit a pull request fixing it? :smiley:

Thanks man, appreciate all the effort you are putting into this!

Sounds like a lot of things within the sensor card still need to be fixed/improved. Just filtering data points out isn’t really the way to go if you want an accurate repesentation of the graph. Maybe they did this instead of actual averaging because it would probably take a lot longer for the line to show up in the UI on slower systems?

Another thing that would be great is an option to hide the card title/icon, for instance if you have the temperature and humidity of the same room vertically stacked together, you don’t need the room name on every card.

Anyways, it would be amazing if we could get a functioning sensor card in the next few releases, still like the concept a lot!