You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Filters error message when a non-array is passed
* BREAKING CHANGE, history change to x,y, raw_state|raw_statistic
* Add `internal` to trace configs to hide them
* attribute and period must be truthy to configure an entity , not only exist. This allows overriding a default entity
* add meta to customdata so it is available for texttemplate and hovertemplate
* adds vars to customdata as suggested by @FrnchFrgg
* only postfix attribute or statistc to trace name if the name was not manually overwritten
* fix removeOutOfRange not removing right side of the range
* Fix entities with offsets break autoranging
* use statistic instead of period to determine entity type. (period may be undefined when using auto-period)
* map "unavailable" ,"none" and "unknown" to none

296
296
297
+
### Caveats
298
+
299
+
The following exceptions apply to traces with offsets:
300
+
301
+
- They get their own cache, meaning that data will be fetched twice if the same entity is in the plot with a different (or no) offset.
302
+
- Websocket state updates are not used to fill their cache (but a request to the server may be triggered)
303
+
- `extend_to_present`is ignored (because extending to an offset present may be far into the future and that messes up with autorange)
304
+
297
305
### Now line
298
306
299
307
When using offsets, it is useful to have a line that indicates the current time. This can be done by using a lambda function that returns a line with the current time as x value and 0 and 1 as y values. The line is then hidden from the legend.
@@ -389,113 +397,226 @@ entities:
389
397
extend_to_present: true # false by default for statistics
390
398
```
391
399
392
-
### `lambda:` transforms
400
+
### `filters:`
393
401
394
-
`lambda` takes a js function (as a string) to pre process the data before plotting it. Here you can do things like normalisation, integration. For example:
395
-
396
-
#### Normalisation wrt to last
402
+
Filters are used to process the data before plotting it. Heavily inspired by [ESPHome's sensor filters](https://esphome.io/components/sensor/index.html#sensor-filters).
403
+
Filters are applied in order.
397
404
398
405
```yaml
399
406
type: custom:plotly-graph
400
407
entities:
401
-
- entity: sensor.my_sensor
402
-
lambda: |-
403
-
(ys) => ys.map(y => y/ys[ys.length-1])
408
+
- entity: sensor.temperature_in_celsius
409
+
filters:
410
+
411
+
# The filters below will only be applied to numeric values. Missing (unavailable) and non-numerics will be left untouched
412
+
- add: 5 # adds 5 to each datapoint
413
+
- multiply: 2 # multiplies each datapoint by 2
414
+
- calibrate_linear:
415
+
# Left of the arrow are the measurements, right are the expected values.
416
+
# The mapping is then approximated through linear regression, and that correction is applied to the data.
417
+
- 0.0 -> 0.0
418
+
- 40.0 -> 45.0
419
+
- 100.0 -> 102.5
420
+
- derivate: # computes rate of change per unit of time
421
+
unit: h # ms (milisecond), s (second), m (minute), h (hour), d (day), w (week), M (month), y (year)
422
+
- integrate: # computes area under the curve per unit of time using Right hand riemann integration
423
+
unit: h # ms (milisecond), s (second), m (minute), h (hour), d (day), w (week), M (month), y (year)
424
+
- map_y_numbers: Math.sqrt(y + 10*100) # map the y coordinate of each datapoint.
425
+
426
+
# In the filters below, missing and non numeric datapoints will be discarded
427
+
- sliding_window_moving_average:
428
+
# default parameters:
429
+
window_size: 10
430
+
extended: false # when true, smaller window sizes are used on the extremes.
431
+
centered: true # compensate for averaging lag by offsetting the x axis by half a window_size
432
+
- median:
433
+
# default parameters:
434
+
window_size: 10
435
+
extended: false
436
+
centered: true
437
+
- exponential_moving_average:
438
+
# default parameters:
439
+
alpha: 0.1 # between 0 an 1. The lower the alpha, the smoother the trace.
440
+
441
+
# The filters below receive all datapoints as they come from home assistant. Y values are strings or null (unless previously mapped to numbers or any other type)
442
+
- map_y: y === "heat" ? 1 : 0 # map the y values of each datapoint. Variables `i` (index), `x`, `state`, `statistic` and `meta` and `vars` are also in scope.
443
+
- map_x: new Date(+x + 1000) # map the x coordinate (javascript date object) of each datapoint. Same variables as map_y are in scope
444
+
- fn: |- # arbitrary function. Only the keys that are returned are replaced. Returning null or undefined, leaves the data unchanged (useful )
445
+
446
+
({xs, ys, meta, states, statistics}) => {
447
+
# either statistics or states will be available, depending on if "statistics" are fetched or not
448
+
# attributes will be available inside states only if an attribute is picked in the trace
- resample: 5m# Rebuilds data so that the timestamps in xs are exact multiples of the specified interval, and without gaps. The parameter is the length of the interval and defaults to 5 minutes (see #duration for the format). This is useful when combining data from multiple entities, as the index of each datapoint will correspond to the same instant of time across them.
455
+
- filter: y !== null && +y > 0 && x > new Date(Date.now()-1000*60*60) # filter out datapoints for which this returns false. Also filters from xs, states and statistics. Same variables as map_y are in scope
456
+
- force_numeric # converts number-lookinig-strings to actual js numbers and removes the rest. Any filters used after this one will receive numbers, not strings or nulls. Also removes respective elements from xs, states and statistics parameters
457
+
```
458
+
459
+
#### Examples
460
+
461
+
##### Celcious to farenheit
462
+
463
+
```yaml
464
+
- entity: sensor.wintergarten_clima_temperature
465
+
unit_of_measurement: °F
466
+
filters: # °F = °C×(9/5)+32
467
+
- multiply: 1.8
468
+
- add: 32
404
469
```
405
470
406
-
#### Normalisation wrt to first fetched value
471
+
alternatively,
407
472
408
473
```yaml
409
-
- entity: sensor.my_sensor
410
-
lambda: |-
411
-
(ys) => ys.map(y => y/ys[0])
474
+
- entity: sensor.wintergarten_clima_temperature
475
+
unit_of_measurement: °F
476
+
filters: # °F = °C×(9/5)+32
477
+
- map_y_numbers: y * 9/5 + 32
412
478
```
413
479
414
-
note: `ys[0]`represents the first "known" value, which is the value furthest to the past among the downloaded data. This value will change if you scroll, zoom out, change the hours_to_show, or just let time pass.
480
+
##### Energy from power
481
+
482
+
```yaml
483
+
- entity: sensor.fridge_power
484
+
filters:
485
+
- integrate:
486
+
unit: h # resulting unit_of_measurement will be W/h
487
+
```
415
488
416
-
#### Accumulated value
489
+
##### Using state attributes
417
490
418
491
```yaml
419
-
- entity: sensor.my_sensor
420
-
unit_of_measurement: "total pulses"
421
-
lambda: |-
422
-
(ys) => {
423
-
let accumulator = 0;
424
-
return ys.map(y => {
425
-
accumulator = accumulator + y;
426
-
return accumulator;
427
-
})
428
-
}
492
+
- entity: climate.loungetrv_climate
493
+
attribute: current_temperature # an attribute must be set to ensure attributes are fetched.
setting it to `true` will remove it from the plot, but the data will still be fetch. Useful when the data is only used by a filter in a different trace
488
599
489
600
```yaml
490
-
- entity: climate.wintergarten_floor
491
-
unit_of_measurement: °C
492
-
lambda: |-
493
-
(ys, xs, entity) => ({
494
-
x: xs.map(x => -x),
495
-
y: ys.map(y => y / 2),
496
-
})
601
+
type: custom:plotly-graph
602
+
entities:
603
+
- entity: sensor.temperature1
604
+
internal: true
605
+
period: 5minute
606
+
filters:
607
+
store_var: temp1
608
+
- entity: sensor.temperature2
609
+
period: 5minute
610
+
name: sum of temperatures
611
+
filters:
612
+
map_y: y + vars.temp1[i].y
497
613
```
498
614
615
+
### `lambda:` transforms (deprecated)
616
+
617
+
Deprecated. Use filters instead.
618
+
Your old lambdas should still work for now but this API will be removed in March 2023.
619
+
499
620
## Default trace & axis styling
500
621
501
622
default configurations for all entities and all yaxes (e.g yaxis, yaxis2, yaxis3, etc).
0 commit comments