How to save energy with BARY: Smart home





I think every modern person at least once wondered: how much can you pay for such waste bills for a communal apartment ?! Here I am - no exception. Light, gas, heating, water, rent, elevator, solid waste removal, etc. etc.



One of the reasons (far from the last) when creating the BARY application was the ability to collect statistics, analyze and reduce energy consumption. Europe has long since passed into a regime of total economy, I think this fate will not bypass us. Therefore, it will definitely not be superfluous to prepare for this in advance.



I propose to consider how it turned out to optimize energy costs together with BARY: Smart Home.



Getting started: air conditioning and underfloor heating



The first optimization of energy costs was putting in order in the use of underfloor heating and air conditioning. Even without a detailed analysis, it was clear that they consume a lot.



Today, only the lazy did not write about the prevention of viral infections. But, nevertheless, repetition is the mother of learning. The key to healthy antiviral weather in an apartment is a temperature of 18-24 C, a humidity of 40-60%, as well as regular ventilation.



My air conditioner practically did not turn off in the summer. In winter, the same thing happened with underfloor heating. During the absence of the owners in the house, the air conditioner was turned off only occasionally (I did not want to return to the stuffy room), and the warm floors never. The bills for this whole thing were simply cosmic, and the temperature was far from ideal. It was somehow impossible to turn off everything manually before leaving: there was no time, then it was simply forgotten.



Most household air conditioners do not have remote air temperature sensors (I just have one), i.e. they do not accurately provide a given temperature regime. But they can be turned on by any external sensor when the upper temperature threshold is reached and turned off - when the lower one is reached. This was my first automation.



In fact, it looks like this: the lower threshold is set to 24.0 ° C and the upper one is 24.5 ° C. As soon as the temperature in the apartment rises above 24.5 ° C, the air conditioner turns on and works until the temperature drops below 24.0 ° C. To prevent the air conditioner from turning on and off every minute, a condition is set for the minimum time of work and rest. I have it for 10 minutes. I selected the meaning empirically. In practice, however, the temperature was always within the specified range.



In BARY it looks like this:





Fig. The rule for turning on the air conditioner



I think it is worthwhile to dwell in more detail on what the rule shown in the example does:



  • The condition of the air conditioner has not changed in the last 10 minutes;
  • Security mode is off;
  • The air conditioner is off;
  • Sleep mode is disabled (a different rule is used in night mode);
  • , ( , . , );
  • ( , .. , );
  • ( , ).


Since that moment, the consumption of electricity by the air conditioner has decreased several times. In order for the air conditioner not to run idle when the owners were absent, a virtual button was made in BARY, the status of which was present in the automation of the air conditioner ("Security" from the example above). The same virtual button was for night mode ("Sleep" from the example above), which was also taken into account in a separate automation rule and turned on the air conditioner in the quietest mode. Initially, these buttons had to be activated manually.



The solution for automation was found in the form of the Apple ecosystem. A bundle of my devices with Homekit was implemented, and an Apple TV was purchased. With its help, you can implement the work of automation rules in Homekit (you can also use an iPad, but I did not have one at that time). In Homekit itself, rules are created: the last person leaves the house; the first person comes home. The virtual buttons in BARY were attached to these rules.





Fig. Rules for automatic arming / disarming



At first I even kept statistics, which displayed the number of minutes worked by the air conditioner per hour. Unfortunately, now the statistics have already been lost, but the operating time of the air conditioner has been reduced by almost ⅔ of the original figure.



Identification of the main consumers of electricity



Main consumer analysis methods



In order to begin to optimize costs, it is necessary to understand where the leaves used for most of the electricity.

Here, I think, there may be different approaches:



  • We use special modules - relays. In addition to their main on / off function, they keep track of the energy that is consumed by the devices connected to them;
  • We use special meters using current transformers;
  • We measure the electricity consumption ourselves (for example, using a wattmeter) and indicate the average value in BARY (this method is completely inaccurate, but it will be possible to take into account the indicative readings).


For all devices, except for underfloor heating, I installed: overhead sockets from Blitzwolf, modules in Shelly 1pm / Aqara Relay Module / Fibaro Double Switch 2 sockets. Perhaps there was something else, I don’t remember now.

For underfloor heating, I took readings based on the status of their work and average consumption rates (just the third, not very accurate method).



There is a special field in the device settings for specifying energy consumption (consumer power):





Fig. Setting power consumption parameters for the device



The total power consumption was taken from the input meter using the Wemos D1 board and a simple sketch:



The source code for this sketch
#include <Wire.h> 
#include <EEPROM.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>

#define WIFI_SSID "****"
#define WIFI_PASS "****"
#define API_URL "http://192.168.1.33/api/post-data"

