If it’s possible for there to be no events, you could wrap the for loop in a check to confirm it’s not empty to prevent errors or to display some special message in that case.
{% if state_attr('sensor.calendar_next_week','scheduled_events') != None %}
{% for ... %}
{% endfor %}
{% else %}
No events this week!
{% endif %}
display:
- platform: ...
# ...
lambda: |-
// at this point calendar_next_week has to be an object/array
int counter=0;
for( const auto& item : id(calendar_next_week).state) {
it.printf(20, 20 + ( counter * 30), id(normal_font), item['start'] );
it.printf(60, 20 + ( counter * 30), id(normal_font), item['summary'] );
counter++;
}
Thing is, I don’t know how to get the data as an object from sensor.calendar_next_week into the ESP32 board. So, text_sensor: has a character limit. And I don’t know if there is an other way to import the data.
Sorry about that. I use an RSS reader that lumps various forum categories together, and didn’t notice that detail of your question. Unfortunately, I don’t have any ideas for your actual problem
text_sensor:
# get the calendar data over to ESP
- platform: homeassistant
id: calendar_scheduled_events
entity_id: sensor.calendar_scheduled_events
on_value:
then:
- lambda: 'id(data_updated) = true;'
- lambda: |-
ESP_LOGI("main", "Scheduled Events: %s", id(calendar_scheduled_events).state.c_str());
id(data_updated) = true;
For testing I have 6 events in this, and the logfile shows “6”
Deep in my lambda display code I can see the “6” as well, but I have absolutely no clue on how to run thru this array and print the individual entries.