Shelly cloud api sensor

Like this:

Would possibly also work to use a RestFul command but that will end up as an service that you then need to handle:

Thanks for this post! It really helped a lot!
Thanks to everyone else who contributed as well.

I can now control a shelly device that is NOT on the same network as the Home Assitant instance, and receive status updates from the shelly.

Great use cases are:

  • Garages or gates that are out of range (Though some internet connections is still required.)
  • Garages or gates you have permission to access, where there is internet but no Home Assistant. (Offices, family member homes)
  • Basic Monitoring of remote properties

NB: Always beware of the security risks of putting access control onto a cloud system. If you don’t understand them, don’t do it.

1 Like

Can anyone give me some help?
I’m trying to get the voltage from a Plus Uni

rest:
  - resource: https://shelly-77-eu.shelly.cloud/device/status
    method: POST
    payload: 'auth_key=123456789abcdefg&id=AAAAAAAAAAA'
    headers:
      User-Agent: Home Assistant
      Content-Type: application/x-www-form-urlencoded
    scan_interval: 5
    sensor:
      - name: "Caddy Battery (Cloud API) - Voltage"
        value_template: '{{ value_json.data.device_status.voltmeter.100.voltage }}'
        device_class: voltage
        unit_of_measurement: 'V'

Im sure my value_template is wrong

With recent HA updates this is broken now… not sure how to resolve.

Logger: homeassistant.helpers.template
Source: helpers/template.py:2652
First occurred: 09:41:21 (21 occurrences)
Last logged: 09:51:21

Template variable error: dict object has no element 0 when rendering '{{ value_json.data.device_status.ext_temperature[0].tC }}'

I used to be able to get reading with this, but it is not working anymore…

  - platform: rest
    name: "Solar Battery"
    device_class: voltage
    unique_id: solar_battery_id
    resource: "https://shelly-31-eu.shelly.cloud/device/status?id=12345678&auth_key=12345678"
    method: POST
    value_template: "{{ value_json.data.device_status.adcs[0].voltage }}"
    unit_of_measurement: "V"

actualy it works, but it is not updating.
Temperature is not working…

{{ value_json.data.device_status.ext_temperature[0].tC }}

Looks like shelly output is different now… Voltage works now, i found that shelly cloud server changed, now updated yaml. Temperature is still not working.

{
    "isok": true,
    "data": {
        "online": false,
        "device_status": {
            "mqtt": {
                "connected": false
            },
            "wifi_sta": {
                "connected": true,
                "ssid": "GEO",
                "ip": "192.168.55.51",
                "rssi": -23
            },
            "actions_stats": {
                "skipped": 0
            },
            "time": "16:22",
            "ext_sensors": {
                "temperature_unit": "C"
            },
            "getinfo": {
                "fw_info": {
                    "device": "shellyuni-12345678",
                    "fw": "20230913-114521/v1.14.0-gcb84623"
                }
            },
            "update": {
                "status": "idle",
                "has_update": false,
                "new_version": "20230913-114521/v1.14.0-gcb84623",
                "old_version": "20230913-114521/v1.14.0-gcb84623",
                "beta_version": "20231107-165239/v1.14.1-rc1-g0617c15"
            },
            "uptime": 495321,
            "unixtime": 1717082012,
            "ram_total": 50776,
            "fs_size": 233681,
            "ext_temperature": {
                "0": {
                    "hwID": "12345678",
                    "tC": 15.31,
                    "tF": 59.56
                }
            },
            "ext_humidity": {},
            "inputs": [
                {
                    "input": 0,
                    "event": "",
                    "event_cnt": 0
                },
                {
                    "input": 0,
                    "event": "",
                    "event_cnt": 0
                }
            ],
            "serial": 49980,
            "has_update": false,
            "mac": "12345678",
            "cloud": {
                "enabled": true,
                "connected": true
            },
            "ram_free": 39088,
            "relays": [
                {
                    "ison": false,
                    "has_timer": false,
                    "timer_started": 0,
                    "timer_duration": 0,
                    "timer_remaining": 0,
                    "source": "input"
                },
                {
                    "ison": false,
                    "has_timer": false,
                    "timer_started": 0,
                    "timer_duration": 0,
                    "timer_remaining": 0,
                    "source": "input"
                }
            ],
            "adcs": [
                {
                    "voltage": 14.29
                }
            ],
            "fs_free": 147086,
            "_updated": "2024-05-30 15:22:01",
            "cfg_changed_cnt": 0
        }
    }
}

so now need to get reading from:

            "ext_temperature": {
                "0": {
                    "hwID": "12345678",
                    "tC": 22.12,
                    "tF": 71.83
                }
            },