trying the distance() function I ran into unexpected behavior.
according to https://www.home-assistant.io/docs/configuration/templating/#distance-examples
we can use states and do: distance(states.device_tracker.name1, states.device_tracker.name2)
we can also use: distance('device_tracker.name1','device_tracker.name2')
works fine.
using a zone, we can do: distance(states.device_tracker.name1, states.zone.name2)
but this however:
distance('device_tracker.name1','zone.name1')
returns none…?
is the a bug? or what am I doing wrong here.
thx
petro
(Petro)
October 5, 2018, 4:16pm
2
Just looking at the code, neither of these methods will work:
{{ distance('device_tracker.name1','device_tracker.name2') }}
{{ distance('device_tracker.name1','zone.name1') }}
Only methods that should work are ones where you have a state object.
{{ distance(states.device_tracker.name1, states.zone.name2) }}
{{ distance(states.device_tracker.name1, states.device_tracker.name2) }}
Edit: one of 2 changes probably need to happen:
Change documentation to only show state objects
or
PR needs to be made with ability to search for the state object by entity_id.
yes, you’re right, trying some further, not even the second example I gave works, dont know how that did the first time I tested… {{distance('device_tracker.name1','device_tracker.name2')}}
need to happen 1 is probably easiest, nth2 would be preferable in my view, and make the code more consistent .
cant stand the fact I had it work earlier… will test some further how that could be.
@petro
seems dev’s @mnigbur are working on it:
home-assistant:dev
← mnigbur:distance-entity-fix
opened 06:11PM - 09 Oct 18 UTC
which is really nice, and makes these templates so much more in line with regular behavior.
Hope this will make it soon!
petro
(Petro)
October 9, 2018, 9:58pm
5
I’m not sure why they never had it to begin with. Maybe it was there and they removed it when a bug was found