Template is not working

Why does I get different result?

#EV Charger

  • platform: template
    sensors:
    charge_remaining:
    friendly_name: ”Remaining charge time"
    value_template: >-
    {% if is_state(‘sensor.330e_xdrive_charging_end_time’, ‘unknown’) %}
    Not connected
    {% else %}
    {{ states(‘sensor.330e_xdrive_charging_end_time’) }}
    {% endif %}

Check what is device_class: in sensor from which you are getting info as based on that it renders info in different ways


        test_timestamp:
            friendly_name: "Remaining charge time"
            device_class : timestamp
            value_template: >
                {% if is_state('sensor.last_boot', 'unknown') %}
                    Not connected
                {% else %}
                    {{ states('sensor.last_boot') }}
                {% endif %}
        

device_class : timestamp in first and no class is second one
image

Thanks - my bad!

hmm. It works to change the time format but there is still problems with the value template . I still get “Unknown” instead of “Not connected”

That‘s because a timestamp cannot have a value of „Not Connected“. You need to remove that device class (so the state becomes a string value) and do the formatting inside the template.