Lovelace conditional card on entity state attribute

On the lovelace ‘conditional’ card type, how would I mode the card on an attribute of an entity.

For example, take a climate entity on the generic-thermostat platform, that has the two (and only two) presets which are: away and none. There seems to be no way to mode on the preset mode. For example, the following does not work in lovelace yaml:-

  - type: conditional
    conditions:
      - entity: climate.my_thermostat.preset_mode
        state: 'away'
    card:
      ..
      ..

Never mind, solved.
I do no think it is possible directly in the conditional card
But is is possible to create a template sensor and mode on that:

# Example configuration.yaml entry
binary_sensor:
  - platform: template
    sensors:
      my_thermostat_in_programmer_mode:
        friendly_name: 'Room thermostat'
        unit_of_measurement: 'degrees'
        value_template: >-
          {{ (state_attr('climate.my_thermostat','preset_mode') == 'away') and (states('climate.my_thermostat') == 'heat') }}

and change the lovelace to:

- type: conditional
    conditions:
      - entity: sensor.my_thermostat_in_programmer_mode
        state: true 
    card:
      ..
      ..

voila!

Just FYI in case you find this thread.

2 Likes

You saved my day! :slight_smile:

Though the Lovelace card config should use binary_sensor and state: 'on'!

  - type: conditional
    conditions:
      - entity: binary_sensor.my_thermostat_in_programmer_mode
        state: 'on'

binary_sensors have binary logicality - so 1,true,on are all the same - logically.
:wink:

I’ve tested it again, it works only with on, but NOT with 1 or true.

Disclaimer: I’m new to HA, so maybe missed something, but really tested it. :slight_smile:

no idea what your config is so cannot comment.