Problem with Template, or maybe a tutorial for dummies is needed

Hi there,

Im really frustrated on the following topic. I have got a Kostal Pico and with the following URL:

http://xxx.xxx.xxx.xxx/api/dxs.json?dxsEntries=67109120&dxsEntries=83886848

I get the following JSON reply:

{
    "dxsEntries": [
        {
            "dxsId": 67109120,
            "value": 987.462402
        },
        {
            "dxsId": 83886848,
            "value": 0.000000
        }
    ],
    "session": {
        "sessionId": 0,
        "roleId": 0
    },
    "status": {
        "code": 0
    }
}

A single value I get with the following:

  - platform: rest
    resource: http://192.168.1.13/api/dxs.json?dxsEntries=67109120
    name: "Netz Ausgangsleistung"
    value_template: "{{ value_json.dxsEntries[0].value | float | round(0) }}"
    unit_of_measurement: "W"

This works. But I want all X value, which I can append in the resource url at once

I tried the following to get the values out (there is no login needed so I removed the username and password):

rest:
  - authentication: basic
    username: ""
    password: ""
    resource: http://192.168.1.13/api/dxs.json?dxsEntries=67109120&dxsEntries=83886848&dxsEntries=83886336&dxsEntries=251658754&dxsEntries=67109120
    scan_interval: 10
    sensor:
      - name: kostal_netz_ausgangsleistung
        json_attributes_path: "$.dxsEntries[0].value"
        device_class: power
        unit_of_measurement: "W"
      - name: kostal_akt_verbrauch_aus_pv
        json_attributes_path: "$.dxsEntries[1].value"
        device_class: power
        unit_of_measurement: "W"

Alternative which also didn’t work:

sensor:
  - platform: rest
    name: kostal_pico
    resource: http://xxx.xxx.xxx.xxx/api/dxs.json?dxsEntries=67109120&dxsEntries=83886848
    json_attributes_path: "$"
  - platform: template
    sensors:
      sensor1whatever:
        value_template: "{{ state_attr('sensor.kostal_pico', 'dxsEntries[0].value')}}"
        device_class: power
        unit_of_measurement: "W"

Try:

  - platform: template
    sensors:
      sensor1whatever:
        value_template: "{{ state_attr('sensor.kostal_pico','dxsEntries')[0]['value'] }}"
        device_class: power
        unit_of_measurement: "W"

Json attributes path is for attributes. Use value_template to extract the states

Thanks for the answer, but didn’t work

Hi petro what do you mean?

That worked.

that didn’t.

Use value_template instead to extract the values.

at the moment I use this code:

- platform: rest
    name: kostal_pico
    resource: http://xxx.xxx.xxx.xxx/api/dxs.json?dxsEntries=67109120&dxsEntries=83886848
  - platform: template
    sensors:
      kostal_netz_ausgangsleistung:
        value_template: "{{ state_attr('sensor.kostal_pico','dxsEntries')[0]['value'] | float | round(0) }}"
        device_class: power
        unit_of_measurement: "W"
      kostal_akt_verbrauch_aus_pv:
        value_template: "{{ state_attr('sensor.kostal_pico','dxsEntries')[1]['value'] | float | round(0) }}"
        device_class: power
        unit_of_measurement: "W"

and get this states:

your rest sensor isn’t pulling any information.

yes the values are 0.000 but that’s ok because the sun is not shining. The 0 should be in the entities above

is English your native language?

nope why? so bad?

No, you just aren’t understanding me.

from Germany

maybe thats true

I thought the information is the json string

rest:
  - resource: http://192.168.1.13/api/dxs.json?dxsEntries=67109120&dxsEntries=83886848&dxsEntries=83886336&dxsEntries=251658754&dxsEntries=67109120
    scan_interval: 10
    sensor:
      - name: kostal_netz_ausgangsleistung
        value_template: "{{ value_json.dxsEntries[0].value | round(0, default=0) }}"
        device_class: power
        unit_of_measurement: "W"
      - name: kostal_akt_verbrauch_aus_pv
        value_template: "{{ value_json.dxsEntries[1].value | round(0, default=0) }}"
        device_class: power
        unit_of_measurement: "W"

thanks petro, thats it.

maybe I try a suggestion for the documentation, for noobs like me