Display message works in notification but not with input_text

Hi !

I have a calendar.sabrina entity (that I get from the Google Calendar integration).
I created a “Sabrina” button in lovelace :

type: button
name: Sabrina
tap_action:
  action: call-service
  service: script.get_calendar_events

And I have this script in scripts.yaml :

get_calendar_events:
  alias: "Get Calendar Events"
  sequence:
    - service: calendar.get_events
      target:
        entity_id:
          - calendar.sabrina
      data:
        start_date_time: "{{ now().replace(day=1).strftime('%Y-%m-%dT%H:%M:%S') }}"
        end_date_time: "{{ (now().replace(day=1) + timedelta(days=32)).replace(day=1) - timedelta(seconds=1) }}"
      response_variable: agenda
    - service: persistent_notification.create
      data:
        title: Daily agenda for {{ now().date() }}
        message: >-
          {% set ns = namespace(total_heures = 0) %}
            {% for event in agenda["calendar.sabrina"]["events"] %}
              {% set start_time = as_datetime(event.start) %}
              {% set end_time = as_datetime(event.end) %}
              {% set duration = (end_time - start_time).total_seconds() / 3600 %}
              {% set ns.total_heures = ns.total_heures + duration %}
            {% endfor %}
          {% set total_euros = ns.total_heures * 14 %}
            HEURES
            {% for event in agenda["calendar.sabrina"]["events"] %}
              {{ as_datetime(event.start).strftime('%Y-%m-%d %H:%M') }} - {{ as_datetime(event.end).strftime('%Y-%m-%d %H:%M') }}: {{ event.summary }}
            {% endfor %}
            TOTAL H: {{ ns.total_heures }} heures (14€/h) = {{ total_euros }} €

This automation display some calculations about events in my calendar.sabrina and works perfectly.

But instead getting notification in HA, I want to get the result in an input_text entity so I can display it in lovelace (through Markdown card for example).
So I created a an input_text.get_text entity wich I display in lovelace :

type: markdown
content: |
  {{ states('input_text.get_text') }}
title: Calendar Events Summary

and a “Get Text” button in lovelace :

type: button
name: Get Text
tap_action:
  action: call-service
  service: script.get_calendar_text

And I have this script in scripts.yaml :

get_calendar_text:
  alias: Get Calendar Text
  sequence:
    - service: calendar.get_events
      target:
        entity_id:
          - calendar.sabrina
      data:
        start_date_time: "{{ now().replace(day=1).strftime('%Y-%m-%dT%H:%M:%S') }}"
        end_date_time: "{{ (now().replace(day=1) + timedelta(days=32)).replace(day=1) - timedelta(seconds=1) }}"
      response_variable: agenda
    - service: input_text.set_value
      target:
        entity_id: input_text.get_text
      data:
        value: >-
          {% set ns = namespace(total_heures = 0) %}
            {% for event in agenda["calendar.sabrina"]["events"] %}
              {% set start_time = as_datetime(event.start) %}
              {% set end_time = as_datetime(event.end) %}
              {% set duration = (end_time - start_time).total_seconds() / 3600 %}
              {% set ns.total_heures = ns.total_heures + duration %}
            {% endfor %}
          {% set total_euros = ns.total_heures * 14 %}
            HEURES
            {% for event in agenda["calendar.sabrina"]["events"] %}
              {{ as_datetime(event.start).strftime('%Y-%m-%d %H:%M') }} - {{ as_datetime(event.end).strftime('%Y-%m-%d %H:%M') }}: {{ event.summary }}
            {% endfor %}
            TOTAL H: {{ ns.total_heures }} heures (14€/h) = {{ total_euros }} €

But with that, my Markdown card displays “unknown” and I don’t undersatnd why.
If I replace the value data of the input_text that I set by “Hello World”, no bug, it displays “Hello worlds” when I click on my button.

Thnaks for your help !

when you call get_calendar_text just by itself… forget about all the rest of the stuff… what value do you see in input_text.get_text?

if you don’t see what you want, post the trace of the call to get_calendar_text