Parse JSON from state

Hi everyone,

I’m once again struggling with some (basic) configuration.

I have set up some sensors on my remote Arduino which sends TCP over Ethernet. I receive the sensor data with:

  - platform: tcp
    host: 192.168.1.6
    port: 1000
    name: Multiple Sensors
    payload: "\n"

And I can retrieve the whole string with states.sensor.multiple_sensors.state, which returns me:

{"S_54":316,"S_55":331,"S_56":362,"S_57":356,"S_58":354,"S_59":376,"S_60":349,"S_61":332,"S_62":305,"S_63":343,"S_64":350,"S_65":356,"S_66":353,"S_67":348,"S_68":340}

That’s all nice and great, but I want to access (let’s say) S_56. I thought that with states.sensor.multiple_sensors.attributes.S_56 I could. Nope. Returns nothing.

Upon further inspection I saw that states.sensor.multiple_sensors.attributes only has friendly_name and nothing more.

Also tried states.sensor.multiple_sensors.state.S_56. Nope.
And states.sensor.multiple_sensors.state["S_56"]. Nope.

I tried to read the sensor with (in hope it would parse to JSON) :

  - platform: tcp
    host: 192.168.1.6
    port: 1000
    name: Multiple Sensors
    payload: "\n"
    value_template: "{{ value_json }}"

which resulted in a “unknown” sensor value. I also tried value_json.S_56 directly. Nope. Gives unknown.

How can I read a value from this JSON? Until now I tried almost everything, I also googled pages and more pages.

My goal is to read every “S_” sensor and put those into template sensors. That way I only need to call the TCP sensor once, which saves bandwith and possible trouble.

Thanks in advance.

I believe

 value_template: '{{value.json.S_54}}'

etc

Thanks for your answer, but value.json won’t work. The valid way to parse it into JSON is value_json, with an underscore.

So does

value_template: '{{value_json.S_54}}'

work?

Unfortunately no…

This page indicates you might need:
value_template: '{{ value_json.S_54.value }}'