Open koburg opened 3 months ago
How-to questions are typically handled elsewhere...Issues
is for bugs and feature requests, as I understand it.
The answer to your question is here.
As of the latest release, you can use scripts in addition to templates. You can repeat the block to add more rows, while a more dynamic solution would involve adding some looping logic.
Here's a simple case:
type: custom:flex-table-card
title: Weather Condition Report
entities: []
service: script.test_response
columns:
- name: Accuweather
data: current_weather
modify: x.weather1
- name: National Weather Service
data: current_weather
modify: x.weather2
test_response:
alias: Test Response
variables:
the_data: >
{% set current = { "current_weather": [
{
"weather1" : states("weather.home"),
"weather2" : states("weather.kboi_daynight")
},
] }
%}
{{ current }}
sequence:
- stop: All Done
response_variable: the_data
I should point out that the script version will not refresh since no entities are being monitored for state changed events. So if the table is to be left up for any period of time, the template approach is the better solution.
Note that these steps to prepare your data for display allow you to combine entity state and attributes in the same table as shown below, which is not possible by using the entities directly.
From configuration.yaml
:
template:
- sensor:
- name: "Test Flex"
state: Not Used
attributes:
current_weather: >-
{% set current = [
{
"weather0" : "Current Conditions",
"weather1" : states("weather.home"),
"weather2" : states("weather.kboi_daynight")
},
{
"weather0" : "Current Temperature",
"weather1" : state_attr("weather.home", "temperature") | string +
" " + state_attr("weather.home", "temperature_unit"),
"weather2" : state_attr("weather.kboi_daynight", "temperature") | string +
" " + state_attr("weather.home", "temperature_unit"),
},
{
"weather0" : "Current Wind Speed",
"weather1" : state_attr("weather.home", "wind_speed") | round | string +
" " + state_attr("weather.home", "wind_speed_unit"),
"weather2" : state_attr("weather.kboi_daynight", "wind_speed") | round | string +
" " + state_attr("weather.kboi_daynight", "wind_speed_unit"),
},
]
%}
{{ current }}
The flex-table-card
:
type: custom:flex-table-card
title: Weather Condition Report (Template)
entities:
include: sensor.test_flex
columns:
- name: ''
data: current_weather
modify: x.weather0
- name: Accuweather
data: current_weather
modify: x.weather1
- name: National Weather Service
data: current_weather
modify: x.weather2
is it possible to use states from different sensors in different columns:
entities:
columns:
regards Allan