Rest API Json string for reading data from the shelly cloud (Shelly plus 1PM & Shelly plug S)

Hello there,
i´m a newbie here and have a question:

I tried to get the data from a shelly device, who is in an other network. So i have to get the data from the shelly cloud, using the rest API.
For the shelly plug s it works, but not for the shelly plus 1PM.
I think there is a problem with the json string.

This is my code in the configuration.yaml who work for the shelly plug s:

> rest:
>   - resource: https://shelly-27-eu.shelly.cloud/device/status?
>     method: POST
>     payload: 'auth_key=XXX&id=XXX'
>     headers:
>       User-Agent: Home Assistant
>       Content-Type: application/x-www-form-urlencoded
>     scan_interval: 5
>     sensor:
>       - name: "shelly_home"
>         **value_template: "{{ value_json.data.device_status.meters[0].power | round(1) }}"**
>         state_class: measurement
>         unit_of_measurement: W
>         device_class: power

I got the information for the value_json from the shelly cloud:

{“isok”:true,“data”:{“online”:true,“device_status”:{“fs_free”:166162,“meters”:[{“power”:205.77,“overpower”:0,“is_valid”:true,“timestamp”:1684582484,“counters”:[239.498,269.015,269.824],“total”:39224}],“actions_stats”:{“skipped”:0},“mqtt”:{“connected”:false},“cloud”:{“enabled”:true,“connected”:true},“fs_size”:233681,“relays”:…

Now i have to replace the shelly plug s with a shelly plus 1PM.

I tried this, but there is a problem with the json value:

>   - resource: https://shelly-27-eu.shelly.cloud/device/status?
>     method: POST
>     payload: 'auth_key=XXX&id=XXX'
>     headers:
>       User-Agent: Home Assistant
>       Content-Type: application/x-www-form-urlencoded
>     scan_interval: 5
>     sensor:
>       - name: "shelly_plus_home"
>         **value_template: "{{ value_json.data.device_status.switch['0']['apower'] | round(1) }}"**
>         state_class: measurement
>         unit_of_measurement: W
>         device_class: power

In the cloud, the value “apower” is here:

{“isok”:true,“data”:{“online”:true,“device_status”:{“code”:“SNSW-001P16EU”,“mqtt”:{“connected”:false},“cloud”:{“connected”:true},“ble”:[],“serial”:1684572654.98,“id”:485519996434,“input:0”:{“id”:0,“state”:true},"_updated":“2023-05-20 08:50:54”,“ws”:{“connected”:false},“switch:0”:{“id”:0,“current”:1.259,“source”:“init”,“output”:true,“apower”:300.4,“voltage”:234.3,“aenergy”:{“by_minute”:[5175.457,4717.925,4156.109],“minute_ts”:1684572599,“total”:545.776}…

I tried:
value_template: “{{ value_json.data.device_status.switch:0[0].apower }}”
value_template: “{{ value_json.data.device_status.switch[0].apower }}”
value_template: “{{ value_json.data.device_status.switch.apower }}”
value_template: “{{ value_json.data.device_status.switch[‘0’][‘apower’] }}”
and so on but nothing works. I get the information, that the value is not numeric or bad formated.

I think the problem is, that the value has a doublepoint in the data (switch:0).
In the data of the shelly plus s there is no doublepoint → works.

Anybody an idea how to correctly set the value_json?

Thanks a lot.

No one out there to help me?

value_json['data']['device_status']['switch:0']['apower']

“Bracket” notation is always safer / better than dot notation.

Hi Troon, that works for me! Thanks a lot!