Hi!
i have cmd_line sensor, he provide me this string: {"86": ["2017-10-19T21:18:24+03:00", "2017-10-19T21:21:02+03:00", "2017-10-19T21:32:35+03:00"], "86к": ["2017-10-19T21:05:56+03:00"], "265": ["2017-10-19T21:14:33+03:00", "2017-10-19T21:34:12+03:00"]}
keys and count of values is various.
how to parse it?
sensor:
- platform: command_line
command: python3 /home/homeassistant/.homeassistant/maps/GetInfo.py 123345
name: bus
scan_interval: 30
value_template: "{{ value_json }}"
- platform: template
sensors:
any_template:
friendly_name: "my bus"
value_template: "{% for attr in states.sensor.bus.state%}{{ attr }}{% endfor %}"
Thank you to reply,
but data is various, and i don’t know keys.
also i don’t know number of values in list,
i want to print all data one time, how can i do it?
need loop list as For Each
value_template: "{% set value_json=states.sensor.bus.state %}{ %from b in value_json %}{{ b }}{% endfor %}"
And
When i give him:
{“86”: [“2017-10-19T21:18:24+03:00”, “2017-10-19T21:21:02+03:00”, “2017-10-19T21:32:35+03:00”], “86к”: [“2017-10-19T21:05:56+03:00”], “265”: [“2017-10-19T21:14:33+03:00”, “2017-10-19T21:34:12+03:00”]}
He return me the same.
It mean that HA cant parse utf8…
I’m not pretty sure what you actually want to display.
Maybe this is helpful:
{% for value in value_json %} {{value}} contains {{value_json[value]|count}} items - {{value_json[value][0]}}
{% endfor %}
would give you as an output
86к contains 1 items - 2017-10-19T21:05:56+03:00
265 contains 2 items - 2017-10-19T21:14:33+03:00
86 contains 3 items - 2017-10-19T21:18:24+03:00
Is this what you are looking for?
thank you for reply
it is bus number and they arriving time.
i want to see: 86: 21:18, 21:21, 21:32 86к: 21:05 256: 21:14, 21:34
when i’m writing {% for value in value_json %} i see error:
Unknown value_json
{% set value_json=states.sensor.bus.state %}{% for value in value_json %}{{value}}{% for item in value_json[value]%}{% set list1 = value_json[value][loop.index0].split('T') %}{{ list1[1] }}{% endfor %}{{value_json[value][0]}} {% endfor %}
Should give something like:
86к 21:05:56+03:00 2017-10-19T21:05:56+03:00
265 21:14:33+03:00 21:34:12+03:00 2017-10-19T21:14:33+03:00
86 21:18:24+03:00 21:21:02+03:00 21:32:35+03:00 2017-10-19T21:18:24+03:00
return: 2017-10-20 18:04:51 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template: UndefinedError: 'str object' has no attribute '{'
he can’t parse my str to json… dunno why…