Selecting board/shield for WiFi controlled relay

Hi!

It's been more than 10 years since I last played around with an Arduino, so the current multitude of boards and shields has kind of overwhelmed me (especially since it seems so much has changed). I could use some sanity checking to make sure I'm on the right track with regards to choosing the correct stuff to buy.

What I want to do:
Override an old in-door temperature sensor to turn off heat-pump when electricity is high. The sensor is a simple thermistor of some kind, and I don't need any more control over it than temporarily lowering the resistance to trick the thermostat into thinking the temperature is higher than it is.

My project:
Get some kind of WiFi Arduino board with a simple relay. Wire up the relay with a suitably sized resistor in parallel with the sensor. When I want to turn off the heat pump the Arduino simply tells the relay to close the circuit which will lower the perceived resistance for the thermostat.

My current plan:
Get a MKR WiFi 1010 and a MKR Relay Proto Shield.
Write up a simple loop that polls the internet for the current/future energy prices.
Switch on relay during the N most expensive hours per day.

Questions:

  1. What do I need to get apart from the boards above? Back in the days I vaguely remember needing an SD card to plug in, but the current boards seem to have internal storage.
  2. It looks like the MKR WiFi 1010 supports being powered from (and charging) a LiPo battery. What types of battery packs work?
  3. I took a quick look at the WiFi APIs. From what I can see, they look pretty straight-forward when it comes to doing HTTP requests (and even serving web pages if I want to dump some stats from the board). Anything I should be aware of with regards to networking limitations?

Thanks!

1 Like

What do You want "high electricity" to tell?

Interesting! Do I understand it correctly that it's compatible with the Arduino standard libraries? If so, that looks exactly like what I want.

Sorry, should have proof-read that before posting. What I meant to say was that I want to turn off the heat-pump when the "electricity price is high". Coding-wise, it looks like this should be fairly trivial given what's included in the standard library.

Okey. It could have been that Your total current consumption was getting high....

If You could post technical documents showing the heat pump possibilities that could help helpers finding even better or easier ways.

I once did a similar thing: As long as the heat pump was not running to 100% the electrical heat system should be off. The producer of the systems gave me an interface card for that....

If You can find out.... Is that thermistor a PTC or NTC element? PTC increases the resistance at raising temperature. NTC does the opposite.

1 Like

Well, you install the ESP8266 libraries in the IDE.

But you need a programmer.
To program the ESP-01, you use a purpose-built USB programming adapter which works perfectly with the Arduino IDE:
Aliexpress item
Even easier is to use the automatic version of the programming adapter.

No jumper, no switch. The button is a reset button, but you don't actually need it for anything as the reset is automatic anyway.
Aliexpress link.

1 Like

From what I can tell, our heating system is a bit weird and not exactly installed the way it's supposed to be. It's a water-based floor heating system where the heat-pump heats the water. Normally a system like this should be controlled by a control module that tries to regulate the water temperature in the heating loop with the desired temperature set by an outdoor sensor.

