Now that I have an integration that gives me the state of my fuel tank (sensor.ux250h_fuel_level which returns a value between 0 and 100), I’d like to add a column that displays the price of a fuel top-up (if the gas tank is 30% full, It should display 70% of the previous column).
Below is my code that doesn’t work but should show you what I expect to be able to do. How can I “access” the value of ‘sensor.ux250h_fuel_level’ inside the flex-table-card?
I’m sorry I need so much hand holding
But I’m doing my best, I swear. From your message (and the fact the code doesn’t work ), I understand I could do that only if my sensor had an attribute on top of its state, which isn’t the case:
I believe I cannot add an attribute to an entity created by an integration, so I shall create a custom sensor with a “liters_to_full” attribute, correct?
And then, how can I pull that data into my flex-table-card?
The “vanilla” way is to create a template sensor.
The hacky way - try using a CustomUI plugin, it allows adding an attribute with a dynamic content, kind of:
The 1st question was “how can I use another entity in flex-table”.
Now the question is SOLVED - the value became an attribute.
Rest of other things is about “check docs for the card, ask in the dedicated flex-table-card thread” - there are plenty of examples about “how to show/use attributes in the card”.
Oh, come on, man, the question was “how to do math based on another sensor?”, not “what type of sensor should I create to be able to do math with it later?”
Which is answered - “you can only do it with attributes, not with another entity”.
And how to do it with attributes - explained in docs or in the dedicated thread.
Ok, suggest to use a dedicated thread for this card (there is a huge one in “Share your projects” with simple examples in the 1st post & lots of nice & complex examples in other posts). And suggest to at least have a quick glance on Docs since EVERY example is related to using attributes (each column IS an attribute) and a huge amount of examples are about using a “modify” option which supports JS to address attributes & do math/etc operations on them.
But why are you willing to spend so much time telling me I should seek help elsewhere? Instead of being helpful?
I’m pretty bad in Python but JS is a whole other level: I understand nothing of it. If I could find the answer in the doc, I wouldn’t ask here but it’s like reading Chinese.
I am done. Several times suggested you to read info in ONE place & ask there if any questions are left.
A general schema:
- data: attr_name
modify: >-
... any JS code for x, where x = a value of the attr
name: any name
And if a column for attribute X needs values from attribute X & attribute Y - then this will only work when both values are sub-attributes of some Z attribute - because you only have access to the CURRENT attribute (“data” option), whether it is a single value or a complex structure like list/dictionary:
- data: Z
modify: >-
... any JS code for Z.X & Z.Y
name: any name
This is all described in the dedicated thread & docs. That is why these “main threads” exist - to accumulate questions & answers. Otherwise we will have 100500 threads about the same. Please, go there into that thread and at least check links in the 1st post, they will help you to learn basics.
A hint: tables may be created in Markdown (w/o sorting) - and you can define ANY complex formula for every column (not bound to that “Z.X / Z.Y” limitation)