Strange issue with quotation marks in Scripts

Since some time I have a strange issue with some scripts.
It might be that this started after installing the latest HA update to version 2025.4.2 but I am not sure about that.

This is an example of such a problematic script:

set_slaapduur_current:
  alias: Set current Slaapduur
  sequence:
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.slaapduur
    data:
      time: '{% from ''easy_time.jinja'' import time_between %}{{ time_between(''input_datetime.in_slaap'',
        ''input_datetime.wakker'') }}'

Note the usage of the pairs of single quotation marks.

When I go to Developer tools → ACTIONS, select this script and click on PERFORM ACTION I am getting an error message:

Failed to perform the action script.set_slaapduur_current. Invalid time specified: {% from ‘easy_time.jinja’ import time_between %}{{ time_between(‘input_datetime.in_slaap’, ‘input_datetime.wakker’) }} for dictionary value @ data[‘time’]. Got None

And when I go to Settings → Automations & scenes → Scripts, select the same script and in the top right-hand corner three dots menu select Run script I get the same error message.
However, when I go to the three dots menu next to the script and select Run action the script runs successfully without error messages.

When I paste the same template that is used in the script directly in the Developer tools → TEMPLATE → Template editor I get another error message:

Template:
{% from ''easy_time.jinja'' import time_between %}{{ time_between(''input_datetime.in_slaap'', ''input_datetime.wakker'') }}

Error message:

TemplateSyntaxError: expected token ‘import’, got ‘easy_time’

When I replace each of the pairs of single quotation marks with one single quotation mark or with on double quotation mark in the template the problem is solved.
So these two templates are functioning correctly:

{% from "easy_time.jinja" import time_between %}{{ time_between("input_datetime.in_slaap", "input_datetime.wakker") }}

{% from 'easy_time.jinja' import time_between %}{{ time_between('input_datetime.in_slaap', 'input_datetime.wakker') }}

And this script also does function correctly:

set_slaapduur_current:
  alias: Set current Slaapduur
  sequence:
  - action: input_datetime.set_datetime
    target:
      entity_id: input_datetime.slaapduur
    data:
      time: "{% from 'easy_time.jinja' import time_between %}{{ time_between('input_datetime.in_slaap',
        'input_datetime.wakker') }}"

The problem however is that I did not enter these pairs of single quotation marks in the script myself.
These originally were either normal single or double quotation marks, but have been automatically changed to those pairs of single quotation marks.

It looks like this modification to the quotation marks is triggered by editing one of the scripts via: Settings → Automations & scenes → Scripts, select the script and in the top right-hand corner three dots menu select Edit in YAML. Then make a modification and save the script.
After that all scripts in scripts.yaml were modified and a lot of those pairs of single quotation marks have appeared.

It looks like this is a problem only when using datetime entities in the script (or may be only when using the EasyTime script?), because for instance this script does still function properly:

cast_youtube_to_cc_chromecast:
  alias: Cast YouTube to CC Chromecast
  sequence:
  - action: media_player.play_media
    target:
      entity_id: media_player.cc
    data:
      media_content_type: cast
      media_content_id: '{{ { ''app_name'': ''youtube'', ''media_id'': ( states( ''input_text.ytl''
        ).split( ''v='' )[1] ) } | to_json }}'

Can someone please confirm this issue?
If I am not the only one with this problem I will raise an issue about this on GitHub.

I’m experiencing the same issue. Were you able to fix it? It looks like Jinja templating isn’t being loaded correctly, or the behavior might have changed in recent updates.

Well, I fixed it at that time by modifying the scripts like I did show in my first post, by replacing the pairs of single quotation marks by double quotation marks.
But some time later, when I edited another script via the GUI almost all the double quotation marks in the scripts.yaml file were replaced again by these pairs of single quotation marks (but not all of them).

And after that I found out that the same thing happens with automations: I did edit one automation in the GUI via Settings → Automations & scenes → Automations → Select one automation → Top right three dots → Edit in YAML and after that it appeared that almost all double quotation marks in the automations.yaml file were replaced by these pairs of single quotation marks as well (but again not all of them).
And I have had some problems now with some automations as well…

This is an example of one simple automation that is still working fine, but shows the effect of this.
This is how it now looks like in the automations.yaml file itself:

This is how it now looks like in the GUI:

And this is how it now is shown in the GUI → Edit in YAML mode:

So in the GUI you still see the double quotation marks, but in the yaml file itself there is a mix-up of the quotation marks: the single quotation marks are replaced by the pairs of single quotation marks, and the double quotation marks are replaced by single quotation marks.

There is something fishy going on in the background by replacing quotation marks, causing problems sometimes with specific usage of the yaml code. However, it still isn’t clear to me what formatting exactly causes these issues.
For now I did solve these issues by modifying the yaml code, but I don’t remember exactly what I did change. I don’t think this were all the same kind of modifications.

In the past I used to only work in the plain text yaml files in an external editor, but I am now more and more using the GUI for this, and I must say that I like this way of working: it often is much clearer than editing a large multiline yaml text file in an editor.
But then one has to be aware of this strange quotation mark issue sometimes causing problems.

For the record: I did not upgrade yet to Home Assistant version 2025.5.0 but am still working in version 2025.4.4

Does anybody else know more about this, and what to do to avoid these problems?

Replacing double quotes with two single quotes is a by-product of storing the config as json then converting it back to yaml.

Two single quotes instead of a double quote is valid yaml.

1 Like

Thank you Tom!
I am pretty sure that this only started to happen to me a month or so ago?
Do you know when this was introduced? Was it shown in the release notes?

This has always been the case with the UI editors.

Really?
Well, then this issue must be caused by my use of the GUI more and more lately.
So I have to be more careful with mixing working in both the GUI and plain yaml files.
Case closed :wink: