Help with template for au futur blueprint

Hello everybody,

for a futur blueprint i need templating something like that but i don’t find the syntax

{% set today2 = now().strftime('%A') | lower %}
{{ today2 }}

{% set saturday_morning_time = states('input_datetime.saturday_morning_time') %}
saturday morning time : {{ saturday_morning_time }}

{% set morningtime = {{ today2~'_morning_time' }} %}
morningtime : {{ morningtime }}

I don’t find the syntax for having the value of "morningtime" which is the state of the concat with the day.
Also the same of the variable saturday_morning_time
I try brackets, simple quote, curly brackets, double quote, parenthesis…

Is anybody have an idea please ?

Thanks a lot

The idea is to have sunday_morning_time and compare in a template using today2

You cannot nest one template inside of another template.

What you want is this:

{% set morningtime = today2~'_morning_time'  %}

Hi,

Thanks for your response.

I don’t want this.
this give me the string if the value of today2 is saturday for exemple, the result is
saturday_morning_time

What i want is the value of saturday_morning_time in the variable morningtime concat by today2~_morning_time
that’s why i put the curly brackets. around today2~_morning_time

I don’t find the workaround.

I misunderstood your example:

{% set morningtime = {{ today2~'_morning_time' }} %}

Anyway, you definitely cannot nest one template in another.


It’s not entirely clear to me what exactly you are attempting to achieve. It appears you are trying to evaluate this template first:

{{ today2~'_morning_time' }}

To produce a string like saturday_morning_time.

That string represents the name of an existing variable and you want to assign its value to a new variable called morningtime.

In other words, you are trying to do this:

{% set morningtime = saturday_morning_time %}

Except you don’t know the name of the variable on the right hand side, you are trying to create it dynamically with today2~'_morning_time'. Is that correct?

If my understanding of what you are trying to do is correct, I don’t believe it’s possible. You’re looking for the ability to dynamically create a variable’s name and then get its value. That would require something like python’s eval function but it isn’t available here.

Hi,
Thanks, you understand perfectly.

Exactly. In fact in blueprint i create some input with selector time as

  • saturday_morning_ime
  • sunday_morning_time
  • monday-morning_time

After i would compare like this

if {{ now().strftime("%H:%M:%S") }} > today2~'_morning_time' .....

you confirm thats is not possible with jinja and blueprint.
I will find a workaround, i hope :wink:

If you have an idea please :wink:

And you’re right, in python_scripts the comparison works :wink: for one of my script.

But with blueprint the creation of automation is really simple :wink: and user-friendly :wink:

I don’t know if this will help you but you can dynamically create an entity name then get its value.

states('input_datetime.' ~ now().strftime('%A') | lower ~ '_morning_time')

You can use it in an if statement like this:

{% if now().strftime("%H:%M:%S") > states('input_datetime.' ~ now().strftime('%A') | lower ~ '_morning_time') %}
... do something ...
{% else %}
... do something else ...
{% endif %}

Yeah,

Thanks a lot. I will search but at this moment i dont know how to do with the blueprint in whic is declare like

saturday_morning_time:
      name: 'Heure de début de la période : "SAMEDI MATIN"'
      description: Heure du début de la période du "SAMEDI matin".
      default: "06:00:00"
      selector:
        time:

and

variables:
  saturday_morning_time: !input saturday_morning_time