I think im going crazy so i come here looking for sanity.
I have an entity that populates an attribute ‘Origin’ with an array of longitude and latitiude.
It looks like this
origin: 59.3,20.3
In the developer section i then wrote
{{ states.sensor.home_to_dest.attributes.origin }}
[
59.3,
20.3
]
so i know its an array, i wrote
{{ states.sensor.home_to_dest.attributes.origin[0] }}
which, in my mind, should return 59.3 but it just returns 5
if i change the 0 to a 1 then it returns 9, its just returning the number based on position.
So im at a loss really as to how to access index of an array.
As the docs say, try to avoid using the states object itself:
Avoid using states.sensor.temperature.state, instead use states('sensor.temperature'). It is strongly advised to use the states(), is_state(), state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup). source
JSONDecodeError: Extra data: line 1 column 10 (char 9)
i see the issue.
The waze entity is not actually creating an array, when i list the attributes it doesnt encase it as [ , ]
It shows it as a string ‘origin’: ‘59.3,20.3’
other entities list such elements as ‘Location’: [None, None] for example
Unfortunately the template editor interprets results. So a string that looks like a list will be interpreted as a list. Actual templates don’t do this, so it remains a string.
many thanks for your input but stating things are obvious is not helpful.
A string of xxx,xxx can be shown the same as an array.
Ive created many entities that contain location of [ xxx,xxx ] which is an array and is accessed as an array ie. a[0] a[1] but this is shown as xxx,xxx
as you can see here if i print out the entity attributes i see that Location is an array
{‘Administrative Area’: ‘Akershus fylke’, ‘Areas Of Interest’: ‘N/A’, ‘Country’: ‘Norge’, ‘Inland Water’: ‘N/A’, ‘ISO Country Code’: ‘O’, ‘Locality’: ‘O’, ‘Location’: [39.38125, 20.18762205], ‘Name’: ‘place’, ‘Ocean’: ‘N/A’, ‘Postal Code’: ‘2414’, ‘Sub Administrative Area’: ‘N/A’, ‘Sub Locality’: ‘N/A’, ‘Sub Thoroughfare’: ‘5’, ‘Thoroughfare’: ‘len’, ‘Time Zone’: ‘Europe/Oslo’, ‘Zones’: [], ‘icon’: ‘mdi:map’, ‘friendly_name’: ‘Maria IPhone Geocoded Location’}
but is listed in the state list as Location: 39.38125, 20.18762205
just the same as waze in visuals
for anyone wanting to split it and know how i decided to do it…
{{ state_attr(‘sensor.home_to_dest’,‘origin’).split(’,’)[0] }}
{{ state_attr(‘sensor.home_to_dest’,‘origin’).split(’,’)[1] }}
I was then able to feed this into a Rest query to openweather to have dynamic weather for calendar destination so that home people could be notified of what to wear.
Notice that the ' ' encloses the full string, where as yours is enclosed in [ ] and is float values.
Not the same.
If you can then the format I posted is better since it only does one split and keeps both halves, yours uses twice the resources and throw away half of the result each time.
If you did not find this obvious then it’s obvious you do not
oh my … yes i clearly stated that this is seen in the template and IS the example of an array confirmation.
but when you query the state of the entity (in developer / states), both a string and array are shown the same.