Insert spaces in Strings in front of Capital letters (Template)

Hi,

from my heating system I get via MQTT text Messages like “FourThreeWayValveIdlePosition” or “LegionellaProtectionTemperatureReached”. How can I convert them into seperate words by inserting a space in front of each capital letter with a template?

Best Regards
Hendrik

With templates you can do this (is also posisble in a 1-liner but this may be more transparent)

{% set s = "FourThreeWayValveIdlePosition" %}
{% set parts = s | regex_findall('[A-Z][a-z]*') %}
{{ parts|join(' ') }}
1 Like