Hi all.
Ive been fiddling with something on and off, but keep getting stuck at the same point.
In a nutshell, i want to display a list of things, similar to the shopping list integration, but not.
Example:
I have a json payload, and i want to list the items in a card - even an entities or glance card would do.
{“items”:[“Car”,“Horse”]}
Items:
Car
Horse
Short of throwing the info into google keep or todoist, i just dont seem to be able to find a way!
TIA!
1 Like
juaigl
(Juaigl)
May 30, 2021, 11:51am
2
How about markdown card??
type: markdown
content: >-
Items:
{% set my_test_json = { "items": ["car","horse"] } %}
{% for item in my_test_json["items"] %}
* {{item}}
{%- endfor %}
Delete the line with set my_test_json and then replace it by the entity or attribute where your json is stored:
e.g:
states(“sensor.my_json”) where my_json is the sensor that stores your json
state_attr(“sensor.my_sensor”, “my_json”) where my_json is an attribute of my_json sensor that stores your json in a attribute.
type: markdown
content: >-
Items:
{% for item in states("sensor.my_json")["items"] %}
* {{item}}
{%- endfor %}
Result:
1 Like
I think that’s exactly what I’m looking for. Will give it a go.
Thanks!
And this generates a list of all the entitites that end with “_battery”, so that it can be pasted on a statistics graph for example.
{% for item in states.sensor|selectattr('entity_id', 'search', '_battery$')|map(attribute='entity_id')|list %}
- {{item}}{%- endfor %}
Remove the $ if you want to make it “contains _battery” (eg. entities that are _battery_state)
Just sharing because I had to mix & match from multiple posts, but juaigl comment gave me the final structure
2 Likes
juaigl:
t markdown card?
Hello, similar to, I also would like to display a list, but a list of phone number … where can I STORE that list.
For the moment I have created a “text” helper which contains the last called phone number … but it is rested each time a new call is made. I would like to make “LIST” of all the phone numbers, then display them.
Here is my test helper
and here is my automation writing the phone number in that helper … but how do I ADD a new phone number every time, on top of already existing phone numbers in that helper ??
juaigl
(Juaigl)
June 29, 2024, 10:36am
7
Use a template sensor.
In the state only store the last number (state is limited to 255 chars)
In one state attribute you can store a list or a dict with all the calls.
Check this post: Store list/dictionary ?! - #8 by 123
Template sensor: Template - Home Assistant
I am sorry but I can’t figure out to use a template.
A template is asking me if binary or not, then the ‘unit’ and “device class” …
What I have here is a phone number I would like to store, in a list, phone nulbers after phone numbers, then display them.
My code is currently the following :
alias: Nouvelle automatisation
description: ""
trigger:
- platform: state
entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
to: ringing
condition: []
action:
- service: persistent_notification.create
data:
message: >-
Un appel est émis de
{{state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
"from")}}
- service: input_text.set_value
target:
entity_id: input_text.dernier_appelant_fritzbox
data:
value: >-
{{
state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
"from")}}
- wait_for_trigger:
- platform: state
entity_id: sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique
from: ringing
to: idle
- service: persistent_notification.create
data:
message: >-
Appel manqué ou raccroché de {{
states("counter.nombre_d_appels_manques") }} + {{
states("input_text.dernier_appelant_fritzbox") }} +
{{state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
"from")}} "- Nombre d'appels manqués ou raccrochés :" {{
states("counter.nombre_d_appels_manques") }}
- service: counter.increment
metadata: {}
data: {}
target:
entity_id: counter.nombre_d_appels_manques
mode: single
see the section where I catch the phone number and store it in an helper :
- service: input_text.set_value
target:
entity_id: input_text.dernier_appelant_fritzbox
data:
value: >-
{{
state_attr("sensor.fritz_box_7530_ax_call_monitor_repertoire_telephonique",
"from")}}
I understand I need to replace this simple text helper by something allowing me to store a LIST, but do not understad what helper I need to create
;-(
jcmleng
September 26, 2024, 8:16am
9
I am trying to generate a list of my zigbee-related entities with “_linkquality”. I used your code which you posted some time back and it works perfectly.
The code fails without the ‘search’ in the selectattr cmd. I have also seen other code to generate lists of entities (eg. using selectattr, but but not “for”) but does not use the ‘search’ parameter at all. Have searched a lot of pages on jinja coding, I can’t seem to find anywhere which explains the purpose of this ‘search’ parameter and when it should be used/not used.
Do you use ‘search’ because you are searching ALL sensor entity_id’s and you want it to SEARCH for any entity_id which has ‘_battery$’, then list it.
Sorry to ask what seems like (and may well be!) a dumb question but I couldn’t find the answer via the documentation. Many thanks for helping with this!
It’s about Regular Expressions: Templating - Home Assistant
Seen here: Selectattr to match part of the attribute - #2 by Burningstone
Do not believe that I know what I’m doing. I just Googled it right now
When it comes to the code I shared, I just grabbed the code from somewhere for a similar search, and changed it to battery.
jcmleng
September 26, 2024, 12:45pm
11
Thanks for the links - they are really helpful!
Good to know I am not the only one!