Problems with input_text.set_value in automation

I have been using an automation to check my apointments and put them in a input_text with formating to use it in my markdown on my dashboard.

This has been working great for the last few months, but since yesterday, my markdown shows as No appointments while the calendar show the appointments.

I have been trying to troubleshoot this, but when I manually run the list events in dev tools, all appointments show up, and when I add that in the dev tools with the used variable and use the code from the automation to format the events, the results are as they should be.

I looked into the automation trace and all seems to be running as intended and there has been no change made to either the automation or the calendars, so I am kinda clueless on why the input_text is staying empty with the results of markdown showing there are no appointments :confused:

the automation (or at least, the relevant part, as it checks every hour so it removes the events that have passed):

if:
  - condition: time
    after: "00:00:00"
    before: "01:00:00"
then:
  - service: calendar.list_events
    data:
      duration:
        hours: 24
        minutes: 0
        seconds: 0
    response_variable: familiecal
    target:
      entity_id: calendar.home_assistant_all_day_excluded
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in familiecal.events %}<ha-icon
        icon="mdi:calendar-heart-outline"></ha-icon> {{as_timestamp(event.start,
        default=0) | timestamp_custom('%d/%m %H:%M') }} {{
        event.summary}}{{'<br>'}}  {% endfor %}
    target:
      entity_id: input_text.familielist
  - service: calendar.list_events
    data:
      duration:
        hours: 24
        minutes: 0
        seconds: 0
    target:
      entity_id: calendar.willemvermeylen_gmail_com
    response_variable: WillemCal
  - service: input_text.set_value
    data_template:
      value: >-
        {% for event in WillemCal.events %}<ha-icon
        icon="mdi:calendar-account-outline"></ha-icon>
        {{as_timestamp(event.start, default=0) | timestamp_custom('%d/%m %H:%M')
        }} {{ event.summary}}{{'<br>'}}  {% endfor %}
    target:
      entity_id: input_text.willemlist

The dev tools try I did:

{% set familiecal = {
  "events": [
    {
      "start": "2023-10-06T08:00:00+02:00",
      "end": "2023-10-06T13:00:00+02:00",
      "summary": "Samantha: belafspraak"
    },
    {
      "start": "2023-10-06T14:00:00+02:00",
      "end": "2023-10-06T15:00:00+02:00",
      "summary": "Jaylah: start gesprek 14:00"
    },
    {
      "start": "2023-10-06T16:15:00+02:00",
      "end": "2023-10-06T17:00:00+02:00",
      "summary": "Jaylah: zwemles 16:15-17:00",
    }
  ]
}
%}
   {% for event in familiecal.events %}<ha-icon
    icon="mdi:calendar-heart-outline"></ha-icon> {{as_timestamp(event.start,
    default=0) | timestamp_custom('%d/%m %H:%M') }} {{
    event.summary}}{{'<br>'}}  {% endfor %}

The results I got back from the dev tools:

<ha-icon
    icon="mdi:calendar-heart-outline"></ha-icon> 06/10 08:00 Samantha: belafspraak<br>  <ha-icon
    icon="mdi:calendar-heart-outline"></ha-icon> 06/10 14:00 Jaylah: start gesprek 14:00<br>  <ha-icon
    icon="mdi:calendar-heart-outline"></ha-icon> 06/10 16:15 Jaylah: zwemles 16:15-17:00<br>

I tried doing this all in the service call to fully test it, but it seems the dev tools service for input_text.set_value is not accepting the data_template (or I am doing something wrong which is very likely :stuck_out_tongue: )

service: input_text.set_value
data_template: 
  value: >-
    {% set familiecal = {
      "events": [
        {
          "start": "2023-10-06T08:00:00+02:00",
          "end": "2023-10-06T13:00:00+02:00",
          "summary": "Samantha: belafspraak"
        },
        {
          "start": "2023-10-06T14:00:00+02:00",
          "end": "2023-10-06T15:00:00+02:00",
          "summary": "Jaylah: start gesprek 14:00"
        },
        {
          "start": "2023-10-06T16:15:00+02:00",
          "end": "2023-10-06T17:00:00+02:00",
          "summary": "Jaylah: zwemles 16:15-17:00",
        }
      ]
    }
    %}
    
     {% for event in familiecal.events %}<ha-icon
      icon="mdi:calendar-heart-outline"></ha-icon> {{as_timestamp(event.start,
      default=0) | timestamp_custom('%d/%m %H:%M') }} {{
      event.summary}}{{'<br>'}}  {% endfor %}
      
