nickrout
(Nick Rout)
June 26, 2023, 12:36am
1
I have a template sensor to convert my car speed from mph to km/h. The template state is
state: {{(state_attr('device_tracker.tesla_location_tracker','speed') * 1.6)}}
However sometimes (like when it is stationery) the attribute returns Unknown
. It is annoying me.
I have read the templating page many times, but I just can’t get it. I would like it to read 0
instead of Unknown
.
Anyone?
dproffer
(David Proffer)
June 26, 2023, 12:46am
2
Would something like this help?
- condition: template
value_template: '{{ ( as_timestamp(now()) - as_timestamp(state_attr(''automation.garage_motion_detected'',
''last_triggered'')) |int(0) ) > 240 }}'
Does this help? Anything that can’t be interpreted as a float value defaults to 0
{{ state_attr('device_tracker.tesla_location_tracker','speed')|float(0) * 1.6 }}
nickrout
(Nick Rout)
June 26, 2023, 1:37am
4
That works, and thank you.
@dproffer thanks for your input too.