Give a sensor a state (string) after condition has been met in a template

An example, where if sentence checks, whether time is over or under 21:00

{% if states('sensor.time') < '21:00' | timestamp_custom('%H:%M', False)  %}
       Hello
{% else %} 
       bye
 {% endif %}   

Question: How can I, instead of hello or bye give a sensor.xx_yy a string value? E.g. if condition is met, sensor.xx_yy receives value “Hello” and so on.

Sensor is not defined anywhere else, this is where i try to define it and use it then elsewhere.

Or if the approach is not right, how shoulkd it be done?

Are you asking how to set up a Template Sensor?

I basically know how to set up a template sensor, but I seem not to figure out how, in combination with the abovementiuoned if-clause, I could initialize a string (sensor) variable in template

Can you clarify what you are trying to do? Your original template is doing a string comparison, not a datetime object or timestamp comparison. Also, both possible return values are strings…

you can’t set a value of a different regular sensor in an automation. Sensor states are determined solely by it’s integration.

the only things I know of that you can set the values of programatically are helpers and template sensors that are set by their own internal logic.