volatile unsigned int state = 0;
volatile unsigned int kWh = 0;
volatile unsigned int blinked = 0;

int impulse = 3200;
int eeAddress = 0;
unsigned int lastMillis = 0;
int counter = 0;
int blinkMin = 10;
int timeout = 15000;
int PIN = D8;

void setup()
{
  state = impulse;

  EEPROM.begin(512);
  counter = EEPROM.read(eeAddress);
  EEPROM.write(eeAddress, counter + 1);
  EEPROM.commit();

  pinMode(PIN, INPUT_PULLUP); 
  
  attachInterrupt(digitalPinToInterrupt(PIN), blink, RISING);

  Serial.begin(115200);
  Serial.println(F(" "));

  connectWiFi();
}

void connectWiFi() 
{
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("WiFi: Waiting for connection");
  }
  Serial.println("WiFi: connected");
}

float roundEx(float value, int digits) 
{
  int newValue = value * pow(10, digits);
  return (float) newValue / pow(10, digits);
}

void loop()
{
  if (blinked >= blinkMin && millis() - lastMillis > timeout) {
    float divider = (float) impulse * (millis() - lastMillis) / 1000 / 3600;
    float power = blinked / divider;
    float kWhFloat = kWh + (float) (impulse - state) / impulse;

    Serial.print(F("sec="));
    Serial.print(millis() / 1000);
    Serial.print(F("; time="));
    Serial.print((millis() - lastMillis) / 1000);
    Serial.print(F("; blinkMin="));
    Serial.print(blinked);
    Serial.print(F("; state="));
    Serial.print(state);
    Serial.print(F("; kWh="));
    Serial.print(kWhFloat, 3);
    Serial.print(F("; power="));
    Serial.print(power, 3);
    Serial.println(F(" "));
    blinked = 0;
    lastMillis = millis();

    if (WiFi.status() == WL_CONNECTED) {
      StaticJsonBuffer<300> JSONbuffer;
      JsonObject& JSONencoder = JSONbuffer.createObject();
      JSONencoder["device"] = "main_counter";
      JSONencoder["function"] = "counter";
      JSONencoder["counter"] = counter;
      JSONencoder["power"] = power;
      JSONencoder["usage"] = kWhFloat;
      char JSONmessageBuffer[300];
      JSONencoder.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
      Serial.println(JSONmessageBuffer);

      HTTPClient http;
      http.begin(API_URL);
      http.addHeader("Content-Type", "application/json");
      int httpCode = http.POST(JSONmessageBuffer);
      String payload = http.getString();
      Serial.print(httpCode);
      Serial.print(" ");
      Serial.println(payload);
      http.end();
    } else {
      connectWiFi();
    }
  }
}

void blink()
{
  detachInterrupt(digitalPinToInterrupt(PIN));
  attachInterrupt(digitalPinToInterrupt(PIN), lowInterrupt, FALLING);
  state--;
  if (state == 0 || state > impulse) {
     kWh++;
     state = impulse; 
   }
   blinked++;
}

void lowInterrupt(){
  detachInterrupt(digitalPinToInterrupt(PIN));
  attachInterrupt(digitalPinToInterrupt(PIN),  blink, RISING);
} 




Any electric meter has a pulse output, which is duplicated by an LED. When the LED blinks, the pulse has passed. If you connect some device, such as an Arduino, to the pulse output, you can count the number of pulses. The sketch makes a POST request with the current readings in BARY every 15 seconds (but not more often than it picks up a sufficient number of pulses) (I don’t remember why the device itself climbs onto the server, and not vice versa, at that moment it seemed convenient) ... The pulses are read on interrupts, and the strange attach / detach scheme is implemented to suppress contact bounce. There were no false positives.



Identification and analysis of other electrical consumers



If a main meter is used in the system, then electricity consumers that do not have meters will be displayed in statistics as unknown:





Fig. Poorly detailed energy consumption statistics



Having identified the obvious main consumers and played enough with homebrew sketches, I realized that there were too many consumers in the “Unknown” classification. It was decided to fire up heavy artillery: the WB-MAP12H multichannel counter . It made it possible to identify the most “voracious” lines and differentiate energy consumption even more.



Most of the expenses were allocated for air conditioning (in summer), underfloor heating (in winter), a breather (in winter), computer and multimedia. And yes, the kettle, which always works so noisily and puffs, turned out to be almost the most common consumer.



Electricity consumption statistics by category in BARY can be viewed in the “Events” - “Statistics”





tab. Fig. More detailed statistics on energy consumption.



