#REST Calling JSON File => Multiple Sensor entities

1 messages · Page 1 of 1 (latest)

solemn zephyr
#

Hey there. Is anyone familiar with the rest integration?

#

I´m loading a rather big JSON file and wante to create multiple sensor values from it, using different json paths... but it's not really working...

winter jetty
#

post what you tried

solemn zephyr
winter jetty
#

post what the data looks like

solemn zephyr
#

i tried to use the json-paths within the value_templates but that didn't work

#

cant paste the data - it's confidential - but i have validated that the json_paths are correct and working

winter jetty
#

is it xml or json?

solemn zephyr
#

JSON

#

config is loaded but sensors appear as "unknown"

winter jetty
#

use

"{{ value_json.clients | selectattr('name','eq','Client Name') | map(attribute='cost.formatted') | first }}"

without the path

solemn zephyr
#

as the value template?

winter jetty
#

yes

solemn zephyr
#

interesting! give me a sec..

#

there we go! works like a charm!

#

thanks man!

#

enjoy a ☕️ on me! 🙂

winter jetty
#

Thanks 🙂

#

make sure it works during restarts

#

I suspect you'll need a |default in case the map doesn't work

#

after the | first

#

the only way it wouldn't work is if you got an empty response from your endpoint

solemn zephyr
#

just like "{{ value_json.clients |default selectattr('name','eq','Client Name') | map(attribute='cost.formatted') | first }}" ?

#

sorry - not familiar with this kind of mapping

winter jetty
#

no, after | first

#

they are filters

#

you start with value_json.clients

#

it then widdles the list down with | selectattr('name','eq','Client Name')

solemn zephyr
#

oh, i understand now...

winter jetty
#

then you map to the value you want

#

so you have a dict, but then you say I just want the cost.formatted (which is 2 dict's deep)

#

then you say I want the first one