Our system is instead controlled by a simple thermostat really meant for radiators. It simply turns on and off the heat-pump based on an indoor temperature sensor. We can tell that the floor temperature fluctuates a bit, but the system is producing a pretty stable indoor-temperature despite the controller not really being meant for controlling a heat-system with this much delay. (It's probably not optimal since the temperature in the heating-loop will end up much higher than it strictly needs to be, which will waste some energy.)

What I would really like to do is to switch out the thermostat to a controller meant for the system. But that is relatively pricey and may require also installing an extra water tank to increase the amount of water in the loop to avoid the pump turning on and off too frequently. But the heat-pump is getting kind of old, so making big investments feels short-sighted since it might need replacement in a couple of years anyway.

Given that our indoor temperature is pretty ok all things considered and the only thing we really want at the moment is to turn off the heat-pump during the most expensive hours, faking the indoor sensor feels like the simplest solution.

Good catch. I assumed it was NTC since that is what most of the documentation for the heat-pump was talking about, but the thermostat I want to mess with is actually another brand and I just measured and found it was increasing resistance when temperature went up.

If you are going to have internet access, it would be possible to get outside temperature (approximately) from a weather API.

It would be another useful datapoint for deciding whether to run the heat pump.

I get it, I think.
I ran a heat pump system gaining energy from the out going air and the system heated up the incoming air. There was a gain and offset parameter to manipulate. As backup an electrical heater heated water circulating in a radiator system at temperatures below 5 C. I'm not sure but guess the heatpump system measured the temperature of the incoming air.

You have a very well working system regarding indoor temperature. If You cut off the heatpump You will experience draft, feeling cold.

I wonder if it's worth it, being less comfortable at home.

To save energy, and cut costs, may there are better ways to do it? Look at dishwashers, washing machine. Running them at low cost hours would save money.

Hi Railroader, Your questions are legit and I also want the solution for them, To save energy, and cut costs, may there are better ways to do it? Look at dishwashers, washing machine. Running them at low cost hours would save money. This line is really worth legit reply. Also Waiting for that!

I wouldn't mind trying a wireless relay one day. Its nice to see the opto isolators, but they really messed up on the high voltage AC to low voltage DC isolation ...

image

Found a dual relay version here where they really paid attention to the AC to DC isolation, but no opto isolators. Still, it seems like a better product, where if using only one relay, I'd pick the one farthest away from the wireless MCU because its located right next to the relay coil which is a bad idea.

image

An air/air heat-pump is a very different beast from an air/water heat-pump driving floor heating. The control response of an air/air heat-pump is more or less immediate. If you turn it off, you will get cold pretty soon.

The response of an air/water heat-pump driving floor heating is typically 24h or longer. I can turn off the heat-pump for a couple of hours and not notice a thing. Hence why floor heating systems like these should ideally be controlling the temperature of the heating loop to match expected heat loss due to outdoor temperature rather than trying to control for a specific indoor temperature. The fact that our radiator style thermostat gives a pretty stable indoor temperature is actually mildly surprising :slight_smile:

No. :slight_smile:
I live in Sweden. Even in a well-insulated house with an efficient heating system, 60-70% of energy usage goes to heating. Dishwashers and washing machine are a drop in the bucket in comparison (although we of course try to not run them when energy is expensive either). Even just shifting the heat-pump away from running during the 4 most expensive hours makes a noticeable difference.

The price is not necessarily the issue, we just want to avoid peak hours to make it easier for the power producers to avoid having to switch on fossil fuel plants. Having hourly billing gives us an incentive to do the right thing. And gives me an excuse to tinker with stuff :smiley:

I do agree. Not sure whether I actually have that module here or not and I don't feel like searching beyond the nearest "ESP" jar on the desk here. :grin: I would not use it for mains myself - but have a couple of Sonoff Minis here which are almost the same concept but more expensive and I trust, far better built.

The OP here is however intending to use it for a low voltage control circuit of some sort so it should be quite safe. :+1:

Okey, I get the picture. I also live in Sweden...
Yes, heating, during winter is the major cost.
Do You have access to the temp sensor terminals so You could measure the changes?
I didn't understand if You know for sure the kind of manipulation needed. Is it switching in a parallell resistor or add extra resistance in serie?

to control heating to avoid peak hours one could have a simple system with a Real Time Clock (such as the DS3231) and a relay which switches the heating ON/OFF at the appropriate times.

The program loops checking the time from the RTC and switching the relay as required - the switching times could be held in an array.

A simple switch could be used to overrule the RTC control
A more sophisticated system could run a webserver which could support switching ON/OFF from a web browser, e.g. similar functionality to the ESP01/01S RELAY MODULE
Or similar functionality using BLE and a smartphone.

When connecting to mains voltages make sure the relay is opto isolated.

Check the current required by the heating system to ensure that the relay contacts can carry it.
e.g. a heat pump could easily take 25amps well beyond the capacity of a small relay such as the ESP01/01S RELAY MODULE (maximum 10amps at 240V resistive load) - the relay would have to drive a contactor of a suitable capacity.

Same module as referenced in #2 and #8, but poor instructions and advice. :worried:

the ESP01/01S RELAY MODULE works OK as a low cost smart switch to control devices such as lights, heaters, etc.
The ESP01/01S RELAY MODULE TUTORIAL gives instructions on setting up and programming the ESP-01 and provides an example program which connects to the local WiFi network and runs a webserver. A web client connects to the webserver which displays a web page with buttons which enable the remote switching ON/OFF of the relay. It would be fairly easy to write a client which connects to the ESP-01 to switch the relay ON/OFF at set times, e.g. to control a water heater.

Edit: modified a Java TCP client program to connect to ESP-01 webserver looping switching the relay ON for 5 seconds then OFF for 5 seconds. ESP-01 code not modified. Would be simple to modify client to control a heater switching ON/OFF at specified times of day.

I have updated the Java TCP client to switch the relay ON and OFF at set times during day

// TCP_relay_timer_2 - switch relay ON and OFF at set times during day

import java.io.*;
import java.util.*;
import java.net.*;
import java.util.concurrent.TimeUnit;
import java.time.LocalDateTime;

public class TCP_relay_timer_2 
{
   static int port=80;                                               // HTTP port to send/receive on
   static String remoteIPaddress= ("192.168.1.210");//"127.0.0.1");  // IP of remote machine   
   // method to switch relay ON or OFF
   static  Boolean TPC_relay(Boolean debug, String command) throws Exception
    {
    if(debug) System.out.println("\nTCPClient: IP address " + InetAddress.getLocalHost().toString() + " port " + port );
    if(debug) System.out.println("Connecting to TCPServer on to " + remoteIPaddress + " socket " + port);
    Socket socket = new Socket( remoteIPaddress, port );                         // open socket to server
    PrintStream objOut = new PrintStream( socket.getOutputStream() );            // OK, open streams
    Scanner objIn  = new Scanner( socket.getInputStream() );
    if(debug) System.out.println("Sending to " + remoteIPaddress + " socket " + port + " data: " + command);
    objOut.println(command);                          // send string
    // loop waiting for message fom server - check for relay ON or OFF
    while(true)                                    
       try {
            String s = (String) objIn.nextLine();             // read string and display it
            if(debug) System.out.println("Client received: " + s );
            if(s.startsWith("Relay is now: ON"))
               {if(debug)  System.out.println("******* relay ON **********"); relayState=true; }
            if(s.startsWith("Relay is now: OFF"))
               {if(debug)  System.out.println("******* relay OFF **********"); relayState=false; }
           }
       catch (Exception se) {break;}
    return true;
   }


static Boolean relayState=false;

// switch ON relay and check result
// if dubug is true print debuf information, e.g.HTTP response
// if check_state is ture communicate with server to make sure it is OFF
static public void relay_ON(Boolean debug, Boolean check_state)  throws Exception {
     if(!check_state && relayState)return;
     System.out.println("\nswitching relay ON ");
     TPC_relay(debug, "/RELAY=ON");
     if(relayState) System.out.println("checked relay is ON ! ");
     else           System.out.println("checked switch ON failed!");
   }

// switch OFF relayand check result
// if dubug is true print debuf information, e.g.HTTP response
// if check_state is ture communicate with server to make sure it is OFF
static public void relay_OFF(Boolean debug, Boolean check_state)  throws Exception {
     if(!check_state && !relayState)return;
     System.out.println("\nswitching relay OFF ");
     TPC_relay(debug, "/RELAY=OFF");
     if(!relayState) System.out.println("checked relay is OFF ! ");
     else           System.out.println("checked switch OFF failed!");
}

// simple time class
public static class Time {
  // constructor setting hour and minutes
  Time(int hour, int min) { this.hour=hour; this.min=min; }
  public String toString() {
      return this.hour + ":" + ((min < 10) ? "0" : "") + min; }
  // return true if time >= on and < off
  public Boolean compare(Time on, Time off) {
    // test for ON hour > OFF hour, i.e. overnight - if so add 24 to OFF hour
    if(on.hour <= off.hour) {
       // On < OFF so normal day ON/OFF timing
       if(((hour+min/60f) >= on.hour+on.min/60f) && (hour+min/60f) < (off.hour+off.min/60f) )
            return true; else return false;
       }
     else
         // overnight ON/OFF timing
         if((hour+min/60f) >= (on.hour+on.min/60f) || (hour+min/60f) < (off.hour+off.min/60f) )
            return true; else return false;
  }
  private int hour, min;
};

public static void main(String args[]) throws Exception
{
     relay_OFF(true,true);
     // sample ON/OFF times - last time is overnight
     //  note: no check on overlapping ON/OFF times etc
     Time[] timeON ={new Time(8, 28), new Time(8, 33), new Time(8, 36), new Time(21,30)};
     Time[] timeOFF={new Time(8, 29), new Time(8, 35), new Time(8, 37), new Time(7, 0)};
     System.out.println("timeON[0] = " + timeON[0]);
     System.out.println("timeOFF[0] = " + timeOFF[0]);
     // test overnight time compare
     Time timeNow=new Time(22, 00);
     //System.out.println(timeNow.compare(timeON[3], timeOFF[3]));
     //timeNow=new Time(2, 00);
     //System.out.println(timeNow.compare(timeON[3], timeOFF[3]));
     LocalDateTime date1 = LocalDateTime.now();
     // check time to send command to switch ON/OFF every minute
     while(true) {
       timeNow=new Time(date1.getHour(),date1.getMinute());
       System.out.print("timeNow = " + timeNow);
       Boolean relayON=false;
       // itterate thru times checking relay should be ON or OFF
       for(int i=0; i< timeON.length;i++)
           if(timeNow.compare(timeON[i], timeOFF[i])) relayON=true;
       if(relayON)   relay_ON(false, true);
       else          relay_OFF(false,true); 
       //if(relayState) System.out.println(" relay is ON ! ");
       //else           System.out.println(" relay is OFF !");
       int lastMinute=date1.getMinute();
       // wait for minute to change 
       do {       
          TimeUnit.SECONDS.sleep(5);
          date1 = LocalDateTime.now();
       }
       while(lastMinute == date1.getMinute());

   }
}
}

ran it for a few days appears to work OK including over night settings
a simple test run gave

> run TCP_relay_timer_2

switching relay OFF 

TCPClient: IP address BB-DELL2/169.254.164.171 port 80
Connecting to TCPServer on to 192.168.1.210 socket 80
Sending to 192.168.1.210 socket 80 data: /RELAY=OFF
Client received: HTTP/1.1 200 OK
Client received: Content-Type: text/html
Client received: 
Client received: <!DOCTYPE HTML>
Client received: <html>
Client received: <head><title>ESP8266 RELAY Control</title></head>
Client received: Relay is now: OFF<br><br>
******* relay OFF **********
Client received: Turn <a href="/RELAY=OFF">OFF</a> RELAY<br>
Client received: Turn <a href="/RELAY=ON">ON</a> RELAY<br>
Client received: </html>
checked relay is OFF ! 
timeON[0] = 8:28
timeOFF[0] = 8:29
timeNow = 8:27
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:28
switching relay ON 
checked relay is ON ! 
timeNow = 8:29
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:30
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:31
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:32
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:33
switching relay ON 
checked relay is ON ! 
timeNow = 8:34
switching relay ON 
checked relay is ON ! 
timeNow = 8:35
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:36
switching relay ON 
checked relay is ON ! 
timeNow = 8:37
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:38
switching relay OFF 
checked relay is OFF ! 
timeNow = 8:39
switching relay OFF 
checked relay is OFF ! 

I think it is simpler to equip the relay Microcontroller with a RTC to control the relay switching times which can be updated using a web client

1 Like