Close
0%
0%

Carbon Intensity controlled Mains Socket Switch

Combining the current carbon intensity of the UK electricity grid, some google script and an application of IFTTT to control a Wi-Fi switch

Similar projects worth following
This project combines the current carbon intensity of the electricity grid, some google script and an application of If This Then That (IFTTT) to turn on or off a WiFi plug socket. Why? I have a modern gas boiler that provides hot water for my central heating and heats water for my hot water tank, if the carbon intensity of the grid gets below a certain amount then it is more environmentally friendly to heat my water using the electric immersion heater in the hot water tank rather than use gas.

The project is split up into 4 separate sections:

  1. Get carbon intensity of grid (API feed from carbon intensity)
  2. If the carbon intensity is lower than a specified amount (google script)
  3. Then call a IFTTT web hook (IFTTT web hook )
  4. Use the IFTTT web hook to control a switch (IFTTT web applet maker)

Each of these steps has links to the other ones and the best way to proceed is probably to do the IFTTT section first of making the webhook and setting up the control of the switch which can be tested.  Then going on to make the carbon intensity feed processing parts.

  • 1 × IFTTT enabled smart Switch Used a TP-LINK HS110

  • 1
    Setting up an IFTTT webhook

    This instruction assumes you have an If This Then That (IFTTT) account, if not you will need to set one up here IFTTT Home Page.

    To create a webhook you need to visit the Webhook maker space. You will need to connect a webhook so hit the connect button


    With Webhooks activated you can bring up the documentation slide.

    This provides the URL that you can now access to cause the webhook to trigger.

    In this case the link is:

    https://maker.ifttt.com/trigger/{event}/with/key/cGNqm1vxEBec2FqnRgBLwe

    The random jumble of numbers and letters at the end is your specific code, this can be changed to a new number using Settings facility.  The {event} part of the code is the variable that gives you some control.  If {event} is changed to ‘turn_on’ or ‘turn_off’ then these events can be made in to trigger specific IFTTT tasks.  The text needs to be saved as this is what is used in the google script later to run the IFTTT task.


  • 2
    Using IFTTT webhook to control a switch

    From the IFTTT home page. Click on the 'My Applets' link at the top

    From this window you can then create a new applet.

    This brings up the following screen, which takes a more of graphical perception of what you are wanting to do. So you need to click the ‘+ this’ blue part of the screen.  This indicates the ‘if this’ part of the code.

    You need to choose a service to instigate the start of the applet, search for a “webhooks” and click on the service required.

    There is only 1 trigger that webhooks allows, that is once a web request is received the trigger is fired.

    The next gives you option of the name of event.  As this is to turn on the switch a sensible event name of ‘Turn_on’ seems appropriate.

    This then returns you the ‘If this then that’ screen, only this time you have click on the second part of the screen.


    The WiFi socket I have chosen to undertake this project is TP-link HS110. Reasons for this choice :

    1. Cost – at time of writing HS110 can be purchased for  £19.99
      1. Specifications –
        • The HS110 can work with up 13A so suitable for heavy heating circuits
        • Also has inbuilt power monitor
    2. Works with IFTTT using KASA app, though is only in BETA.

    Samsung SmartThings, Z-wave switches, Belkin Wemo Smart plugs, Dlink smart plug, energenie Mi Home, wifiplug, wattio to name the few I am aware of.

    First, comes the setup of the plug.  Each comes with its own setup.  The HS110, involved the installation of an App.  Creation of a Kasa account and setting up the smart plug.

    For this project I selected TP-link Kasa (Beta) is the selected output.

    When selecting TP-Link Kasa (Beta) you will need to link you IFTTT to Kasa, after giving it authorisation you can select one of the actions Kasa offers. As this action is to turn on the light.

    This loads the switches you have available in Kasa and the names you have given each switch.

    Creating the action and finishing the action.

    You can now test if this works using the URL from the webhook earlier –

    https://maker.ifttt.com/trigger/{event}/with/key/cGNqm1vxEBec2FqnRgBLwe

    We can change {event} to turn_on making it :

    https://maker.ifttt.com/trigger/turn_on/with/key/cGNqm1vxEBec2FqnRgBLwe

    Change the link to the one you have been given and going to the link should turn on the switch.

    This task needs to be repeated but instead of creating an event to turn on the light you can create one to turn it off.

  • 3
    Get carbon intensity of UK electricity grid

    The carbon intensity of electrical grids varies as the amount of coal, gas, nuclear, wind, solar or other energy sources are used to provide it.  Various companies provide services that can give you the current data being used in a current grid, https://www.electricitymap.org/ gives an international over view of the countries, states and regions that provided data. GridCarbon provides a smartphone app to tell you what the current grid emission is and gives you a few nice details. 

    In the UK a consortium of EDF (environmental defence fund), National Grid (UK transmission firm), Met Office (UK Weather forecaster) and WWF (now simply known by its initials) created a website which both tells the current GB electricity carbon intensity and forecasts the next 48 hours (http://carbonintensity.org.uk/).  For the point of this project the most useful part of this website is the ability to use an API (application programming interface) to their data.  Whilst their API provide a range of facilities such as carbon intensity in the past and intensity forecast for the future.  This project takes the simple approach of what is relevant now and the intensity function. If you click this intensity link , then depending on your browser it responds differently.  Internet explorer tries to get you to download a JSON (javascript object Notation) file which when opened in a text editor looks like:

    { 
      "data":[{ 
        "from": "2017-11-24T16:00Z",
        "to": "2017-11-24T16:30Z",
        "intensity": {
          "forecast": 368,
          "actual": 408,
          "index": "very high"
        }
      }]
    }
     

    If you open in another browser it would probably just show you the text.  The data suggests that for the half an hour time window just finished the carbon intensity of the grid was 408g CO2e (carbon dioxide equivalent) for each kWh (kilowatt hour) of power generated.

    If only this data could be extracted in an automatic manner every 15 minutes or so

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates