Setting a variable

I want to change a variable after a trigger has fired.
That means something like that

blueprint:
    name: Bluetest
    description: Testing of a blueprint
    domain: automation
    input:
        timeOpen:
            name: timeOpen
            description: Time
            selector:
                time:

trigger:
  - platform: time
    at: !input timeOpen

variables:
  text: "Hello"

action:
    service: >
        {%- set text = "Echo" -%}
          system_log.write
    data_template:
        message: >
            {{ text }}
mode: single

But the log output is always “Hello” and not “Echo”.
Is there a way to achieve this?

Answering to myself in case somebody else has a similar problem.
Even in YAML syntax the Fundamental theorem of software engineering is still true :slight_smile:

I still don’t know whether variables can be changed, but I can accomplish my goal by calling another script, ie. something like this:

blueprint:
    name: Bluetest
    description: Testing of a blueprint
    domain: automation
    input:
        timeOpen:
            name: timeOpen
            description: Time
            selector:
                time:

trigger:
  - platform: time
    at: !input timeOpen

variables:
  text: "Hello"

action:
    service: script.do_something
    data:
         msg: >
          {%- if now().strftime( "%T" ) < "11:00" -%}
            {{ text }}
          {%- else -%}
            "Echo"
          {%- endif -%}

mode: single

You have to overwrite it in the message, not the service. But tbh, that defeats the purpose of variables as they are always resolved after the trigger. You should just put the syntax in the variable.

action:
    service: system_log.write
    data_template:
        message: >
            {% set text = "echo" %}
            {{ text }}

To clarify more… each template field is independent from each other. Changes you make in 1 template will not transfer to another. Only variable templates transfer to the other templates, hence the name variables.

That is quite helpful to know. Are these details explained somewhere?

It’s implied. Triggers and Conditions are for automations. The action section & accompanying fields are scripts. All information about scripts are in the script documentation. By definition, actions occur after conditions and triggers, so do variables.

1 Like

Thanks a lot @petro . I didn’t make the connection between an action in an automation and a normal script. For me variables were just one part of an automation. I’ll try it tomorrow. This could solve my problem i started with.