Help to create a LIST of elements, then display it

Hi there,

I would like to display a list of phone numbers … 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 reset (overwritten) 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 ??

Many Thanks !!

Please don’t post the same question multiple times (Display a list of items - #6 by cedricdelecole)

And to help others to help you: post/format your YAML code properly.

1 Like

Smth like this (untested):

template:
  - trigger:
      ...
    actions:
      ...
    sensor:
      - name: last_calls
        state: ...
        attributes:
          history: >-
            {% set CURR = this.attributes['history'] -%}
            {%- set NEW = [{
                            'phone': ... phone no ...,
                            'time': now().isoformat()
                          }] -%}
            {{(CURR + NEW)[:5]}}

In “actions” - send a notification.
“:5” - to keep last 5 numbers (you can set it to 500).

Thank you @Ildar_Gabdullin but is this an helper I need to create to store the phone number ?

For the moment I have created a text helper called “input_text.derbier_appelant_fritzbox”, but only allowing me to store 1 phone number at the time … :

  - 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")}}

or I need to use the templates.yaml ??
But I do not get it.
My last calling phone number is stored in :

  - 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")}}

… here is my templates.yaml file

- sensor:
    # Net Power"
    - name: "NetPower"
      unique_id: 8d4f5ecc-e745-49df-811c-c30eeabe5ea4
      icon: mdi:flash
      unit_of_measurement: "W"
      state: >
        {{ states('sensor.shellypro3em_c8f09e879cec_phase_a_active_power') }}

    # Production Panneaux solaires"
    - name: "NetProduction"
      unique_id: 0bc77fce-e1ea-4989-8d90-7d90559d4f55
      icon: mdi:flash
      state: >
        {{ states('sensor.shellypro3em_c8f09e879cec_phase_b_active_power') }}

    # List of last calls
    - name: fritzbox_last_calls
      state: ...
      attributes:
        history: >-
          {% set CURR = this.attributes['history'] -%}
          {%- set NEW = [{
                          'phone': ... phone no ...,
                          'time': now().isoformat()
                        }] -%}
          {{(CURR + NEW)[:5]}}