target:
  entity_id: input_text.familielist

The results I get there are the following error:

This service requires field value, which must be provided under data:

I am not sure why it stopped working and what I can do to test this in dev tools or troubleshoot this more to see why the automation is not filling the text_input :confused: So any help would be nice!

Not sure if you need data_template for this service. I have very basic template based service call for input_text and it is working well.

  - service: input_text.set_value
    target:
      entity_id: input_text.tts_input
    data:
      value: '{{trigger.id}} is open for a long time!'

I might be wrong but data_template would not used by new services anymore, it was built earlier. Now, using data and value with template should work

That would mean that the service test in dev tools would look like this right?

service: input_text.set_value
data: 
  value: >-
    {% set familiecal = {
      "events": [
        {
          "start": "2023-10-06T08:00:00+02:00",
          "end": "2023-10-06T13:00:00+02:00",
          "summary": "Samantha: belafspraak"
        },
        {
          "start": "2023-10-06T14:00:00+02:00",
          "end": "2023-10-06T15:00:00+02:00",
          "summary": "Jaylah: start gesprek 14:00"
        },
        {
          "start": "2023-10-06T16:15:00+02:00",
          "end": "2023-10-06T17:00:00+02:00",
          "summary": "Jaylah: zwemles 16:15-17:00",
        }
      ]
    }
    %}
    
     {% for event in familiecal.events %}<ha-icon
      icon="mdi:calendar-heart-outline"></ha-icon> {{as_timestamp(event.start,
      default=0) | timestamp_custom('%d/%m %H:%M') }} {{
      event.summary}}{{'<br>'}}  {% endfor %}
      
target:
  entity_id: input_text.familielist

Because on my mobile I don’t get an error now, but it also not seems to update the target input_text :confused:

Let me check and get back to you, I am at home :slight_smile:

I have no idea why, but suddenly it started fixing itself just now…

Both the family and my own calendar are now again being filled by the automation. I do wonder why this stopped working and fixed itself again now though :confused:

The test one I did just now to check if it was the automation or my manual testing constantly but delayed. And that too was now added after the family ones were suddenly filled by themselves.

screenshot

1 Like

Either a network error if it is all local, or a delay in gettiong information from whatever cloud service you may be using?

I was thinking so to and i did had network issues this morning, but even after that was fixed and i restwater the home assistant, it was still trying the calendar info from Google and was able to parse it correctly, but somehow failed to set the input_text. Which is not needing any network at all (local or remotely)

I cannot give advice as I do not know your exact setup, all I can say is, dig, dig, and dig to look through history and logs, as a friend of mine used to say to me at work, “Learn to enjoy it!”

haha, yeah used to go through logs at work, so no issues there :sweat_smile: problem is that I have no idea where I could see errors with the part of putting the data that the automation gathers into the input_text. That is why I was trying to replicate this with the dev tools, but i kinda got stuck as the dev tools services wouldn’t accept the data_template.

But the main thing I do with this is gather the info from the Google calendar with calendar.list_events, give it a response_variable (familiecal in this case), and use that response_variable to put the data into the input_text with input_text.set_value formatted into a way it looks good in the markdown card I have.

Nothing too fancy and apart from the Google calendar needing to sync with HA, it is all local. And the weird part is that the data was in the calendar, so I was able to grab that with list_events and even parse it with the data_template value I use in the input_text.set_value through setting the response from the calendar.list_events into the familiecal variable in the dev tools template and then run the data that is used by input_text.set_value and getting the correct info there, so the only part that was failing was either the input_text which was failing to save the data or the set_value which failed to execute (even after a HA restart).

It was pointed out to me that the limit for states is 255 characters and that this might be the reason it was failing to save it in the input_text and did manage to do so later that dat when one of the appointments was gone.

Is there a way I can circumvent this? Can I save the output in the attribute (if it supports more then 255 characters) or could I save it in a file and load that output in markdown with an !include?