texttemplate - display a calculated extra entity value #359
-
Sorry for the noob question, but how do you reference "y" in a customdata expression? I'm trying to display a second value in the texttemplate which is a function of the "y" value.
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 6 replies
-
Try with this: customdata: |
$fn ({statistics}) => {
console.log(statistics); // look at the chrome devtools console
return statistics.map(({mean}) => ({ extra_attr: (mean / 80) }) )
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for your prompt reply! If I use that code I get "NaN". But I suspect you're giving me a nudge in the direction of the answer, however, I'm still not sure what to do with it and haven't managed to google any useful hints. In chrome dev tools console I can see the html produced by plotly, but don't I need to get the value from HA? Would I be right to assume that customdata is not returning a number, as Sorry, I'm still completely lost. |
Beta Was this translation helpful? Give feedback.
-
customdata: |
$ex ys.map(y => ({ extra_attr: y / 80 }) ) Would be the shortest way to do it. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dbuezas/lovelace-plotly-graph-card?tab=readme-ov-file#debugging may help you debugging in the future 💪 |
Beta Was this translation helpful? Give feedback.
-
Well, I don't understand why, in customdata,
Thanks again for your help, and for bringing plotly-graph to us! 🙂 |
Beta Was this translation helpful? Give feedback.
Well, I don't understand why, in customdata,
y
returned the first value rather than the last value, butys[ys.length - 1]
did the trick.Here's where I ended up:
Thanks again for your…