Appliance, Smartplug, OpenEVSE demand scheduler: Find the best time to run household loads
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Demand Shaper

Appliance, Smartplug, OpenEVSE demand shaper: Find the best time to run household load.

The demand shaper module uses a day ahead power availability forecast and user set schedules to determine the best time to run household loads. An example could be charging an electric car, the user enters a desired completion time and charge duration, the demand shaper module then works out the best time to charge the car, generally there will be higher power availability overnight and during sunny midday hours. The demand shaper attempts to avoid running appliances at peak times while ensuring that the appliance has completed the required run period.

Developed as part of the CydYnni EnergyLocal project, see:


9th November 2018: The demand shaper module now supports the use of the UK grid carbon intensity and Octopus Agile forecasts.


  • Emoncms
  • Emoncms Device module
  • MQTT Mosquitto broker and MQTT emoncms setup as per emonSD image
  • Redis


Download or git clone the demandshaper repository to your home folder:

git clone

Link the 'demandshaper-module' into the emoncms Modules folder:

ln -s /home/pi/demandshaper/demandshaper-module /var/www/emoncms/Modules/demandshaper 


The demand shaper background process is called run.php. It can be ran manually with:

php run.php

Or via service:

sudo ln -s /home/pi/demandshaper/demandshaper.service /lib/systemd/system
sudo systemctl enable demandshaper.service
sudo systemctl start demandshaper

The demand shaper process publishes the device state to an MQTT topic of the form:


Remote Cache

The remote cache currently run's on to reduce the potential API load on the Octopus and CarbonIntensity servers. The cache provides the following routes:

To install and use the cache on your own server. Symlink emoncms-remote module to Modules folder:

ln -s /home/username/demandshaper/emoncms-remote /var/www/emoncms/Modules/demandshaper

Add the cron entry:

0 * * * * php /home/username/demandshaper/emoncms_remote_cache.php >> /var/log/demandshaper-cache.log

Using the Demand Shaper module with a SonOff S20 smart plug


  1. Install the EmonESP (control_merge branch) firmware on a Sonoff S20 smartplug. See guide here:

  2. Enable the UDP broadcast script on the emonbase/emonpi:

    crontab -e
    * * * * * php /home/pi/emonpi/UDPBroadcast/broadcast.php 2>&1
  1. Install the demand shaper module as above and make sure that you have the latest emoncms master branch and latest emoncms device module installed.

User guide

  1. The Sonoff S20 smartplug creates a WIFI access point, connect to the access point and enter home WIFI network. That is all the configuration required.
  1. Connect back to your home WIFI network. Login to emoncms and navigate to inputs. Refresh the page until a popup appears asking to connect:


What happened here?: The smart plug discovers the emonbase/emonpi automatically by listening out for the periodic UDP packet published by the emonbase/emonpi, enabled by the UDP broadcast script.

  1. After clicking allow the smart plug will then appear in the inputs list with a small icon identifying it as a schedulable device:


What happened here?: The smart plug received the MQTT authentication details from the emonbase/emonpi automatically as part of a pairing process enabled by clicking on Allow. After connecting to MQTT the smartplug sent a descriptor message that automatically created and configured an emoncms device based on the smartplug device template in the emoncms device module.

  1. Click on the clock icon to load the demandshaper module, where the smart plug can be scheduled:


  1. Wait for the plug to turn on! :)


Submit schedule: