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
Copy file name to clipboardExpand all lines: readme.md
+80-5Lines changed: 80 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -400,8 +400,6 @@ type: custom:plotly-graph
400
400
entities:
401
401
- entity: sensor.temperature_in_celsius
402
402
name: living temperature in Farenheit # Overrides the entity name
403
-
lambda: |- # Transforms the data
404
-
(ys) => ys.map(y => (y × 9/5) + 32)
405
403
unit_of_measurement: °F # Overrides the unit
406
404
show_value: true # shows the last value as text
407
405
texttemplate: >- # custom format for show_value
@@ -686,10 +684,87 @@ entities:
686
684
map_y: y + vars.temp1[i].y
687
685
```
688
686
689
-
### `lambda:` transforms (deprecated)
687
+
### Universal functions
690
688
691
-
Deprecated. Use filters instead.
692
-
Your old lambdas should still work for now but this API will be removed in March 2023.
689
+
Javascript functions allowed everywhere in the yaml. Evaluation is top to bottom and shallow to deep (depth first traversal).
690
+
691
+
#### Gotchas
692
+
693
+
- The following entity attributes are required for fetching, so if another function needs the entity data it needs to be declared below them. `entity`,`attribute`,`offset`,`statistic`,`period`
694
+
- Functions are allowed for those properties (`entity`, `attribute`, ...) but they do not receive entity data as parameters. You can still use the `hass` parameter to get the last state of an entity if you need to.
695
+
- Functions cannot return functions for performance reasons. (feature request if you need this)
696
+
- Defaults are not applied to the subelements returned by a function. (feature request if you need this)
697
+
- You can get other values from the yaml with the `getFromConfig` parameter, but if they are functions they need to be defined before.
698
+
- If a function throws an exception, the complete plot won't be rendered. Make sure to use `if` statements or [Optional Chaining (?.)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) if the values you use may be undefined.
699
+
700
+
#### Adding the last value to the entitiy's name
701
+
702
+
```yaml
703
+
type: custom:plotly-graph
704
+
entities:
705
+
- entity: sensor.garden_temperature
706
+
name: |
707
+
$fn ({ ys,meta }) =>
708
+
meta.friendly_name + " " + ys[ys.length - 1]
709
+
```
710
+
711
+
#### Sharing data across functions
712
+
713
+
```yaml
714
+
type: custom:plotly-graph
715
+
entities:
716
+
- entity: sensor.garden_temperature
717
+
718
+
# the fn attribute has no meaning, it is just a placeholder to put a function there. It can be any name not used by plotly
0 commit comments