The template can be enhanced if you let me know the constraints. For example, if the values can only be less than 4, we can do this:
template:
- sensor:
- name: Wärmepumpe - Betriebszustand
unique_id: gw_warmepumpe_status_sg_ready_betriebszustand
state: >
{% set x = states('sensor.warmepumpe_status_sg_ready_betriebszustand_numeric') | int(0) %}
{{ 'Zustand ' ~ x if x <= 4 else 'Failed' }}
NOTE
Correction. It’s state not value_template. This is a Template Sensor in modern format, not legacy format.
EDIT
I’m not sure if periods are allowed in the value of unique_id (it should be a slug which doesn’t allow using any character) so I changed it to an underscore.
The sensor doesn’t appear because it has a syntax error.
You have defined a Template Sensor in modern format yet you used the name of an option that is only supported by legacy format.
In modern format, the option’s name is state not value_template.
NOTE
Unless this application has a more complex requirement, the use of a map is overkill for appending a number to the string ‘Zustand’. A simple template can do that as shown in my example above.
The example in the first post contains two mistakes:
It used value_template instead of state in a modern format Template Sensor which caused the error “property value_template is not allowed”.
Changing value_template to state fixed one problem but exposed another, namely the template contains an error. The map keys are numeric but the sensor’s value is a string. The quick fix is to use int(0) to convert the sensor’s value from string to integer.
However, as mentioned, there’s no need for a map to perform a simple string concatenation. The example I posted above is syntactically correct and uses simple templating to combine Zustand and the sensor’s value.
I’m still extremely insecure configuring sensors in modern and legacy format… This is extremely confusing while there a many tutorials and snippets in the other format. But I’m still learning.
You’re right, it doesn’t make sense just to merge a string with the number I’m very lazy, therefore I’ve just wrote down an example to test my script Later there will be individual, meaningful strings to show a status.