Trigger Template Sensors and attributes

When do attributes get updated for trigger template sensors?

I have a trigger template sensor whose state is defined using a non-trivial template.
The sensor attributes are also based on a very simple template and rely on the state of the ‘parent’ sensor.

It appears to me that when triggered, the attributes might be being updated at the same time as the state instead of afterwards causing the attributes to be evaluated using the value for the state of the sensor before it gets updated (by the non-trivial template).

(By which I mean the attributes appear to be being evaluated too quickly i.e. before the state.)

Is this true?
If so, I would suggest that this is undesirable behaviour.

Here is a contrived and simplified example of my sensor (excluding the trigger which is not necessary for illustrative purposes)

sensor:
  name: my_sensor
  state: >
    {% non trivial template here %}
    {{ resulting in a number from 1 to 6 }}
  attributes:
    attribute_name: >
      {% set VALUE = states('sensor.my_sensor') %}
      {{ states('input_boolean.my_boolean_' ~ VALUE) }}

I have the same problem. Attribute templates seem to be evaluated in parallel to the state. So they consume the old state. As attributes are additional information to the state their templates should be evaluated when state processing is done. Or is there a another way to get it in the right order?

For the moment I worked around this problem using trigger variables like this:

- trigger:
    - platform: state
      entity_id:
        - sensor.triggering_sensor
      variables:
        _state: >-
          {% non trivial template here %}
          {{ resulting in a number from 1 to 6 }}
  sensor:
    name: my_sensor
    state: "{{ _state }}"
    attributes:
      attribute_name: >
        {% set VALUE = _state %}
        {{ states('input_boolean.my_boolean_' ~ VALUE) }}

For anyone landing here, the solution is in this post (thanks to @123)