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,
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
If I would like to list the side by side, is that an option.
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 }}
You guys especially Troon are todays MVP . Thanks for helping me out
Remember this advice for when the id
rolls over to seven digits .
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.
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):