Hi all.
I had a possibly rare need to try and access data from a Shelly Uni from outside my LAN, specifically to obtain 12v battery voltage from a vehicle. The car has a pocket wifi device.
I did have some trouble finding information in one place as to how to accomplish this but in the end I was able to make it work by cobbling together scraps from a number of sources. I’ll try and document it here in case anyone else looks to do the same.
Firstly you need to have a shelly account, and the device that you want to reach has to be connected to the cloud service
You need to enable the cloud service on the device in question within the account (or directly on the device via the IP address or Shelly App
Then you need to obtain the API (AUTH) key and device ID and server URL, which are also obtainable within the account / app (or directly on the device via the IP address or Shelly App. The device ID is available on the device info page on each device, and the other 2 items are available on the settings page under ‘User Settings’.
Once you have this information, you can test your URL to see if you get a valid response, the format of the URL is as follows:-
https://(YOUR_ALLOCATED_SERVER)/device/status?id=(YOUR_DEVICE _ID)&auth_key=(YOUR_AUTH_KEY)
The beginning of the URL may look like this
https://shelly-58-eu.shelly.cloud/device/status?id=
Something like this should be returned
{ "isok": true, "data": { "online": true, "device_status": { "fs_free": 146333, "uptime": 20701, "ext_humidity": [], "mac": "4417931B8E61", "time": "17:04", "ram_free": 37376, "cfg_changed_cnt": 9, "inputs": [ { "input": 0, "event": "", "event_cnt": 0 }, { "input": 0, "event": "", "event_cnt": 0 } ], "fs_size": 233681, "mqtt": { "connected": false }, "ext_sensors": [], "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" } ], "has_update": false, "adcs": [ { "voltage": 12.83 } ], "ext_temperature": [], "ram_total": 50776, "actions_stats": { "skipped": 0 }, "_updated": "2023-08-16 07:04:05", "cloud": { "enabled": true, "connected": true }, "update": { "status": "idle", "has_update": false, "new_version": "20230503-102354/v1.13.0-g9aed950", "old_version": "20230503-102354/v1.13.0-g9aed950", "beta_version": "20230809-185136/v0.14.0-rc1-ge28dcb8" }, "wifi_sta": { "connected": true, "ssid": "ZR", "ip": "192.168.43.42", "rssi": -67 }, "serial": 12399, "unixtime": 1692163576 } } }
Now Home Assistant has some data available it can retrieve.
The next step is to add some lines of code you your configuration.yaml / sensors.yaml / secrets.yaml (depending on how you like to do things). for simplicity I’ll just condense mine into a single block suitable for configuration.yaml without using secrets.yaml
Modify your code to suit what you are doing
- platform: rest
name: zoe_12v_battery_rest2
unit_of_measurement: "v"
resource: https://shelly-58-eu.shelly.cloud/device/status
method: POST
payload: auth_key=(YOUR_AUTH_KEY)&id=(YOUR_DEVICE ID)
scan_interval: 10
headers:
User-Agent: Home Assistant
Content-Type: application/x-www-form-urlencoded
value_template: "{{ value_json.data.device_status.adcs[0].voltage }}"
The biggest stumbling block for me was finding the json path format and the need for headers (user-agent and Content-Type).
If you look to find other sensor values, then consider using this resource to get the json path you need
( https://jsonpathfinder.com/ ).