I would think you could do a webhook
Hi,
My question looks long but I’m just trying to be exhaustive. My JS skills are non-existant and reading the card documentation is extremely hard for me, so I try to be as clear as possible when seeking your help.
I have a bit over 100 entities created by an integration ( Prix Carburant) that reports fuel prices in my area.
I use Flex-table-card to filter (I’m interested in certain types of fuel only), sort (the cheaper the better) and display the data.
It looks like this:
The column “Plein” shows the price multiplied by the tank capacity. I do that with a modify: Intl.NumberFormat('fr',{minimumFractionDigits:2,maximumFractionDigits:2}).format(parseFloat(x)*43), with 43 being the tank capacity in liters.
So far, so good.
Now, my issue is with the “Appoint” column: it should show the cost of a top-up from the current amount of fuel in the car to a full tank. The current level of fuel in the tank is stored by an entity created by another integration. Ildar_Gabdullin told me I couldn’t do math with another state and I had to create a template sensor with the current fuel level as an attribute, which I did. Of course, it’s not an attribute of the fuel price entity, it can’t be since data are generated independently by two integrations.
So my question is “How can do math based on another sensor?” Id est, how can I replace the hard-coded “43” by data from another entity?
To help, below is the code of my card
type: custom:flex-table-card
sort_by: state+
clickable: true
title: UX 250h
max_rows: 5
entities:
include:
- sensor.station_*E10
- sensor.station_*SP95
- sensor.station_*SP98
columns:
- data: entity_picture
align: center
name: ""
modify: "'<img src=\"' + x + '\" style=\"height: 35px; max-width: 100px;\">'"
- data: fuel_type
align: center
name: ""
icon: mdi:gas-station
- data: address,city
multi_delimiter: ", "
align: left
name: ""
- icon: mdi:currency-eur
data: state
name: " "
align: center
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:3,maximumFractionDigits:3
}).format(parseFloat(x))
suffix: €/l
- data: state
name: Plein
align: center
modify: Intl.NumberFormat('fr',{ minimumFractionDigits:2,maximumFractionDigits:2}).format(parseFloat(x)*43)
suffix: €
- data: state
name: Appoint
align: center
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:2,maximumFractionDigits:2
}).format(parseFloat(x)*43*(1-25/100))
suffix: €
- data: distance
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:1,maximumFractionDigits:1
}).format(parseFloat(x))
suffix: " km"
name: Distance
- icon: mdi:calendar-clock
name: " "
data: days_since_last_update
align: center
prefix: J+
css:
tbody tr:nth-child(1): "color: #00C62D; font-weight: bold"
layout_options:
grid_columns: 8
My fuel level (created by the Toyota integration) is the state of sensor.ux250h_fuel_level
The code of my template sensor that calculates the amount of liters necessary to reach a full tank and store is as an attribute:
- sensor:
- name: "UX250h Carburant en litres"
unique_id: ux250h_fuel_in_liters
state: "{{ states('sensor.ux250h_fuel_level') | float(0.1) * 43/100}}"
unit_of_measurement: "L"
device_class: volume
attributes:
tank_capacity: 43
liters_to_full: "{{ (100 - states('sensor.ux250h_fuel_level') | float(0.1)) * 43 / 100 }}"
As a hint for a next one, try to provide a minimal (!) example to indicate the issue.
For as far as I can tell, this could do it, the helper has value ‘5’ right now
type: 'custom:card-templater'
card:
type: custom:flex-table-card
sort_by: state+
clickable: true
title: UX 250h
max_rows: 1
entities:
include:
- sensor.station_*E10
- sensor.station_*SP95
- sensor.station_*SP98
columns:
- data: address,city
multi_delimiter: ", "
align: left
name: ""
- icon: mdi:currency-eur
data: state
name: " "
align: center
modify: >-
x
suffix: €/l
- data: state
name_template: rest
align: center
modify_template: >
{{ states('input_number.test_total') }} * x
entities:
- something
I probably misunderstood your code, it doesn’t work:
You have a second entities option at the same indentation with - something? That something is the entity that gives the fuel level?
We’re working with state and not attribute?
name vs name_template?
modify vs modify_template?
Sorry for being so helpless :-/
Just copy/paste the code and replace the input_helper… with yours, that should work, then you can take it stepwise further. You can even leave ‘something’ as is (read the card-templater docs if you want to extend its usage)
EDIT: I am assuming that you installed the card-templater (via HACS)
Yeah, I finally understood you used lovelace-card-templater ![]()
There is no way to achieve this with the Flex-table-card by itself?
Possibly but this is least complex imo and you will now also have learned how to use templates in cards that donot support templates
But now I have one more custom component to manage, make sure it doesn’t break anything when I update it, etc. So, if it’s possible to avoid it…
This card-templater has been there since ages and works fine, repeating that you can also use it for other cards or even use it to provide template-based headers in this one… it is your choice of course and maybe someone else will chime in… I will stop making this a chatty answer/reply now ![]()
1st post → “what can be shown in a row?”
Already suggested here that if a column must contain foo(x,y) where x,y - different attributes of same entity or attributes/states of different entities - then these data need to be a part of ONE attribute:
- data: Z
modify: >-
... any JS code for Z.X & Z.Y
name: any name
i.e. one attribute Z is a dictionary like:
{
X: some data,
Y: some data
}
For that you will need to create a template sensor.
I have no idea how I can create a template sensor with a dynamic number of entities (I’m not creating the fuel sensors, an integration is)
Ok, in my last post in your another tread I also suggested to consider a stock Markdown card. You can create tables in markdown. If creating a template sensor is difficult for you, may be the Markdown alternative would be easier? Can you at least LIST your data in a table-like list in “Dev tools - Template”?
I’m not sure I could, I don’t control the entities, the integration does. It’s susceptible to add or remove fuel stations dynamically
The simplest code to print out a table-like structure:
{%- set LITRES = states("input_number.test_number")|float(default=0) -%}
{%- for STATE in states.sensor
|selectattr('entity_id','in',integration_entities('waze_travel_time'))
|rejectattr('state','in',['unavailable','unknown']) -%}
{%- set STATE_NAME = state_attr(STATE.entity_id,"attribution") -%}
{%- set PRICE_PER_LITRE = state_attr(STATE.entity_id,"duration") -%}
{%- set PRICE_TOTAL = PRICE_PER_LITRE * LITRES -%}
{{STATE_NAME}} {{PRICE_PER_LITRE|round(2)}} eur/l {{PRICE_TOTAL|round(2)}} eur
{% endfor -%}

