petrho
(Peter)
February 3, 2022, 6:06pm
1
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 %}
n1k5y
(Nikola)
February 4, 2022, 1:30pm
2
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
petrho
(Peter)
February 4, 2022, 10:33pm
4
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”
m0wlheld
(Christoph Dahlen)
February 5, 2022, 8:54am
5
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.