Skip to the content.

Date: 2024-07-01

I’ve put the YaSolR project in pause for a few days to work on this very cool and awesome Shelly integration…

Shelly Solar Diverter / Router

What is a Solar Router / Diverter ?

A Solar Router allows to redirect the solar production excess to some appliances instead of returning it to the grid. The particularity of a solar router is that it will dim the voltage and power sent to the appliance in order to match the excess production, in contrary to a simple relay that would just switch on/off the appliance without controlling its power.

A Solar Router is usually connected to the resistance of a water tank and will heat the water when there is production excess.

A solar router can also do more things, like controlling (on/off) the activation of other appliances (with the grid normal voltage and not the dimmed voltage) in case the excess reaches a threshold. For example, one could activate a pump, pool heater, etc if the excess goes above a specific amount, so that this appliance gets the priority over heating the water tank.

A router can also schedule some forced heating of the water tank to ensure the water reaches a safe temperature, and consequently bypass the dimmed voltage. This is called a bypass relay.

Shelly Solar Diverter Features

This solar diverter based on Shelly devices and a Shelly script can control remotely dimmers and could even be enhanced with relays. Shelly’s being remotely controllable, such system offers a very good integration with Shelly App and Home Automation Systems like Home Assistant.

It is possible to put some rules based on temperature, time, days, etc and control everything from the Shelly App or Home Assistant.

The Shelly script, when activated, automatically adjusts the dimmers to the grid import or export (solar production excess).

Download

Hardware

All the components can be bought at https://www.shelly.com/, except the voltage regulator, where you can find some links on my website

Shelly Pro EM - 50 Shelly Dimmer 0/1-10V PM Gen3 Shelly Plus Add-On Temperature Sensor DS18B20 Voltage Regulator
- Loncont LSA-H3P50YB
- LCTC DTY-220V40P1

Some additional hardware are required depending on the installation. Please select the amperage according to your needs.

Wiring

Shelly Add-On + DS18B20

First the easy part: the temperature sensor and the Shelly Add-On, which has to be put behind the Shelly Dimmer.

Electric Circuit

RC Snubber

If switching the contactor / relay causes the Shelly device to reboot, place a RC Snubber between the A1 and A2 ports of the contactor / relay.

Add other dimmers

If you want to control a second resistive load, it is possible to duplicate the circuit to add another dimmer and voltage regulator.

Modify the config accordingly to support many dimmers and they will be turned on/off sequentially to match the excess production.

Setup

First make sure that your Shelly’s are setup properly.

The script has to be installed inside the Shelly Pro EM 50, because this is where the measurements of the imported and exported grid power is done. Also, this central place allows to control the 1, 2 or more dimmers remotely.

Shelly Dimmer Setup

Shelly Pro EM 50 Setup

How to use

Configuration

Edit the CONFIG object and pay attention to the values, especially the resistance value which should be accurate, otherwise the routing precision will be bad.

const CONFIG = {
  // Debug mode
  DEBUG: 1,
  // Grid Power Read Interval (s)
  READ_INTERVAL_S: 1,
  PID: {
    // Reverse
    REVERSE: false,
    // Proportional Mode:
    // - "error" (proportional on error),
    // - "input" (proportional on measurement),
    // - "both" (proportional on 50% error and 50% measurement)
    P_MODE: "input",
    // Derivative Mode:
    // - "error" (derivative on error),
    // - "input" (derivative on measurement)
    D_MODE: "error",
    // Integral Correction
    // - "off" (integral sum not clamped),
    // - "clamp" (integral sum not clamped to OUT_MIN and OUT_MAX),
    // - "advanced" (advanced anti-windup algorithm)
    IC_MODE: "advanced",
    // Target Grid Power (W)
    SETPOINT: 0,
    // PID Proportional Gain
    KP: 0.3,
    // PID Integral Gain
    KI: 0.3,
    // PID Derivative Gain
    KD: 0.1,
    // Output Minimum (W)
    OUT_MIN: -10000,
    // Output Maximum (W)
    OUT_MAX: 10000,
  },
  DIMMERS: {
    "192.168.125.98": {
      // Resistance (in Ohm) of the load connecter to the dimmer + voltage regulator
      // 0 will disable the dimmer
      RESISTANCE: 24,
      // Percentage of the remaining excess power that will be assigned to this dimmer
      // The remaining percentage will be given to the next dimmers
      RESERVED_EXCESS_PERCENT: 100,
      // Set whether the Shelly EM with this script will be used to control the bypass relay to force a heating
      // When set to true, if you activate remotely the bypass to force a heating, then the script will detect it and turn the dimmer off
      BYPASS_CONTROLLED_BY_EM: true,
    },
    "192.168.125.97": {
      RESISTANCE: 0,
      RESERVED_EXCESS_PERCENT: 100,
      BYPASS_CONTROLLED_BY_EM: false,
    },
  },
};