Then:
- Adapt this example for your sensors (a matter of “Templating”).
- Make a table in Markdown (search in Community, plenty of examples, one of them).
So, here perhaps it is easier to choose a Markdown instead of creating own template sensor exclusively for flex-table-card.
I’m so out of my depth here, I have no idea what you want me to do.
I guess I’m gonna leave that idea alone, I’ll do the math in my mind ![]()
Yes, it requires having basic skills in jinja.
Hi all,
I need help filtering entities.
I have a custom:flex-table-card showing gas prices (a list of “station” sensors containing “SP98”). I’d like to filter them by brand.
Each sensor has a brand attribute, I want to show only the ones with the brand containing “Agip” or “Total” (including “Total access”) or “Esso” (including “Esso Express”).
In my mind, it would look like this:
entities:
include:
- sensor.station_*SP98
filter:
- attribute: Brand
value: Agip || Esso* || Total*
I found one example in the doc (which is so scattered it’s really hard to search for anything) that mentions filtering by attribute: flex-table-card/info.md at 781c4b71f45c26c320f6e912c683671bca50d0b5 · custom-cards/flex-table-card · GitHub
…but 1. it works only for one attribute value (in my case, that would be only one brand) and 2. it displays the attribute in the table (which I don’t want to do)
My current full code:
type: custom:flex-table-card
clickable: true
sort_by: state+
title: M Coupé
max_rows: 5
entities:
include:
- sensor.station_*SP98
columns:
- data: entity_picture
align: center
name: ""
modify: "'<img src=\"' + x + '\" style=\"height: 35px; max-width: 100px;\">'"
- data: fuel_type
align: center
name: ""
icon: mdi:gas-station
- data: address,city
multi_delimiter: ", "
align: left
name: ""
- icon: mdi:currency-eur
data: state
name: " "
align: center
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:3,maximumFractionDigits:3
}).format(parseFloat(x))
suffix: €/l
- data: state
name: Plein
align: center
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:2,maximumFractionDigits:2
}).format(parseFloat(x)*55)
suffix: €
- data: distance
modify: >-
Intl.NumberFormat('fr',{ minimumFractionDigits:1,maximumFractionDigits:1
}).format(parseFloat(x))
suffix: " km"
name: Distance
- icon: mdi:calendar-clock
name: ""
data: days_since_last_update
align: center
prefix: J+
css:
thead th: "background-color: #1144ab"
tbody tr:nth-child(1): "color: #00C62D; font-weight: bold"
layout_options:
grid_columns: 8
I would only see an option with auto-entities, like this
type: 'custom:auto-entities'
filter:
include:
- entity_id: sensor.station_*gazole
attributes:
brand: "/(Total|Esso|Agip)/"
card:
etc.etc.
@vingerha You always come up with a solution and offer a code example, I really appreciate that
I’ll keep that solution in mind but I don’t have custom:auto-entities and I try to avoid installing new components when I can because it’s another thing to maintain and another failure point.
I thought I could build the list with a template sensor and parse it to the card but it doesn’t work (or I couldn’t find the right syntax??): [FR] accepting a list in an attribute as the entities parameter · Issue #199 · custom-cards/flex-table-card · GitHub
Has anyone another idea? For a native HA solution, I mean
I understand the preference and I myself aim to add as little as possible too. However, in this case, do note that also flex-table-card has a specific section that refers to a solution with auto-entities and one could guess that this is not for nothing (covering certain limitations). Recently the ownership of auto-entities has been taken over (fork) so it is maintained.
Wrt to template, I assume you aimed for this to have max control in-house? It should be feasible but it is quite a bit of code too.


