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

Added named variables #43

Merged
merged 1 commit into from
Oct 27, 2020
Merged

Conversation

jpeletier
Copy link
Contributor

This PR adds named variables support to variables: in the configuration.

If variables is a key-value map, then vars[] can be indexed by name. Moreover, the variables are injected when evaluating the template and are directly available by name, which greatly improves the readability of a yaml configuration that uses templates, namely:

type: 'custom:config-template-card'
variables:
  LIGHT_STATE: states['light.bed_light'].state
  GARAGE_STATE: states['cover.garage_door'].state
  CURRENT_TEMP: states['climate.ecobee'].attributes.current_temperature
  ALARM_STATE: states['alarm_control_panel.alarm'].state
entities:
  - light.bed_light
  - cover.garage_door
  - alarm_control_panel.alarm
  - climate.ecobee
card:
  type: "${LIGHT_STATE === 'on' ? 'glance' : 'entities'}"
  entities:
    - entity: alarm_control_panel.alarm
      name: "${GARAGE_STATE === 'open' && ALARM_STATE === 'armed_home' ? 'Close the garage!' : ''}"
    - entity: binary_sensor.basement_floor_wet
    - entity: climate.ecobee
      name: "${CURRENT_TEMP > 22 ? 'Cozy' : 'Too Hot/Cold'}"
    - entity: cover.garage_door
    - entity: "${LIGHT_STATE === 'on' ? 'light.bed_light' : 'climate.ecobee'}"
      icon: "${GARAGE_STATE === 'open' ? 'mdi:hotel' : '' }"

This change is backwards-compatible with the current vars[n] syntax.

@iantrich iantrich merged commit 3eeead8 into iantrich:master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants