📝 100% Templatable Lovelace Configurations

Any feedback/help please?

There must be something stupid I am doing that stop all the rest of the static text to be showed.

Did you try states['binary_sensor.andrea_oneplus5_charging'].state === true ? 'Charging' : 'Not Charging' ?

Yes, by itself it does work (and yes, I changed true to on) :slight_smile:

If it is working by itself, the template should be fine. With variables now possible, I would try putting in variables.

Current status:

secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : ''}"

Result in:
image

While this:

secondary_info: "${states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? 'Charging' : ''}"

Correctly return:
image

You mean put the text in a variable?

What if you just try secondary_info: "${states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? 'Charging' : 'Not Charging'}"?

Ehm, it’s my second example, which works correctly :wink:

Here is a other example i wanted to do that since a while, make the opacity of the lights on my 3D floor plan follow my real lights. thanks for that card!!!
Here is a little video demonstration:
https://youtu.be/qj2n5xoRNT0


The code is taken from the Lovelace editor

- type: 'custom:config-template-card'
  config:
    type: 'custom:card-modder'
    card:
      type: 'custom:hui-picture-elements-card'
      image: /local/floorplan.png
      elements:
        - entity: light.kitchen
          image: /local/fp_kitchen_off.png
          style:
            left: 66.9%
            top: 26.7%
            width: 17.88%
          state_filter:
            'off': opacity(0%)
            'on': >-
              ${"opacity(" + (states['light.kitchen'].attributes.brightness /
              2.55) + "%)"}
          tap_action:
            action: toggle
          type: image
13 Likes

Awesome!
I’m going to plan on adding updates only on attribute changes in the future as well which should improve performance for anyone using attributes

EDIT: Wait, I’m already checking the full state object for the entity…nevermind :slight_smile: Just restricting by entities will work :tada:

1 Like

Try this

secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + (states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : '')}"

I believe the eval didn’t like your ternary not being wrapped. I tested it here and is probably a good place to test your logic quickly:

1 Like

Hi @iantrich, I tried your code but it actually returns a new error:

while parsing a block mapping in “/home/ha/.homeassistant/lovelace/views/test.yaml”, line 28, column 23 expected <block end>, but found ‘<block mapping start>’ in “/home/ha/.homeassistant/lovelace/views/test.yaml”, line 32, column 24

I also tried to check the JS Bin site you posted but I am not sure how am I supposed to use it because also when I add the code you suggested it return an error
"SyntaxError: Invalid or unexpected token

Share you new config

You can’t just copy that line into jsbin, if you see what I defined for states, it doesn’t match your’s exactly. You also need to not include the ${} as I strip those out in my code before running eval

1 Like

Oh I am sorry!
I didn’t realize that the link was pointing to a pre-coded page, I tought the code was just example and I pasted the code in there , my bad!

Regarding the YAML error in HA I added an unnecessary additonal white space at the beginning, now it works!!!
image
image

Thank you so much!

1 Like

:tada: Release 1.0.5 :tada:

:warning: Breaking Change: config renamed to card

5 Likes

Looking great, care to share your config of the card?

Sure thing, here it is:

              - type: custom:config-template-card
                config:
                  type: custom:hui-entities-card
                  title: House Members
                  show_header_toggle: false
                  entities:
                    - entity: person.andrea
                      type: "custom:secondaryinfo-entity-row"
                      secondary_info: "${'OnePlus 5 Battery: ' + states['sensor.andrea_oneplus5_battery'].state + '%' + (states['binary_sensor.andrea_oneplus5_charging'].state === 'on' ? ' - Charging' : '')}"

I tried variables:

            card:
              type: 'custom:hui-entities-card'
              title: MQTT & Wifi Connections
              show_header_toggle: false
              variables:
                - states['sensor.sonoff1_2914_status'].attributes['MqttCount']
                - states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount']
              entities:
                - entity: sensor.sonoff1_2914_status
                  name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + vars[0] + '\xa0'.repeat(4) + 'WiFi ' + vars[1]}"

But it shows unknown… did I do something wrong?

Also trying this:

                - entity: sensor.sonoff1_2914_status
                  name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + states['sensor.sonoff1_2914_status'].attributes['MqttCount'] + '\xa0'.repeat(4) + 'WiFi ' + states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount'] + states['sensor.sonoff1_2914_status'] >= 100 ? 'Excellent' : states['sensor.sonoff1_2914_status'] > 80 ? 'Good' : states['sensor.sonoff1_2914_status'] > 60 ? 'Fair' : 'Weak'}"

To append information about the WiFi RSSI strength… Excellent, Good, Fair or Weak to the end… but doesn’t seem to like that either

Any ideas?

I got my variables: option before the config:/card: line of custom:config-template-card.

1 Like

Ah that will be it for the error… but why isn’t my conditional info showing?

                - entity: sensor.sonoff1_2914_status
                  name: "${'Coffee' + '\xa0'.repeat(16) + 'MQTT ' + states['sensor.sonoff1_2914_status'].attributes['MqttCount'] + '\xa0'.repeat(4) + 'WiFi ' + states['sensor.sonoff1_2914_status'].attributes['WiFi LinkCount'] + states['sensor.sonoff1_2914_status'] >= 100 ? 'Excellent' : states['sensor.sonoff1_2914_status'] > 80 ? 'Good' : states['sensor.sonoff1_2914_status'] > 60 ? 'Fair' : 'Weak'}"

states[‘sensor.sonoff1_2914_status’] probably is not giving you a number, maybe parseFloat(states[‘sensor.sonoff1_2914_status’].state) ?