Falcon4Tech / ha

Home Assistant Assets
0 stars 0 forks source link

Im sure its me - configuration error #1

Open timmills opened 1 week ago

timmills commented 1 week ago

Hi, Im new to creating customer cards and tried to follow your instructions. I selected a new entity card, clicked on the code editor and replaced the code with yours and am getting this error.

`Configuration errors detected: missed comma between flow collection entries (1:2)

1 | {% set attr = "battery" %} ------^ 2 | {% set sensors = [ 3 | "sensor.atc_bb0b_battery",`

This is the start of the YAML that I altered `{% set attr = "battery" %}

{% set sensors = [ "sensor.atc_bb0b_battery", "sensor.unit1_98db_battery", "sensor.unit1_98db_battery" ] %} `

Am I putting this code in the wrong spot - sorry for the most basic of questions!

Falcon4Tech commented 1 week ago

I should put this information in the instructions.

Use the markdown card to paste the code from the repository. Or edit the existing one to start with:

type: markdown
content: >-
  {% set attr = "battery" %}
timmills commented 1 week ago

Wow thanks for the quick reply!

type: markdown content: {% set attr = "battery" %} {% set sensors = [ "sensor.atc_bb0b_battery", "sensor.unit1_98db_battery", "sensor.unit1_98db_battery" ] %}

Configuration errors detected: missed comma between flow collection entries (3:2)

