iantrich / config-template-card

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

Issue with template sensor #22

Closed zappasmart closed 4 years ago

zappasmart commented 4 years ago

Description of problem:

In my test I have a template sensor that changes value, name and icon based on an input boolean.

Displaying the template sensor in sensor or entities cards works well, state changes are correctly detected and value, name and icon properly updated when input boolean toggles.

However, if sensor or entities cards are surrounded by config-template-card, they don't detect the input boolean state changes properly. I used the config-template-card only to dinamically change the theme (a blue or orange theme), based on the input boolean state.

Input Boolean OFF

When input boolean is off, blue theme is correcly applied, card content is correctly displayed: image

Input Boolean turned ON

When input boolean is turned on, orange theme is correctly applied but card content is not updated: image

Input Boolean turned OFF

When input boolean is turned back off, blue theme is correctly applied but card content is wrongly updated: image

configuration.yaml:

input_boolean:
  test:

sensor:
  - platform: template
    sensors:
      test:
        entity_id:
          - input_boolean.test
        unit_of_measurement: '°C'
        device_class: temperature
        value_template: >-
          {% if is_state('input_boolean.test','on') %}
            20
          {% else %}
            -20
          {% endif %}
        icon_template: >-
          {% if is_state('input_boolean.test','on') %}
            mdi:fire
          {% else %}
            mdi:snowflake
          {% endif %}
        friendly_name_template: >-
          {% if is_state('input_boolean.test','on') %}
            Hot
          {% else %}
            Cold
          {% endif %}

lovelace:

    cards:
      - type: entities
        entities:
          - entity: input_boolean.test
            name: Heat
            icon: 'mdi:fire'
      - type: 'custom:config-template-card'
        entities:
          - input_boolean.test
        card:
          type: 'custom:hui-sensor-card'
          entity: sensor.test
          graph: line
          theme: >-
            ${ states['input_boolean.test'].state === 'on' ? 'OrangeTheme'
            : 'BlueTheme' }
      - type: 'custom:config-template-card'
        entities:
          - input_boolean.test
        card:
          type: 'custom:hui-entities-card'
          entities:
            - sensor.test
          theme: >-
            ${ states['input_boolean.test'].state === 'on' ? 'OrangeTheme'
            : 'BlueTheme' }
      - type: sensor
        entity: sensor.test
        graph: line
      - type: entities
        entities:
          - entity: sensor.test
iantrich commented 4 years ago

Try having both entities listed in the config-template-card. This is what dictates when things should change. Those entities dictate what things inside the card should update.

entities:
  - input_boolean.test
  - sensor.test