Template: concat all states since 0:00

Hi,
i have an input_text entity (i am changing it per Rest).
now i want to show all the states of this input_text since midnight in a row on a dashboard.

example:

8:00 changed to "abc"
9:00 changed to "def"
10:00 changed to "ghi"

i want to display “abc, def, ghi” on the dashboard

I know, with statistics i can access Numeric and Binary sensors. But how can i access the history of input_text?

Wouldn’t it be simpler to write small automation that updates another input text when the first one changes? i.e. if ipt1 change then ipt2.state = ipt2.state + ipt1.state?

It’s probably possible to use a SQL sensor to do this retrospectively, but I would just use a trigger-based template sensor to store the values going forward.

template:
  - trigger:
    - platform: time
      at: "00:00:00"
    - platform: state
      entity_id: input_text.example
      not_to:
        - 'unknown'
        - 'unavailable' 
    sensor:
      - name: Input Text History
        unique_id: input_text_history_1_001
        state: |
          {% if trigger.platform == 'state' %}
          {{ trigger.to_state.state }}
          {% else %} not set {% endif %}
        attributes:
          history: >
            {% if trigger.platform == 'state' %}
            {% set current = this.attributes.get('history', []) %}
            {% set new = [{
                "text": trigger.to_state.state,
                "time": now().strftime("%H:%M") }] %}
            {{ (new + current) }}
            {% else %}
            {% endif %}
1 Like

thanks that is a great solution. I’ve changed the state slightly in my favour, so the states shows the history too:

- trigger:
    - platform: time
      at: "00:00:00"
    - platform: state
      entity_id: input_text.work_topic
      not_to:
        - "unknown"
        - "unavailable"
  sensor:
    - name: Arbeits-Themen des Tages
      unique_id: work_topic_history
      state: |
        {% if trigger.platform == 'state' %}
          {% set current = this.attributes.get('history', []) %}
          {% set new = trigger.to_state.state%}
          {{now().strftime("%H:%M")}} {{ new }} 
          {% for issue in current -%}
            {{issue.time}} {{issue.text}}            
          {% endfor -%}
        {% else %} not set {% endif %}
      attributes:
        history: >
          {% if trigger.platform == 'state' %}
          {% set current = this.attributes.get('history', []) %}
          {% set new = [{
              "text": trigger.to_state.state,
              "time": now().strftime("%H:%M") }] %}
          {{ (new + current) }}
          {% else %}
          {% endif %}