Please help to extract data from a json

I’m trying to make a sensor that extracts data from a Json specifically the ““Uso CPU”” but I’ve been trying with templates for a week and there’s no way, I always get the message “UndefinedError: ‘value_json’ is undefined” I’m already desperate

Could anyone help me?

the json is very extensive because it is from openhardware monitor

ID 59

I get the json from a local ip http://10.128.99.7:8085/data.json

{"id": 0, "Text": "Sensor", "Children": [{"id": 1, "Text": "DESPACHO", "Children": [{"id": 2, "Text": "ASRock X570 Phantom Gaming X", "Children": [{"id": 3, "Text": "Nuvoton NCT6796D-R", "Children": [{"id": 4, "Text": "Voltages", "Children": [{"id": 5, "Text": "CPU VCore", "Children": [], "Min": "0,184 V", "Value": "0,536 V", "Max": "0,536 V", "ImageURL": "images/transparent.png"}, {"id": 6, "Text": "Voltage #2", "Children": [], "Min": "1,640 V", "Value": "1,648 V", "Max": "1,664 V", "ImageURL": "images/transparent.png"}, {"id": 7, "Text": "AVCC", "Children": [], "Min": "3,424 V", "Value": "3,440 V", "Max": "3,440 V", "ImageURL": "images/transparent.png"}, {"id": 8, "Text": "3VCC", "Children": [], "Min": "3,232 V", "Value": "3,264 V", "Max": "3,280 V", "ImageURL": "images/transparent.png"}, {"id": 9, "Text": "Voltage #5", "Children": [], "Min": "1,792 V", "Value": "1,800 V", "Max": "1,816 V", "ImageURL": "images/transparent.png"}, {"id": 10, "Text": "Voltage #6", "Children": [], "Min": "1,080 V", "Value": "1,088 V", "Max": "1,096 V", "ImageURL": "images/transparent.png"}, {"id": 11, "Text": "Voltage #7", "Children": [], "Min": "1,192 V", "Value": "1,200 V", "Max": "1,200 V", "ImageURL": "images/transparent.png"}, {"id": 12, "Text": "3VSB", "Children": [], "Min": "3,424 V", "Value": "3,424 V", "Max": "3,440 V", "ImageURL": "images/transparent.png"}, {"id": 13, "Text": "VTT", "Children": [], "Min": "1,608 V", "Value": "1,632 V", "Max": "1,640 V", "ImageURL": "images/transparent.png"}, {"id": 14, "Text": "Voltage #11", "Children": [], "Min": "1,024 V", "Value": "1,024 V", "Max": "1,024 V", "ImageURL": "images/transparent.png"}, {"id": 15, "Text": "Voltage #12", "Children": [], "Min": "0,632 V", "Value": "0,632 V", "Max": "0,632 V", "ImageURL": "images/transparent.png"}, {"id": 16, "Text": "Voltage #13", "Children": [], "Min": "0,936 V", "Value": "0,936 V", "Max": "0,944 V", "ImageURL": "images/transparent.png"}, {"id": 17, "Text": "Voltage #14", "Children": [], "Min": "0,920 V", "Value": "0,920 V", "Max": "0,928 V", "ImageURL": "images/transparent.png"}, {"id": 18, "Text": "Voltage #15", "Children": [], "Min": "0,904 V", "Value": "0,904 V", "Max": "0,912 V", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/voltage.png"}, {"id": 19, "Text": "Temperatures", "Children": [{"id": 20, "Text": "Temperature #1", "Children": [], "Min": "44,0 °C", "Value": "47,0 °C", "Max": "55,0 °C", "ImageURL": "images/transparent.png"}, {"id": 21, "Text": "Temperature #2", "Children": [], "Min": "44,0 °C", "Value": "45,0 °C", "Max": "45,0 °C", "ImageURL": "images/transparent.png"}, {"id": 22, "Text": "Temperature #3", "Children": [], "Min": "15,0 °C", "Value": "15,0 °C", "Max": "16,0 °C", "ImageURL": "images/transparent.png"}, {"id": 23, "Text": "Temperature #5", "Children": [], "Min": "12,0 °C", "Value": "12,0 °C", "Max": "12,0 °C", "ImageURL": "images/transparent.png"}, {"id": 24, "Text": "Temperature #6", "Children": [], "Min": "31,0 °C", "Value": "31,0 °C", "Max": "31,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 25, "Text": "Fans", "Children": [{"id": 26, "Text": "Chasis Fan", "Children": [], "Min": "778 RPM", "Value": "874 RPM", "Max": "1988 RPM", "ImageURL": "images/transparent.png"}, {"id": 27, "Text": "CPU Fan", "Children": [], "Min": "711 RPM", "Value": "717 RPM", "Max": "747 RPM", "ImageURL": "images/transparent.png"}, {"id": 28, "Text": "Bomba CPU", "Children": [], "Min": "1878 RPM", "Value": "1988 RPM", "Max": "2695 RPM", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/fan.png"}, {"id": 29, "Text": "Controls", "Children": [{"id": 30, "Text": "Fan Control #1", "Children": [], "Min": "38,4 %", "Value": "42,0 %", "Max": "95,7 %", "ImageURL": "images/transparent.png"}, {"id": 31, "Text": "Fan Control #2", "Children": [], "Min": "30,2 %", "Value": "30,2 %", "Max": "30,2 %", "ImageURL": "images/transparent.png"}, {"id": 32, "Text": "Fan Control #3", "Children": [], "Min": "58,8 %", "Value": "62,0 %", "Max": "95,3 %", "ImageURL": "images/transparent.png"}, {"id": 33, "Text": "Fan Control #4", "Children": [], "Min": "99,2 %", "Value": "99,2 %", "Max": "99,6 %", "ImageURL": "images/transparent.png"}, {"id": 34, "Text": "Fan Control #5", "Children": [], "Min": "100,0 %", "Value": "100,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 35, "Text": "Fan Control #6", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "0,0 %", "ImageURL": "images/transparent.png"}, {"id": 36, "Text": "Fan Control #7", "Children": [], "Min": "100,0 %", "Value": "100,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/control.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/chip.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/mainboard.png"}, {"id": 37, "Text": "AMD Ryzen 9 3900X", "Children": [{"id": 38, "Text": "Clocks", "Children": [{"id": 39, "Text": "Bus Speed", "Children": [], "Min": "100,0 MHz", "Value": "100,0 MHz", "Max": "100,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 40, "Text": "CPU Core #1", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 41, "Text": "CPU Core #2", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 42, "Text": "CPU Core #3", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 43, "Text": "CPU Core #4", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 44, "Text": "CPU Core #5", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 45, "Text": "CPU Core #6", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 46, "Text": "CPU Core #7", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 47, "Text": "CPU Core #8", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 48, "Text": "CPU Core #9", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 49, "Text": "CPU Core #10", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 50, "Text": "CPU Core #11", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 51, "Text": "no se utiliza", "Children": [], "Min": "4000,0 MHz", "Value": "4000,0 MHz", "Max": "4000,0 MHz", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/clock.png"}, {"id": 52, "Text": "Temperatures", "Children": [{"id": 53, "Text": "Temperatura CPU", "Children": [], "Min": "47,5 °C", "Value": "53,3 °C", "Max": "76,9 °C", "ImageURL": "images/transparent.png"}, {"id": 54, "Text": "CPU CCD Max", "Children": [], "Min": "45,8 °C", "Value": "53,0 °C", "Max": "77,0 °C", "ImageURL": "images/transparent.png"}, {"id": 55, "Text": "CPU CCD Average", "Children": [], "Min": "45,3 °C", "Value": "51,5 °C", "Max": "74,9 °C", "ImageURL": "images/transparent.png"}, {"id": 56, "Text": "CPU CCD #1", "Children": [], "Min": "45,8 °C", "Value": "53,0 °C", "Max": "77,0 °C", "ImageURL": "images/transparent.png"}, {"id": 57, "Text": "CPU CCD #2", "Children": [], "Min": "44,5 °C", "Value": "50,0 °C", "Max": "72,8 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 58, "Text": "Load", "Children": [{"id": 59, "Text": "Uso CPU", "Children": [], "Min": "0,0 %", "Value": "1,4 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 60, "Text": "CPU Core #1", "Children": [], "Min": "0,0 %", "Value": "5,5 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 61, "Text": "CPU Core #2", "Children": [], "Min": "0,0 %", "Value": "3,1 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 62, "Text": "CPU Core #3", "Children": [], "Min": "0,0 %", "Value": "4,7 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 63, "Text": "CPU Core #4", "Children": [], "Min": "0,0 %", "Value": "3,1 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 64, "Text": "CPU Core #5", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 65, "Text": "CPU Core #6", "Children": [], "Min": "0,0 %", "Value": "0,8 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 66, "Text": "CPU Core #7", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 67, "Text": "CPU Core #8", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 68, "Text": "CPU Core #9", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 69, "Text": "CPU Core #10", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 70, "Text": "CPU Core #11", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}, {"id": 71, "Text": "CPU Core #12", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "100,0 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}, {"id": 72, "Text": "Powers", "Children": [{"id": 73, "Text": "CPU Package", "Children": [], "Min": "12,2 W", "Value": "21,4 W", "Max": "72,1 W", "ImageURL": "images/transparent.png"}, {"id": 74, "Text": "CPU Cores", "Children": [], "Min": "0,7 W", "Value": "6,7 W", "Max": "65,0 W", "ImageURL": "images/transparent.png"}, {"id": 75, "Text": "CPU Core #1", "Children": [], "Min": "0,1 W", "Value": "1,1 W", "Max": "5,8 W", "ImageURL": "images/transparent.png"}, {"id": 76, "Text": "CPU Core #2", "Children": [], "Min": "0,1 W", "Value": "1,2 W", "Max": "5,9 W", "ImageURL": "images/transparent.png"}, {"id": 77, "Text": "CPU Core #3", "Children": [], "Min": "0,1 W", "Value": "1,2 W", "Max": "5,8 W", "ImageURL": "images/transparent.png"}, {"id": 78, "Text": "CPU Core #4", "Children": [], "Min": "0,0 W", "Value": "0,9 W", "Max": "5,9 W", "ImageURL": "images/transparent.png"}, {"id": 79, "Text": "CPU Core #5", "Children": [], "Min": "0,0 W", "Value": "0,6 W", "Max": "5,8 W", "ImageURL": "images/transparent.png"}, {"id": 80, "Text": "CPU Core #6", "Children": [], "Min": "0,0 W", "Value": "0,8 W", "Max": "5,9 W", "ImageURL": "images/transparent.png"}, {"id": 81, "Text": "CPU Core #7", "Children": [], "Min": "0,0 W", "Value": "0,2 W", "Max": "5,1 W", "ImageURL": "images/transparent.png"}, {"id": 82, "Text": "CPU Core #8", "Children": [], "Min": "0,0 W", "Value": "0,2 W", "Max": "5,0 W", "ImageURL": "images/transparent.png"}, {"id": 83, "Text": "CPU Core #9", "Children": [], "Min": "0,0 W", "Value": "0,2 W", "Max": "5,0 W", "ImageURL": "images/transparent.png"}, {"id": 84, "Text": "CPU Core #10", "Children": [], "Min": "0,0 W", "Value": "0,1 W", "Max": "5,0 W", "ImageURL": "images/transparent.png"}, {"id": 85, "Text": "CPU Core #11", "Children": [], "Min": "0,0 W", "Value": "0,1 W", "Max": "5,0 W", "ImageURL": "images/transparent.png"}, {"id": 86, "Text": "CPU Core #12", "Children": [], "Min": "0,0 W", "Value": "0,1 W", "Max": "5,0 W", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/power.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/cpu.png"}, {"id": 87, "Text": "NVIDIA NVIDIA GeForce GTX 1080", "Children": [{"id": 88, "Text": "Clocks", "Children": [{"id": 89, "Text": "GPU Core", "Children": [], "Min": "139,0 MHz", "Value": "1607,0 MHz", "Max": "1607,0 MHz", "ImageURL": "images/transparent.png"}, {"id": 90, "Text": "GPU Memory", "Children": [], "Min": "405,0 MHz", "Value": "5005,8 MHz", "Max": "5005,8 MHz", "ImageURL": "images/transparent.png"}, {"id": 91, "Text": "GPU Shader", "Children": [], "Min": "278,0 MHz", "Value": "3214,0 MHz", "Max": "3214,0 MHz", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/clock.png"}, {"id": 92, "Text": "Temperatures", "Children": [{"id": 93, "Text": "Temperatura GPU", "Children": [], "Min": "34,0 °C", "Value": "40,0 °C", "Max": "46,0 °C", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/temperature.png"}, {"id": 94, "Text": "Load", "Children": [{"id": 95, "Text": "Uso GPU", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "85,0 %", "ImageURL": "images/transparent.png"}, {"id": 96, "Text": "GPU Frame Buffer", "Children": [], "Min": "0,0 %", "Value": "1,0 %", "Max": "39,0 %", "ImageURL": "images/transparent.png"}, {"id": 97, "Text": "GPU Video Engine", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "2,0 %", "ImageURL": "images/transparent.png"}, {"id": 98, "Text": "GPU Bus Interface", "Children": [], "Min": "0,0 %", "Value": "0,0 %", "Max": "38,0 %", "ImageURL": "images/transparent.png"}, {"id": 99, "Text": "GPU Memory", "Children": [], "Min": "7,2 %", "Value": "12,1 %", "Max": "15,3 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/load.png"}, {"id": 100, "Text": "Fans", "Children": [{"id": 101, "Text": "Fan GPU", "Children": [], "Min": "1279 RPM", "Value": "1290 RPM", "Max": "1306 RPM", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/fan.png"}, {"id": 102, "Text": "Controls", "Children": [{"id": 103, "Text": "GPU Fan", "Children": [], "Min": "24,0 %", "Value": "24,0 %", "Max": "29,0 %", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/control.png"}, {"id": 104, "Text": "Powers", "Children": [{"id": 105, "Text": "GPU Power", "Children": [], "Min": "8,5 W", "Value": "42,7 W", "Max": "45,3 W", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/power.png"}, {"id": 106, "Text": "Data", "Children": [{"id": 107, "Text": "GPU Memory Free", "Children": [], "Min": "6940,6 MB", "Value": "7198,4 MB", "Max": "7605,3 MB", "ImageURL": "images/transparent.png"}, {"id": 108, "Text": "GPU Memory Used", "Children": [], "Min": "586,7 MB", "Value": "993,6 MB", "Max": "1251,4 MB", "ImageURL": "images/transparent.png"}, {"id": 109, "Text": "GPU Memory Total", "Children": [], "Min": "8192,0 MB", "Value": "8192,0 MB", "Max": "8192,0 MB", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/power.png"}, {"id": 110, "Text": "Throughput", "Children": [{"id": 111, "Text": "GPU PCIE Rx", "Children": [], "Min": "0,0 KB/s", "Value": "0,0 KB/s", "Max": "1216,8 MB/s", "ImageURL": "images/transparent.png"}, {"id": 112, "Text": "GPU PCIE Tx", "Children": [], "Min": "0,0 KB/s", "Value": "0,0 KB/s", "Max": "607,4 MB/s", "ImageURL": "images/transparent.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/power.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/nvidia.png"}], "Min": "", "Value": "", "Max": "", "ImageURL": "images_icon/computer.png"}], "Min": "Min", "Value": "Value", "Max": "Max", "ImageURL": ""} 

Please post your config.

Do you mean configuration?

rest:

among a million more variants

en https://jsonpathfinder.com/ this route comes out

x.Children[0].Children[1].Children[2].Children[0].Value

Use JsonPathFinder to help you get the correct path to the desired key and value.

For example, to get Uso CPU

the path is x.Children[0].Children[1].Children[2].Children[0].Text which for Home Assistant (in a REST or Template Sensor) would be:

value_template: '{{ value_json.Children[0].Children[1].Children[2].Children[0].Text }}'

If you want the associated Value key (which contains 1.4%) then use this:

value_template: '{{ value_json.Children[0].Children[1].Children[2].Children[0].Value }}'

A potential problem here is that the information is contained in lists and the desired item (Uso CPU) might not always be in exact same location the next time fresh data is received.

I had already tried that before, just what you put, but it keeps getting “UndefinedError: ‘value_json’ is undefined”

rest:

If I just try this:

rest:

still getting the same error

What am I doing wrong?

by the browser and home assistan access the local IP fine

The structure of the example you posted is invalid; it doesn’t conform to the example in the documentation.


Here are two ways to define a REST sensor.

Like this:

rest:
  - resource: http://10.128.99.7:8085/data.json
    sensor:
      - name: example 1
        value_template: '{{ value_json.id }}'

Or using the RESTful integration

sensor:
  - platform: rest
    resource: http://10.128.99.7:8085/data.json
    name: example 2
    value_template: '{{ value_json.id }}'

This should work
attention(when I remember right), only 255 characters allowed in the output

  - platform: command_line
    name: LoremIpsumestdolor
    command: "curl -JsL -m 5 --retry 5 -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36' 'https://pastebin.com/raw/HwCzut36' | jq .Children[0].Children[1].Children[2].Children[0].Value"

this is with the same technique one of my sensors
(The backslashes ar’nt valid yaml but for readability, I also store the command in a secret that the quotation marks wont throw me off )

  - platform: command_line
    name: wl_eckpergasse
    command: curl -JsL -m 5 --retry 5 -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36' \
             'http://www.wienerlinien.at/ogd_realtime/monitor?rbl=131' \
             | jq '.data.monitors[] | { name: .lines[].name ,stop: .locationStop.properties.title, towards: .lines[].towards ,data: .lines[].departures.departure[].departureTime.countdown, trafficjam: .lines[].trafficjam }'\
             | jq -cs '{name: .[0].name, stop: .[0].stop, towards: .[0].towards, next: .[0].data, seccond: .[1].data, third: .[2].data, fourth: .[3].data, trafficjam_0: .[0].trafficjam, trafficjam_1: .[1].trafficjam }'
    value_template: '{{ value_json.trafficjam_0 | default("")  | replace(false, "") | replace(true, "STAU")}}{{ value_json.trafficjam_1 | default("")  | replace(false, "")| replace(true, "STAU")}}{{ value_json.next | default("")  | replace(null, "") }}, {{ value_json.seccond | default("")  | replace(null, "")}}, {{ value_json.third | replace(null, "") }}'
    json_attributes: 
      - next
      - seccond
      - third
      - fourth
      - trafficjam_0
      - trafficjam_1
      - name
      - stop
      - towards

Docu

in all 4 examples above it keeps getting “UndefinedError: ‘value_json’ is undefined”

This on not how the template editor works.
You have to set these up for example in configuration.yaml under sensors:

THANKS A LOT!!!

what a fool I am, a week of work and in the end it was silly that I tried the sensor in the template editor.

she thought it would work there

it works now

what I said, thank you all, it works

Sin título 2

the problem now is that when passing the value to int or float it returns “0” I don’t know why

I have tried:

value_template: ‘{{ value_json.Children[0].Children[1].Children[2].Children[0].Value | float}}’
value_template: ‘{{ value_json.Children[0].Children[1].Children[2].Children[0].Value | int}}’
value_template: ‘{{ value_json.Children[0].Children[1].Children[2].Children[0].Value | replace (’ %’, ‘’) | int}}’
value_template: ‘{{ value_json.Children[0].Children[1].Children[2].Children[0].Value | replace (’ %’, ‘’) | float}}’

returns “0”

I just have one question, if it’s not too much trouble…

123 taras said…

“A potential problem here is that the information is contained in lists and the desired item (CPU usage) might not always be in exact same location the next time fresh data is received.”

Is there any way to make a template that, for example, takes the data from “CPU usage” instead of list?

Thank you very much and sorry if I’m annoying

The purpose of the Template Editor is to test templates. You were trying to use it to test a sensor’s configuration based on the RESTful integration.

Because the value uses a comma as a decimal separator. The float and int filters expect a period, not a comma (and so they fail to convert the value and report 0). Your template removes the % symbol and will also need to convert , to . in order for float to recognize it as a numeric string.

You would have to give up using the jsonpath method and perform a text-search using a regex pattern (it’s more complex than using jsonpath).

to be honest, it would be a nice feature. probably terrible to implement

I said, thank you both very much