Pesky state 255 max attribute. Please help me

Hi everybody.
I am trying to get my calendar events into a card using automatio. So far I have been able to get this into a variable, saved into an “input_text” state, but this is not going well. The reason is that if the calendar entries becomes longer than 255 characters, the state either does not get updated, or just goes into an unknown state. What can I use to circumvent this behaviour?

My current automation looks like this:

alias: ALL Calendars to input_text
description: ""
triggers:
  - trigger: time_pattern
    minutes: /1
conditions: []
actions:
  - target:
      entity_id:
        - calendar.isah
    data:
      start_date_time: "{{ today_at('00:00:00') }}"
      end_date_time: "{{ today_at('23:59:59') }}"
    response_variable: Iagenda
    action: calendar.get_events
  - target:
      entity_id: input_text.calendar_eventsI
    data:
      value: |
        {% for calendar, data in Iagenda.items() %}
         - **Isah:**
          {% for event in data.events %}
            {{ event.start | as_timestamp | timestamp_custom('%H:%M') }} - {{ event.end | as_timestamp | timestamp_custom('%H:%M') }} : {{ event.summary }} 
          {% endfor %}
        {% endfor %}
    action: input_text.set_value
mode: single

I hope you can assist, as I am a bit of a newbie.
Cheers
cyber7 (aka Aubrey)

You can’t, not with a text helpr. A state can’t hold more than 255 characters.

The solution may be to set up a template entity/sensor which stores the information in an attribute instead, since those can hold up to 65535 characters (and also directly store lists, dict’s etc. without going through JSON).

According to the following PR, it’s less than that (16 Kb).

Create a Trigger-based Template Sensor that stores the calendar events in its attributes.

template:
  - trigger:
      - trigger: time_pattern
        minutes: /10
    action:
      - action: calendar.get_events
        data:
          start_date_time: "{{ today_at('00:00:00') }}" 
          end_date_time: "{{ today_at('23:59:59') }}"
        target:
          entity_id: calendar.isah
        response_variable: agenda
    sensor:
      - name: Isah Agenda
        unique_id: isah_agenda_abc123
        state: "{{ now().isoformat() }}"
        attributes:
          events: "{{ agenda['calendar.isah']['events'] }}"

You can use a Markdown card, with an appropriate template, to display the contents of sensor.isah_agenda’s events attribute.

The template will look something like this:

{% for event in state_attr('sensor.isah_agenda', 'events') %}
{{ event.start}}: {{ event.summary }}
{% endfor %}

I will try this and report back tomorrow :slight_smile:

THIS is the reason I just love HA. The users are not only friendly, but also extremely helpful. Thank you for the assistance, it works 100%!

1 Like