Very convenient: when the consumption for any of the categories exceeds the average, the category is highlighted in red. Like “Air Conditioning” in the picture above. By the fullness of this line, one can judge the value of the excess as a percentage of the average.



You can also see what the statistics for a particular category are composed of:





Fig. Detailed statistics by device



How to avoid data duplication



If you use a set of devices for analyzing electricity consumption - a meter in an outlet + a total meter per line - the readings will be duplicated. BARY allows you to build a parent-child hierarchy. It is implemented as follows: for the devices themselves, we set the category of consumption and the superior counter (see the figure "Setting energy consumption parameters for the device").



A higher-level counter is needed if one counter counts the entire line, and the second counts a specific outlet. When viewing statistics, the readings of this outlet will be subtracted from the readings of the superior meter, and the data will not be duplicated. If we take readings from the upstream meter and specific points, then part of the costs (costs of those electrical consumers that belong to the lines of the upstream meter, but do not hang on the sockets with a dedicated counter) will be displayed as unknown in the statistics. (see fig. "Low-detailed statistics of energy consumption")

The nesting itself is not limited in any way. For example, I use a scheme of up to 4 attachments.



And now what i can do?



Let's say we are finished with the unknown, how can we start saving now? Of course, each smart home will have its own specifics. But here are some general working guidelines.



Leaving Home / Coming Home Scenarios



I highly recommend setting up a leaving home scenario! It seems to be trite, but it works very well. We include in this scenario disabling everything that is possible. The return home script, accordingly, returns everything to working mode.





Fig. List of devices to turn off when leaving home



Good Night Scenario



Have you ever wondered how much a standby device consumes? Just plugged into an outlet? I, yes. To drive in, so to drive =)

For example, an air conditioner, simply left in the outlet, consumes 1.4 W * h. It turns out 1.4 W * h * 24 hours * 30 days = 1 KW * h per month, and does not work for half a year at least.

Of course, the figure is small. But it costs us nothing to optimize costs with the Smart Home system. And there may be more than one and not five such “waiting” devices in the house. TVs, game consoles, computers and other devices. The more devices, the more consumption.





Fig. List of devices to disconnect in sleep mode



Temperature regime



We set the temperature regime of underfloor heating to the minimum permissible. For example, in the bathroom, the temperature is set at 26 ° C, this is a perfectly acceptable temperature and not much energy is spent on this mode. If the humidity is exceeded (someone is taking a shower), we increase the temperature (during the shower, the floors usually have time to warm up by 2-3 degrees).



In other rooms, we do auto-shutdown of the heated floor using a motion sensor (why heat the floors if there is no one in the room?).



If separate electric heaters are used, then we also bind their operation to the temperature sensor (as with an air conditioner). If a “Tion” type breather is used, then in summer we try to let as little air as possible into the room (it is hot and this is an extra work for the air conditioner), in winter - the same with cold air (the breather itself heats it).



Let there be light! But only on business



If the lighting in bathrooms, dressing rooms, storerooms and other similar rooms is still turned on and off manually, we tie it to a motion sensor. This way you will never forget to turn off the lights! Well, you will not need to look for a switch in the kitchen next to the midnight refrigerator in the dark. In addition, this is not difficult to do - Ali has a bunch of switches that work over Wi-Fi / Zigbee / 433 MHz, including those without a zero line.



If you still use incandescent lamps, halogen and other gluttonous light sources, then know:



On November 23, 2009, Federal Law No. 261-FZ "On Energy Saving" was issued, which provided that incandescent lamps with a capacity of 100 watts or more would be banned for production and sale from January 1, 2011, with a capacity of 75 watts or more will be canceled from January 1 2013.



It's time to think about switching to more economical ones - LED and energy-saving ones.



With the same luminous flux of 1200Lm, an incandescent lamp consumes 100 W, fluorescent / energy-saving - 25-30 W, and LED - about 10 W. Plus the lifespan of LED and energy saving bulbs is much longer than that of an incandescent lamp.



We recently had an automation case that used Edison-style incandescent bulbs. More than 40 lamps of 60 W each. Having taken statistics on energy consumption for one month, we found without surprise that more than a third of the electricity bill fell on these lamps. All lamps were immediately replaced with similar, but LED. They paid off very quickly.



Epilogue



For 5 years of work on your smart home, many scenarios and automation have improved and underwent significant changes. Energy saving has become a pleasant habit. Now it is difficult to imagine that underfloor heating is fried from morning to night, and the air conditioner is constantly humming. The weather in the house is comfortable, and payments for light are pleasing to the eye and wallet. BARY on guard for saving resources!



I hope you found this material useful. If you have your own examples of optimizing electricity costs, share in the comments what and how you have automated. And also join our group in VK and telegrams !



All Articles