iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
434 stars 56 forks source link

Variables: use VARIABLE_1 to define VARIABLE_2 #47

Closed ildar170975 closed 1 year ago

ildar170975 commented 3 years ago

Earlier I could use one variable to define another variable:

    type: 'custom:config-template-card'
    variables:
      - 'states[''input_select.graph_hours_to_show_sys'']'
      - 'states[''input_boolean.graph_realtime_sys'']'
      - '''binary_sensor.rpi_power_status'''
      - 'vars[1].state === "on" ? vars[2] : "sensor.test_zero"'      #### LOOK AT THIS !!!!
    entities:
      - '${vars[0].entity_id}'
      - '${vars[1].entity_id}'
      - '${vars[3]}'
    card:
      type: history-graph
      entities:
        - entity: '${vars[2]}'
          name: Питание
      hours_to_show: '${vars[0].state}'
      refresh_interval: 0

изображение

Now I am trying to use variables SENSOR & INPUT_REALTYME to define a variable SENSOR_TO_BE_CHECKED - and I am failed:

type: 'custom:config-template-card'
variables:
  HOURS_TO_SHOW: 'states[''input_select.graph_hours_to_show_sys'']'
  INPUT_REALTYME: 'states[''input_boolean.graph_realtime_sys'']'
  SENSOR: '''binary_sensor.rpi_power_status'''
  SENSOR_TO_BE_CHECKED: 'INPUT_REALTYME.state === "on" ? SENSOR : "sensor.test_zero"'
entities:
  - '${HOURS_TO_SHOW.entity_id}'
  - '${INPUT_REALTYME.entity_id}'
  - '${SENSOR_TO_BE_CHECKED}'
card:
  type: history-graph
  entities:
    - entity: '${SENSOR}'
      name: Питание
  hours_to_show: '${HOURS_TO_SHOW.state}'
  refresh_interval: 0

изображение

Look, now it works again:

type: 'custom:config-template-card'
variables:
  HOURS_TO_SHOW: 'states[''input_select.graph_hours_to_show_sys'']'
  INPUT_REALTYME: 'states[''input_boolean.graph_realtime_sys'']'
  SENSOR: '''binary_sensor.rpi_power_status'''
#  SENSOR_TO_BE_CHECKED: 'INPUT_REALTYME.state === "on" ? SENSOR : "sensor.test_zero"'
entities:
  - '${HOURS_TO_SHOW.entity_id}'
  - '${INPUT_REALTYME.entity_id}'
#  - '${SENSOR_TO_BE_CHECKED}'
card:
  type: history-graph
  entities:
    - entity: '${SENSOR}'
      name: Питание
  hours_to_show: '${HOURS_TO_SHOW.state}'
  refresh_interval: 0

изображение

I suspect that now I cannot ise a VARIABLE_1 to define a VARIABLE_2.

ildar170975 commented 1 year ago

Solution is simple - use vars["your_var_name"] Check this example:

    variables:
      BOOL: states['input_boolean.test_boolean']
      COLOR: '(vars["BOOL"].state === "on") ? "red" : "green"'