1 | type: markdown 2 | content: 3 | {% set attr = "battery" %} ------^ 4 | {% set sensors = [ 5 | "sensor.atc_bb0b_battery",

Falcon4Tech commented 1 week ago

You missed >- in line 2: content: >-

timmills commented 1 week ago

was the same with that too: Configuration errors detected: missed comma between flow collection entries (3:2)

1 | type: markdown 2 | content: >-

timmills commented 1 week ago

OK ive had a bit of a fiddle.. I included state. in the variable which I shouldn't have. I then threw it through chat GPT it now dynamically pulls all entities with battery in the name (and removes battery when displaying)

type: markdown content: >- {% set attr = "battery" %} {% set sensors = namespace(entities=[]) %}

{% set battery_entities = states | selectattr('entity_id', 'search', 'battery') | list %}

{% for entity in battery_entities %} {% set sensor_id = entity.entity_id %} {% set sensor_state = states[sensor_id] %} {% if sensor_state %} {% set signal_strength = sensor_state.state | int(default=0) %} {% set last_changed = as_timestamp(sensor_state.last_changed) %} {% set time_diff = (as_timestamp(now()) - last_changed) | round %}

  {% set sensor_name = sensor_state.attributes.friendly_name.replace(' Battery', '') %}

  {% set sensor_data = {
    "e": sensor_id.split('.')[1].replace('_', ' ').title(),
    "n": sensor_name,
    "t": signal_strength,
    "d": time_diff
  } %}

  {% set sensors.entities = sensors.entities + [sensor_data] %}
{% endif %}

{% endfor %}

{% set sensors.entities = sensors.entities | sort(attribute='t', reverse=true) %} {% set max_length = 6 %}


  {% for t in sensors.entities %}
  {%- if t.d // 60 > 60 %}{% set time = '⇮' ~ (t.d / 60 // 60) | int ~ 'h' %}
  {%- else %}{% set time = (t.d / 60) | int ~ 'm' %}
  {%- endif %}
  {%- set d_length = time | length %}
  {%- set pad_length = max_length - d_length %}
  {%- set d_name = ' ' * pad_length ~ time %}
  {%- if loop.last %}🆘
  {%- elif t.t | int >= 75 %}🟩
  {%- elif 75 > t.t > 25 %}🟨
  {%- else %}🟥{% endif %}
  {{- " " ~ "◼︎" * (t.t // 10) }}{{ " " * (12 - t.t // 10) }}{{ ' %03d' % t.t }}% | {{ d_name }} | {{t.n}}
  {% endfor %}
timmills commented 1 week ago

And the same for Temperature:

type: markdown content: >- {% set attr = "temperature" %} {% set entities = namespace(entities=[]) %}

{% set filtered_entities = states | selectattr('entity_id', 'search', attr) | list %}

{% for entity in filtered_entities %} {% set sensor_id = entity.entity_id %} {% set sensor_state = states[sensor_id] %} {% if sensor_state %} {% set state = sensor_state.state | float(default=0) %} {% set last_changed = as_timestamp(sensor_state.last_changed) %} {% set time_diff = (as_timestamp(now()) - last_changed) | round %}

  {% set sensor_name = sensor_state.attributes.friendly_name %}
  {% if sensor_name %}
    {% set sensor_name = sensor_name.replace(' ' ~ attr.capitalize(), '') %}
  {% endif %}

  {% set sensor_data = {
    "e": sensor_id.split('.')[1].replace('_', ' ').title(),
    "n": sensor_name,
    "t": state,
    "d": time_diff
  } %}

  {% set entities.entities = entities.entities + [sensor_data] %}
{% endif %}

{% endfor %}

{% set entities.entities = entities.entities | sort(attribute='t', reverse=true) %} {% set max_length = 6 %}


  {% for t in entities.entities %}
  {%- set d_length = (t.d) | string | length %}
  {%- set pad_length = max_length - d_length %}
  {%- set d_name = ' ' * pad_length ~ t.d %}
  {%- if loop.last %}❄️
  {%- elif t.t > 25 %}🔥
  {%- elif 22 > t.t > 20 %}🟩
  {%- else %}🟨{% endif %}
  {{- " " ~ "◼︎" * (t.t | int // 3) }}{{ " " * (11 - t.t | int // 3) }}{{ '%04.1f' % t.t }}°C | {{ d_name }}s | {{ t.n }}
  {% endfor %}
timmills commented 1 week ago

Align the battery columns: {% set attr = "battery" %} {% set sensors = namespace(entities=[]) %}

{% set battery_entities = states | selectattr('entity_id', 'search', 'battery') | list %}

{% for entity in battery_entities %} {% set sensor_id = entity.entity_id %} {% set sensor_state = states[sensor_id] %} {% if sensor_state %} {% set signal_strength = sensor_state.state | int(default=0) %} {% set last_changed = as_timestamp(sensor_state.last_changed) %} {% set time_diff = (as_timestamp(now()) - last_changed) | round %}

{% set sensor_name = sensor_state.attributes.friendly_name.replace(' Battery', '') %}

{% set sensor_data = {
  "e": sensor_id.split('.')[1].replace('_', ' ').title(),
  "n": sensor_name,
  "t": signal_strength,
  "d": time_diff
} %}

{% set sensors.entities = sensors.entities + [sensor_data] %}

{% endif %} {% endfor %}

{% set sensors.entities = sensors.entities | sort(attribute='t', reverse=true) %}

{% set max_length = sensors.entities | map(attribute='t') | map('string') | map('length') | max %} {% set max_length = 4 if max_length < 4 else max_length + 1 %}


{% for t in sensors.entities %}
  {%- if t.d // 60 > 60 %}{% set time = '⇮' ~ (t.d / 60 // 60) | int ~ 'h' %}
  {%- else %}{% set time = (t.d / 60) | int ~ 'm' %}
  {%- endif %}
  {%- set d_length = time | length %}
  {%- set pad_length = max_length - d_length %}
  {%- set d_name = ' ' * pad_length ~ time %}

  {%- set black_squares = "◼︎" * (t.t // 10) %}
  {%- set white_squares = "◻︎" * (10 - (t.t // 10)) %}

  {%- if loop.last %}🆘
  {%- elif t.t | int >= 75 %}🟩
  {%- elif 75 > t.t > 25 %}🟨
  {%- else %}🟥{% endif %}

  {{- " " ~ black_squares ~ white_squares }}{{ ' %03d' % t.t }}% | {{ d_name }} | {{ t.n }}
{% endfor %}
Falcon4Tech commented 1 week ago

Looks good. But please note, your template listens for all state changed events. So check CPU utilisation after add this card to dashboard.