Several dimmers

The script can automatically control several dimmers. Just add the IP address of the dimmer and the resistance of the load connected to it.

How it works:

If you have 2000W of excess, and 2 dimmers of 1500W each (nominal load), then the first ome will be set at 100% and will consume 1500W and the second one will consume the remaining 500W.

Excess sharing amongst dimmers

It is possible to share the excess power amongst the dimmers. Let’s say you have 3 dimmers with this configuration:

DIMMERS: {
  "192.168.125.93": {
    RESISTANCE: 53,
    RESERVED_EXCESS_PERCENT: 50,
  },
  "192.168.125.94": {
    RESISTANCE: 53,
    RESERVED_EXCESS_PERCENT: 25,
  },
  "192.168.125.95": {
    RESISTANCE: 53,
    RESERVED_EXCESS_PERCENT: 100,
  }
}

When you’ll have 3000W of excess:

Start / Stop Automatic Divert

Once the script is uploaded and started, it will automatically manage the power sent to the resistive load according to the rules above.

You can start / stop the script manually from the interface or remotely by calling:

http://192.168.125.92/rpc/Script.Start?id=1
http://192.168.125.92/rpc/Script.Stop?id=1

Solar Diverter Status

You can view the status of the script by going to the script status endpoint, which is only available when the script is running.

http://192.168.125.92/script/1/status
{
  "config": {
    "DEBUG": 2,
    "READ_INTERVAL_S": 1,
    "PID": {
      "REVERSE": false,
      "P_MODE": "input",
      "D_MODE": "error",
      "IC_MODE": "advanced",
      "SETPOINT": 0,
      "KP": 0.3,
      "KI": 0.3,
      "KD": 0.1,
      "OUT_MIN": -10000,
      "OUT_MAX": 10000
    },
    "DIMMERS": {
      "192.168.125.98": {
        "RESISTANCE": 24,
        "RESERVED_EXCESS_PERCENT": 100
      },
      "192.168.125.97": {
        "RESISTANCE": 0,
        "RESERVED_EXCESS_PERCENT": 100
      }
    }
  },
  "pid": {
    "input": 0,
    "output": 0,
    "error": 0,
    "pTerm": 0,
    "iTerm": 0,
    "dTerm": 0,
    "sum": 0
  },
  "divert": {
    "lastTime": 1720281498691.629,
    "dimmers": {
      "192.168.125.98": {
        "divertPower": 0,
        "maximumPower": 2263.98374999999,
        "dutyCycle": 0,
        "powerFactor": 0,
        "dimmedVoltage": 0,
        "current": 0,
        "apparentPower": 0,
        "thdi": 0,
        "rpc": "success"
      }
    }
  }
}

Automation ideas

You may need to use Home Assistant or Jeedom depending on what you need to do because the Shelly App, at the time of writing, does not support a lot of actions.

PID Control and Tuning

The script uses a complex PID controller that can be tuned to really obtain a very good routing precision. The algorithm used and default parameters are the same as in the YaSolr project. You will find a lot of information in the YaSolR manual.

Future Improvements

Demos

Here is a demo video of the Shelly device reacting to EM measured power:

Shelly Solar Diverter Demo

Here is a demo video where you can see the solar production and grid power of the home, and the Shelly device reacting to the excess production and setpoint defined.

Shelly Solar Diverter Demo

Here is a PoC box I am using for my testing with all the components wired. In this PoC on the left, I have used the LCTC voltage regulator which comes already pre-mounted on a heat sink. On the right, with the LSA. The Shelly Dimmer Gen 3 with the Shelly Addon are in the black enclosure, the voltage regulator on the right and the Shelly EM Pro at the top right.

Help and Support