Packing a REST sensor state with a larger number of dates than the 255 character limit allows

I’m extracting a large list of dates using a REST sensor and running into the 255 character limit. Knowing the list only contains date_times to exact minutes, I’ve been playing with ideas to pack more items in. Firstly converting from data_time to timestamp allowed 23 dates to the nearest second. Using as_timestamp(x)//60 allows me to pack in 28 (//60 converts to minutes, using 8 characters plus a separator per date). I’d like to go further, ideally to 60. It then struck me that these timestamps can be represented by 32bit integers which in turn could be represented by 4 ASCII characters. Allowing another character as a separator makes 5 per, ie 51 dates packed into 255 characters. Not quite my target of 60, but close enough. The trouble is I can’t work out how to do it and my understanding of the terminology for what is going on hasn’t allowed me to search successfully. Can any kind soul point me in the right direction?
What I’ve got so far:

{% set value_json = 
[{
    "DateTime": "2025-02-11T00:00:00Z",
    "Height": 1.897947
}, {
    "DateTime": "2025-02-11T00:01:00Z",
    "Height": 1.904356
} etc
] %}

            {% set target, offset = states('input_number.tide_low_restriction')|float(1.5), states('sensor.tide_offset')|float(0) -%}            {% set ns = namespace(times='') -%}
            {% for item in value_json -%} 
              {% if loop.previtem is defined and loop.nextitem is defined -%}
                {% if (item.Height < target-offset and loop.previtem.Height >= target-offset )
                   or (item.Height < target-offset and loop.nextitem.Height >= target-offset ) -%}
                  {% set ns.times = ns.times ~ as_timestamp(item.DateTime)|int//60~',' -%}
                {% endif -%} 
              {% else -%}
                {% if item.Height <= target - offset -%}
                  {% set ns.times = ns.times ~  as_timestamp(item.DateTime)|int//60~',' -%}
                {% endif -%}
              {% endif -%}  
            {% endfor %}
            {% set out =  ns.times -%}
            {{out}}

Incidentally this is getting a list of the times the tide is less than or greater to a certain height restriction, currently only running in developer tools.
I guess another method is the return a list consisting on the number of minutes since the last transition, but that could be a 4 or 5 digit number per plus 9 for the original timestamp, so less efficient & more uncertain.

The usual way to bypass the 255 char state limitation is to use attributes, which do not have this limitation

I’d love to do that but I can’t find anyway of templating attributes in a REST sensor. As far as I can see you can only populate attributes froma a json dictionary defined by the REST response. Unless I’m missing a trick?

alternative approach

  1. create a rest command. It will give you the output of the rest command as response variable
  2. create a trigger based template sensor on a time pattern trigger.
    • in the action section of that template trigger, use the rest command created in step 1
    • in the sensor part of that template trigger, use the response variable of the rest command to create an attribute with over 255 characters.

Bonus: you have a lot more freedom on when to use the rest command by use of trigger and condition section of the template sensor

Thanks, there are 2 new concepts for me in that - I’ll need to read up on REST commands & trigger based template sensors. Are you saying that the response variable to the former can be longer that 255 characters? What is the limit?
Another nice thing about this idea is I can make sure the huge REST response is only called for when I want it rather than every xxx seconds.