Controlling Shelly Cloud Devices in Home Assistant

I’ve created a YAML blueprint that allows you to control Shelly devices via the Shelly Cloud API in Home Assistant.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.


Configuration (explained in blueprint)

:wrench: Prerequisites

  • Shelly Cloud Account: Make sure your Shelly device is connected to the Shelly Cloud.
  • Home Assistant: You need a working Home Assistant installation.
  • Helpers Setup:
    • URL: Create a text helper for your Shelly Cloud server URL (e.g., shelly-42-eu.shelly.cloud).
    • API Key: Create another text helper for your API key.

:gear: Setup Steps

  1. Add the Blueprint: Download the YAML code from my Gist and add it to your Home Assistant configuration.
  2. Create Helpers: Go to Settings > Devices & Services > Helpers and create the text helpers mentioned above.
  3. Add REST Command: Add the following REST command to your configuration.yaml:
rest_command:
  shelly_cloud_control:
    url: "https://{{ url }}/v2/devices/api/set/{{ device_type }}"
    method: POST
    payload: >
      {
        "id": "{{ device_id }}",
        "channel": {{ channel | int }},
        "on": {{ state }},
        "auth_key": "{{ api_key }}"
      }
    headers:
      Content-Type: application/json
      verify_ssl: true
  1. Restart Home Assistant: Restart Home Assistant to apply the changes.

:warning: Notes

  • Disable Multiline: Make sure the multiline option for the text helpers is disabled.
  • Device ID: You can find the device ID in your Shelly device settings under control.shelly.cloud.
  • Status Updates: The device state is not updated from the cloud. Only changes pushed from Home Assistant will be reflected.
3 Likes

what do you mean by manage? what is the benefit of this blueprint, i am having hard time to understand before installing and testing it out.

When researching, I couldn’t find any integration or blueprint that can control Shelly devices in a remote network, for example in a holiday apartment. This blueprint makes that possible.

1 Like

Thanks for this, saved me a lot of trouble as i just installed 5 shellys remotely.
Just tried on a Shelly Pro EM-50 and it works wonderfully.

Here is my code to get the EM-50 stats if interested:
It pulls wifi signal, relay status and Power/Energy from each of the two sensors.
I didnt bother to get the rest for now.

rest:
  - resource: https://shelly-xx-eu.shelly.cloud/device/status
    method: POST
    payload: auth_key=xxx&id=xxx
    scan_interval: 5
    headers:
      User-Agent: Home Assistant
      Content-Type: application/x-www-form-urlencoded
    sensor:
      - name: RVN Big Shelly RSSI
        value_template: "{{ value_json.data.device_status.wifi.rssi }}"
        unit_of_measurement: "dBm"
        device_class: signal_strength
      - name: RVN Big House Power
        value_template: '{{ value_json.data.device_status["em1:0"].act_power }}'
        unit_of_measurement: "W"
        device_class: power
      - name: RVN Big House Energy
        value_template: '{{ value_json.data.device_status["em1data:0"].total_act_energy }}'
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
      - name: RVN Big WaterHeater Power
        value_template: '{{ value_json.data.device_status["em1:1"].act_power }}'
        unit_of_measurement: "W"
        device_class: power
      - name: RVN Big WaterHeater Energy
        value_template: '{{ value_json.data.device_status["em1data:1"].total_act_energy }}'
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
    binary_sensor:
      - name: RVN Big Waterheater Status
        value_template: '{{ value_json.data.device_status["switch:0"].output }}'

The last part of the code reports the status of the actual switch, so you dont have to guess.

I created a dummy switch that controls your automation.

And finally a template switch that swithces the dummy switch on and off (to control the relay) gets its value from {{states.binary_sensor.rvn_big_waterheater_status.state}} so it reflects the true state of the relay.

It would be great if someone with enough knowledge could pack all these into an integration that would work with just the url/api key / device id :slight_smile:

1 Like

Thanks so much for your kind words—really glad the post helped and that your Shelly Pro EM-50 setup is working smoothly! :raised_hands:

Just a heads-up: Shelly also provides a WebSocket API that allows you to receive real-time events (like instant status updates without polling). However, Home Assistant currently only supports this via a custom integration, so the process is a bit more complex and not as plug-and-play as one might hope.

If anyone wants to build on the blueprint I shared, feel free to use it, modify it, and even publish your version in the forum. The more people benefit from it, the better :bulb:

And if you’re ever interested in packaging this into a proper integration—where you just enter the URL, API key, and device ID—I’d be happy to help brainstorm or collaborate!

That would be super cool if someone took the time to turn this into a proper integration :slight_smile:

2 Likes

Honestly, it was one of the (not few) times where i searched something and found exactly what i was looking.
So thanks again

I have no serious coding skills, but i believe a remote-shelly integration would be rather usefull, as their popularity increases constantly.

For now i worked on my own code for the devices I have (two PM-50, a gen1 and two smoke detectors) that unfortunately is too specific to help someboday else.

Let’s hope someone with the correct knowledge has the same need aswell :slight_smile:

2 Likes

I am trying to get this working, but am completely lost. I followed the instruction to the letter - as far as i understood it:

  • made a text helper for the URL
  • made a Text helper for the API key
  • added the YAML to my config file
  • imported the blueprint
  • in the blueprint I selected the two helpers I created in the according fields
  • I set shelly channel 0
  • I copied the Device ID
  • I (had to) create a toggle helper in the blueprint
  • I hit save

Now I’m getting these errors and the toggle helper does nothing:

When I re-open the blueprint, all the fields are empty again. I tried re-filling them and saving again, but upon re-opening it, they again are empty. Then realized this somehow adds a new block of configurations to the automations.yaml each time. So i deleted all but one block.

What am I doing wrong? I have never before used a blueprint and have no clue about programming.

Do I understand correctly, that toggle helper would then be the switch that remotely controls the shelly? …and also feeds back its state if locally switched?

How (if at all) would i be able to read out the power measurement (it is a 1PM Gen4)?

Any help would be appreciated, thanks in advance!

Hi there!

Could you please check your indentation and make sure you placed the rest_command: section at the correct level in your configuration?

Also verify that it is included in your configuration.yaml and not nested incorrectly under another key.