custom-cards / secondaryinfo-entity-row

Custom entity row for HomeAssistant, providing additional types of data to be displayed in the secondary info area of the Lovelace Entities card
172 stars 15 forks source link

Code help #54

Closed Tom-ahawk closed 1 year ago

Tom-ahawk commented 1 year ago

Not an issue, but I am struggling with the syntax. How do I use a sensor state into an if-result like:

secondary_info: '[[ if(sun.sun.attributes.elevation < 0, "Below", "Above") ]] the horizon'  #This works fine

secondary_info: '[[ if (binary_sensor.energy_mode_cost == "on",  "Cost {{ states('sensor.nordpool_kwh_home') }} Kr/kWh ", "") ]]' #ERROR

Please advise.

ildar170975 commented 1 year ago
  1. Try smth like this:

    secondary_info: >-
      [[ if(input_boolean.test_boolean.state == "on","Cost ",
      "") ]]
      [[ if(input_boolean.test_boolean.state == "on",zone.home.state,
      "") ]]
      [[ if(input_boolean.test_boolean.state == "on"," Kr/kWh",
      "") ]]

    Could be cumbersome - but seems to be only solution... image

  2. In SOME cases it is better to use a custom:template-entity-row - it supports jinja. Update: OMG, I forgot that this card does support jinja too))) - see below.

  3. Suggest to ask similar questions in the dedicated Community thread (https://community.home-assistant.io/t/custom-secondary-info-for-entities-card/82551) and leave Github for reporting bugs & proposing FRs.

Tom-ahawk commented 1 year ago
  1. I have this working, but not when text combined with state: secondary_info: >- [[ if(input_boolean.test_boolean.state == "on", "LOOK AT" zone.home.state "TOT", "") ]]

3) Will do

ildar170975 commented 1 year ago
  1. but not when text combined with state:

Exactly. These seem to be unsupported:

"LOOK AT" zone.home.state "TOT",
"LOOK AT" + zone.home.state + "TOT",
ildar170975 commented 1 year ago

Or you may use jinja )))

    secondary_info: >-
      {% if is_state('input_boolean.test_boolean','on') -%}
        Cost {{states('zone.home')}} Kr/kWh
      {%- endif %}
Tom-ahawk commented 1 year ago

Perfect 👍🏻