Entity char length limit issue - Advice sought

Hello Community,
I have hit a bit of a road block and are seeking advice.
I am creating a schedule using @neliss scheduling component. I take the scheduling attributes and create a template sensor which I want to send to my ESP32 device, where I will use the schedule to provide local control of a heating system (similar to @BrianHanifin irrigation controller, but with on / off state control using a RTC, so if HA is down the device continues follow the schedule) .
The issue I am having is once I combine the attributes into a string via the template I get a unknown value if the length is over 255 chars.
My template code is as follows:-

            {% set days = state_attr('switch.schedule_24abce','weekdays')%}
              {% set times = state_attr('switch.schedule_24abce','timeslots')%}
              {% set actions = state_attr('switch.schedule_24abce','actions.service')%}
              {% set ns = namespace(counter=0) %} 
              {%- for day in days -%}
                {% set day_var = {"sun": "1", "mon": "2", "tue": "3", "wed": "4", "thu": "5", "fri": "6", "sat": "7"}[day] | default("") %}
                {%- set ns.counter = 0 %}
                {%- for time in times %}
                  {%- set actions = state_attr('switch.schedule_24abce','actions')[ns.counter].service %}
                  {%- set action = actions.split('_') %}
                  {%- set start_time = time.split(' - ') -%}
                  {{ day_var }}:{{ start_time[0] }}={{action[1]}},
                  {%- set ns.counter = ns.counter + 1 %}  
                {%- endfor %}
              {%- endfor %}
              {%- set daysa = state_attr('switch.schedule_873981','weekdays') %}
              {%- set timesa = state_attr('switch.schedule_873981','timeslots') %}
              {%- set actionsa = state_attr('switch.schedule_873981','actions.service') %}
              {%- set ns = namespace(counter=0)  %} 
              {%- for day in daysa -%}
                {% set day_var = {"sun": "1", "mon": "2", "tue": "3", "wed": "4", "thu": "5", "fri": "6", "sat": "7"}[day] | default("") %}
                {%- set ns.counter = 0 %}
                {%- for timea in timesa %}
                  {%- set actions = state_attr('switch.schedule_873981','actions')[ns.counter].service %}
                  {%- set action = actions.split('_') %}
                  {%- set start_time = timea.split(' - ') -%}
                  {{ day_var }}:{{ start_time[0] }}={{action[1]}}{%if not loop.last %},{% endif %}
                  {%- set ns.counter = ns.counter + 1 %}  
                {%- endfor %}
              {%- endfor %}

The resultant string using the template editor in dev tools is

7:00:00:00=off,7:17:00:00=on,7:22:50:00=off,1:00:00:00=off,1:17:00:00=on,1:22:50:00=off,2:00:00:00=off,2:18:00:00=on,2:20:50:00=off3:00:00:00=off,3:18:00:00=on,3:20:50:00=off4:00:00:00=off,4:18:00:00=on,4:20:50:00=off5:00:00:00=off,5:18:00:00=on,5:20:50:00=off6:00:00:00=off,6:18:00:00=on,6:20:50:00=off

The scheduler looks like this (note have to use 2 schedulers weekdays and weekend schedule)

So I am looking for advice as to how to get this data to the esp device running ESPhome in a efficient way that can be easily consumed by ESPhome
Thanks in advanced

Template attributes don’t have that limit. I assign lists to attributes and give a simpler value to the state.

Thank you @BrianHanifin for your advice. In the end I used a python script to generate the schedule and used a ESPhome user defined service to get the data to the device. Code posted below that might help some else in this position.

# schedule_service.py
daySchedule = []
day_entity_id = data.get('day_entity_id')
wk_entity_id = data.get('wk_entity_id')
logger.info('send schedule called')
if day_entity_id is not None:
    state = hass.states.get(day_entity_id)
    days = state.attributes.get('weekdays') or 'none'
    times = state.attributes.get('timeslots') or 'none'
    actions = state.attributes.get('actions') or 'none'
    for day in days:
      action_cnt = 0
      for time in times:
        action = list(actions[action_cnt].values())[0:1][0]
        action = action.split('_')[1]
        time = time.split(' - ')[0]
        day = day.replace('sun', '1').replace( 'mon', '2').replace( 'tue', '3').replace( 'wed', '4',).replace('thu', '5').replace( 'fri', '6').replace( 'sat', '7')
        sched_item = day + ':' + time + '-' + action +','
        daySchedule.append(sched_item)
        action_cnt =  action_cnt+ 1
if wk_entity_id is not None:
    state = hass.states.get(wk_entity_id)
    days = state.attributes.get('weekdays') or 'none'
    times = state.attributes.get('timeslots') or 'none'
    actions = state.attributes.get('actions') or 'none'
    for day in days:
      action_cnt = 0
      for time in times:
        action = list(actions[action_cnt].values())[0:1][0]
        action = action.split('_')[1]
        time = time.split(' - ')[0]
        day = day.replace('sun', '1').replace( 'mon', '2').replace( 'tue', '3').replace( 'wed', '4',).replace('thu', '5').replace( 'fri', '6').replace( 'sat', '7')
        sched_item = day + ':' + time + '-' + action + ','
        daySchedule.append(sched_item)
        action_cnt =  action_cnt+ 1
logger.info('Sending %s', daySchedule)

if daySchedule is not None:
    hass.services.call('esphome', 'boiler_controller_update_schedule', {'schedule_string':daySchedule })

On the esp end here is the service code

  services:
    - service: update_schedule
      variables:
        schedule_string : string[]
      then:
        - text_sensor.template.publish:
            id: ha_sent_schedule
            state: !lambda |-
                      std::string s;
                      for (std::vector<std::string>::const_iterator i = schedule_string.begin(); i != schedule_string.end(); ++i)
                        s += *i;
                      return s;
   

This presents the following service to HA

1 Like