Template syntax error

As you can see from the screen shot it does not like the format but I just cant seem to get it right.

The template works fine in Dev tools.

the code:

service: script.turn_on
target:
  entity_id: script.google_home_resume
data:
  variables:
    action:
      - service: tts.cloud_say
        target:
          entity_id: media_player.home
        data_template:
          {{ set cook_time = states('sensor.meater_cook_time_remaining') }}
          {% if cook_time == 'unknown' %}
            The Meater is unavailable.
          {% else %}
            The {{ states('sensor.meater_cook_name') }} will be ready in {{ 
              relative_time(now() - timedelta(seconds=as_timestamp(cook_time) - as_timestamp(now()))) 
            }}
          {% endif %}
        extra:
          volume: 0.5

Can anyone point where it is wrong please?

You are missing the multi line indicator and you no longer need to use “data_template” just “data” will do, and you have the wrong delimiters for your first line in the template

      - service: tts.cloud_say
        target:
          entity_id: media_player.home
        data: >
          {% set cook_time = states('sensor.meater_cook_time_remaining') %}
          {% if cook_time == 'unknown' %}
            The Meater is unavailable.
          {% else %}
            The {{ states('sensor.meater_cook_name') }} will be ready in {{ 
              relative_time(now() - timedelta(seconds=as_timestamp(cook_time) - as_timestamp(now()))) 
            }}
          {% endif %}

{% %} performs some function, {{ }} prints output.

You could probably also simplify this considerably using has_value() and time_until()

In Developer Tools → States, what is the value of sensor.meater_cook_time_remaining?

Thank you. Unfortunately, I am unable to see the state of sensor.meater_cook_time_remaining without cooking something else.

Screenshot 2024-05-07 at 09.51.10
I’m not sure if the history of states shows the same as it would in dev tools.

You don’t actually have to cook anything, just tell the Meater you are cooking something. Hot water can mimic the internal temp and give you a time remaining once it sets that time.

You can lower the preferred internal temp and speed up your test samples.

I thought the Meater was only water resistant and couldn’t be submerged?

The sensor is in the tip and yes, I don’t recommend submerging it. You can apply heat other ways as well.
Hair dryer, stove etc…

I will have a little play around and see what I can do. Thank you

@Jakesa Avoid the ambient end. Heat up the Food Temperature area.