Using data from Rest Sensor in Dashboard

The only diff from your example is that " is replaced with ’

That’s the problem. Use this in the markup card (careful with the quotes!):

{% for i in (states('sensor.resource_120_rest')|replace("'",'"'))|from_json %}

That gave a different output, :slight_smile:

type: markdown
content: |-
  type: markdown
  content: |-
    {% for i in (states('sensor.resource_120_rest')|replace("'",'"'))|from_json %}
      <ha-alert alert-type="error">{{ i }}</ha-alert>
    {% endfor %}
title: TEST

Why have you doubled these up?

Because I’m an idiot :slight_smile:

If I would like to list the side by side, is that an option. Skærmbillede 2023-02-23 kl. 10.46.54

Perfect. One last question. Trying to get the “Today” to work. But the rest sensor respond with nothing.
When using my API, I use the filter. Later Than. It sends it correctly. But when I use EQ the response is empty. Any good ideas


 sensor:
    - name: "Resource_120_rest_today"
      value_template: >
          {{ value_json
             |selectattr('startCalendar','eq',now().date()|string)
             |map(attribute='id')
             |map('truncate',length=6,end='')
             |list }}

Nevermind, Just switched < with > then the response is correct

Skærmbillede 2023-02-23 kl. 11.03.46

You guys especially Troon are todays MVP . Thanks for helping me out

2 Likes

Remember this advice for when the id rolls over to seven digits :wink: .

I’ve encountered a response, that returns 10 ID’s, if I would limit that to eg. 5. Where to do so ?

          {{ (value_json
              |selectattr('startCalendar','<',now().date()|string)
              |map(attribute='id')
              |map('truncate',length=6,end='')
              |list)[:5] }}

Open bracket at the beginning of the template, close at the end then follow with [:x] where x is the maximum number of elements you want. That gives you the first x elements — if you want the last x elements, use [-x:] instead.

Alternatively, if you want the full list in the sensor but restrict the card, same technique in the markdown card code:

    {% for i in ((states('sensor.resource_120_rest')|replace("'",'"'))|from_json)[:5] %}

It still works. but I’ve encountered when I Reload HA, the markdowns goes blank, and I need to manually refresh the screen by F5 og Switching dashboards. Do you have a simple fix for this ?
@Troon

The code now looks like this :

{% for i in (states('sensor.resource_301_rest')|replace("'",'"'))|from_json %}
  <ha-alert alert-type="error">{{ i }}</ha-alert>
{% endfor %}
{% for i in (states('sensor.resource_301_rest_today')|replace("'",'"'))|from_json %}
  <ha-alert alert-type="success">{{ i }}</ha-alert>
{% endfor %}
{% for i in (states('sensor.resource_301_rest_future')|replace("'",'"'))|from_json %}
  <ha-alert alert-type="info">{{ i }}</ha-alert>
{% endfor %}

Restart HA less frequently. Mine goes weeks without a restart — why are you restarting so often?

I’m building it, so adding new sensors and changes daily. :slight_smile:

In a lot of cases, a restart isn’t needed. See Developer Tools / YAML for the sections you can reload; and with the new 2023.3 release, you have a quick reload option (equivalent to clicking all the items in the list on the YAML page):

image