Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use different states in different columns #134

Open
koburg opened this issue Mar 22, 2024 · 2 comments
Open

use different states in different columns #134

koburg opened this issue Mar 22, 2024 · 2 comments

Comments

@koburg
Copy link

koburg commented Mar 22, 2024

is it possible to use states from different sensors in different columns:

entities:

  • sensor.sensor1
  • sensor.sensor2

columns:

  • data: state (sensor1)
    name: water
  • data: state (sensor2)
    name: soup

regards Allan

@EdLeckert
Copy link
Contributor

EdLeckert commented Mar 22, 2024

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

weathercondition

@EdLeckert
Copy link
Contributor

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

WeatherTemplate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants