I have an online service that publishes multiple sensors to the same MQTT topic, but with a unique identifier in the JSON payload.
to accomodate for this I have a value template that checks if the identifier matches a specific value and returns the data value if true:
value_template: >-
{%if value_json.mmsi == 219025528 and
((value_json.type == 1 ) or
(value_json.type == 2 ) or
(value_json.type == 3 )) %}
{{ value_json.status_text}}
{%endif%}
This works very well for number based sensors, but for sensor relying on text strings, like:
device_class: "timestamp"
device_class: "enum"
The status sensor value is either blanked or unknown respectively when a JSON payload is received that does not pass the initial test.
So my question is how can make a value template that only updates the value for string based sensors, if the initial check passes?