Introduction

written by MOHAMAD HAMIDA Sami ,CZERNIEWSKI Blazej , PIROLA Rémy

Today, the energy management is one major challenge for the energy transition. Energy saving will be made through the advent of Smart-buildings capable of regulating, managing its consumption.
definition of key-word:

Energy management : the art of optimally compromising between quality of services and costs.
Energy smart buildings: technologies that support humans for energy management.

Smart building uses data and knowledge in order to optimize the comsuption in the building. It provides services in order to support energy management:
- Estimation of past present and future performances
- Determination of most relevant settings
- Suggestion of possible improvements

Project definition

In this project , our objective is to make a python scrip which will command , complete an interface software of energy management called Jeedom.

We will design a solution of energy management for the laboratory room.we have at our disposal :

- Raspberry PI 2 model B with SD Card, Z-Wave dongle and IP configuration.
- 12 pre-installed Aeotec Z-wave light bulbs controlled in intensity and in color.
- 12 Aeotec Z-wave multi-sensors with motion detectors, luminosity, temperature & humidity.
- 1 Z-wave switch.
- paper sheets to adjust motion detector selectivity.
Our goal is to propose a solution that will detect movement, presence of peaple in the room and will aitomatically open the light near the position.
the laboratory is decrib below

For this project we will use a home automation middleware called Jeedom. The Jeedom software is Open source.We have a total access to middleware which manages our home automation. This is a guarantee of transparency, but also longevity of the software and your installation.Jeedom does not require the access to outer waiters to work. All your installation manages in premises and thus you are the only ones to have access there to protect yourselves a complete confidentiality.Jeedom is compatible with various protocols as Z-Wave, RFXcom, RTS SOMFY, EnOcean, xPL. The system of plugins, via Market Jeedom, allows to guarantee a compatibility with current and future numerous protocols.

Componant definition

Raspberry pi is a computer with the size of a credit card that can be plugged into a screen and used as a standard computer. Its small size, and its attractive price makes Raspberry pi an ideal product to host that did not ask a lot of performance .In our case , after installing linux on it , we will install the energy management middleware Jeedom.
Z-Wave products can be used in a decentralized manner. (Uses of switch or a socket) or by a centralized gateway. Gateways enable access to the Z-Wave network to the outside world (internet, local area network). In our case, we got a z wave dongle that make the bridge between the raspberry pie which host the middleware Jeedom.
We have at our disposal , 12 lights and 12 sensors.
These multisensors allow us to sense the position, temperature, movement in a certain zone (circle). The range of the multi sensor can be reduced in order to optimize our strategy. With Zwave bulbs, we can control the luminosity and the color of the light These components are smart and communicate throught Z-wave.Z-wave is a protocol of communication wireless between electronic components. This protocol is mainly destined to home automation. Z-wave communications are relatively secure, double sense. Information, orders, request, are exchanged through this Zwave network. We have to pay attention on the environment of the laboratory. In fact, Walls curb, limit the propagation of Zwave in the air.Make the link between the Z-wave network and the local network of the lab is the role of the Zwave dongle. We will also have to install the Zwave plugin on jeedom in order to control Z-wave components.


Network

In order to make the communication between smart-component, Jeedom and the operator, we have to create a network between each device. The first step is to prepare the raspberry setup:
- Install Linux on the Rasberry - Connect it to the local network of the lab and to internet
- Download jeedom , all updates, library and plugins (Zwave) that we will need in order to use jeedom.
- Put the z-wave dongle in the raspberry

After this, we can use any other computer on the local network of the lab in order to go on Jeedom interface. We use google chrome on another computer in order to use Jeedom but the data that we sent through jeedom don’t use internet to go to the raspberry but just the local network of the lab. The request and answer between the rasberry and laboratory cumputer use http protocol , it is a webservice.

The second step is to connect Smart component to Jeedom and the raspberry. The connection between Zwave and classic network is done by the Zwave dongle and the z-wave plugin.

In order to connect Zwave bulb to jeedom :
In order to connect zwave bulb on jeedom, we follow the step on the notice provided with the light:
- We install the bulb on a electric grid.
- Put jeedom on “exclude all” (it deletes all system already connected on the middleware)
- Switch off the light.
- Put jeedom on inclution mode
- Switch off/on the light 5 times.

After connected all the light we test to change colors, luminosity : image lumiere couleur / screen jeedom avec tout les composant connecté In order to connect multisensory to jeedom:
- We put Jeedom in exclusion mode
- Put battery in multisensors
- Connect the multisensory with a usb2 wire in order to insure the alimentation during the connection.
- Put Jeedom in inclusion mode.
- Push the button of the multisensor.


The rooter allocated dynamic IP to all the componement of the network. The rooter manage all the IP of the component .The dhcp server in the rooter config the gateway in order to manage the IP od the network.It is preferable to put a Static IP for the raspberry for we configure the dhcp in order to put an IP that don’t change.

Control algorithme

To manage the lights, we have to determine a specific strategy. We follow this schema:

We put 4 sensors in each corner of the room, in the picture, each sensor is corresponding to one color. We can see the surface of detection for each component.
Our algorithm follows the following logic:
- If sensor blue is detecting a presence, L9 is switching on. If it doesn’t detect a presence, L9 is switching off.
- If sensor green is detecting a presence, L1 is switching on. If it doesn’t detect a presence, L1 is switching off.
- If sensor red is detecting a presence, L4 is switching on. If it doesn’t detect a presence, L4 is switching off.
- If sensor black is detecting a presence, L12 is switching on. If it doesn’t detect a presence, L12 is switching off.
- If sensors blue and green are detecting a presence, L8 is switching on. If they don’t detect a presence, L8 is switching off.
- If sensors red and green are detecting a presence, L2 and L3 are switching on. If they don’t detect a presence, L2 and L3 are switching off.
- If sensors red and black are detecting a presence, L5 is switching on. If they don’t detect a presence, L5 is switching off.
- If sensors black and blue are detecting a presence, L10 and L11 are switching on. If they don’t detect a presence, L10 and L11 are switching off.
- If all sensors are detecting a presence, L6 and L7 are switching on. If they don’t detect a presence, L6 and L7 are switching off.

These conditions are written with “if” conditions in Python. We are using “threads” to run them, actually, this choice allows us to run each condition independently to each other. They are running “alone”, in their own loop. This particularity allows to make a detection of movement for each sensor in real time. Without this solution, the code will run each instruction one by one, sequentially.
To send command to smart component and manage lamps, we use HTTP requests. It’s a simple solution to make communication between Python and SmartComponents, indeed, each command for each component is a simple line in HTTP format.

Our algorithm works like this:
- We create all thread that we need
- We switch-off all lamps to initialize our system and to synchronize it with matrix which is representing the state of our system
- We start all thread one by one
- All threads are working at the same time
- We display each 5 seconds the state of our system with the state matrix which is actualized in real time


In the command, the code is displaying these information:


You can find attached our code.

Though our solution is working, we can improve it. Our time of computation is high, we can reduce it by finding another way to manage thread. We can also try to improve our computation time by using a younger version of Raspberry Pi (we use version 2.0).We can try to complete our solution with other information like temperature to have a better detection, or try to determine the number of people in the room at each time. Here we are just detecting a movement.Maybe we can think about making a compromise between the comfort of people and the saving of energy (playing with the time of keeping the state 1 when a sensor detect a movement).

Problem met

In this Project we have met a lot of problem that cost us a lot of time.

Encountered issues:
- Communication

In order to simplify system configuration process we decided to connect the Raspberry Pi with a PC through the LAN. However, we met several issues with the connection between mentioned components which consumed much time to solve it.

- Configurations issues

During the configuration process we have met two issues. Firstly, we forgot to exclude all the devices from the Z-wave network which caused problems with demanded components inclusion. Secondly, during the include process, another group did that as well. It caused unsolvable problem. In that reason we were forced to restart the system and start to configure everything again.

- Sensor arrangement,

The issue related with the sensors is an operational range. The range of every sensor is almost as big as the room’s area. It was very hard to ration out particular area with using the sensors.

- Code optimisation,

Developed code allows to control the lightening in the room. However, delay between receiving the presence signal and turning on the LED is too long. It is necessary to optimize the code in order to solve it.

Script

#Importation of librairies
import urllib.request
import threading
import numpy as np
import time

#Declaration of variables
running = True
bulb_index = [i+1 for i in range(12)]
bulb_status = [0] * 13
state_lamp = np.zeros1)

1) 4,3),dtype='i');
state_multisensors=np.zeros((2,2),dtype='i');

#Lamp's definition
switch_on=['119','127','135','143','95','111','103','87','50','42','58','34']
switch_off =['120','128','136','144','96','112','104','88','51','43','59','35']

#Function's definition
def switch_on_lamp(lamp_number):
  lamp=switch_on[lamp_number-1]
  return urllib.request.urlopen("http://192.168.0.139/core/api/jeeApi.php?apikey=PLJ8tBtM8Ij6yJPIAinMiqhI4EW1lD9Spir0B3lgjvB1V1g6&type=cmd&id="+lamp)
def switch_off_lamp(lamp_number):
  lamp=switch_off[lamp_number-1]
  return urllib.request.urlopen("http://192.168.0.139/core/api/jeeApi.php?apikey=PLJ8tBtM8Ij6yJPIAinMiqhI4EW1lD9Spir0B3lgjvB1V1g6&type=cmd&id="+lamp)
def switch_off_all_lamp():
  for i in range (12):
      switch_off_lamp(i+1)
      print("Lamp "+str(i+1)+"off")
      time.sleep(0.5)
#Multisensor's definition
multisensor_presence=['71','148','153','158','163'] def get_presence(multisensor_number):
  multisensor=multisensor_presence[multisensor_number-1]
  ##print('start reading sensor value')
  status = int(urllib.request.urlopen("http://192.168.0.139/core/api/jeeApi.php?apikey=PLJ8tBtM8Ij6yJPIAinMiqhI4EW1lD9Spir0B3lgjvB1V1g6&type=cmd&id="+multisensor).read())
  return status
#State function
def print_state():
  while running==True:
      print("\n"*100)
      print("L1 L8 L9" +"        C02"+"  C01"+"\n"+str(state_lamp[0,0])+"  "+  str(state_lamp[0,1])+ "  "+ str(state_lamp[0,2])+"          "+str(state_multisensors[0,0])+"    "  +str(state_multisensors[0,1]))
      print("L2 L7 L10" +"       C03"+"  C04"+"\n"+str(state_lamp[1,0])+"  "+  str(state_lamp[1,1])+ "  "+ str(state_lamp[1,2])+"          "+str(state_multisensors[1,0])+"    "  +str(state_multisensors[1,1]))
      print("L3 L6 L11\n"+str(state_lamp[2,0])+"  "+str(state_lamp[2,1])+"  "+str(state_lamp[2,2]))
      print("L4 L5 L12\n"+str(state_lamp[3,0])+"  "+str(state_lamp[3,1])+"  "+str(state_lamp[3,2]))
      time.sleep(5)
#B
def Lamp_9():
  while running==True:
      ##print("ok9")
      if get_presence(1)==1:
          state_multisensors[0,1]=1;
          ##print("Etat capteur 1 :" + str(get_presence(1))+"\n")
          if bulb_status[9] != 1:
              switch_on_lamp(9)
          bulb_status[9] = 1
          state_lamp[0,2]=bulb_status[9]
          ##print("Lampe 9 allumée \n")
      else:
          state_multisensors[0,1]=0;
          #print("Etat capteur 1 :" + str(get_presence(1))+"\n")
          if bulb_status[9] != 0:
              switch_off_lamp(9)
          bulb_status[9] = 0
          state_lamp[0,2]=bulb_status[9]
          #print("Lampe 9 éteinte \n")
#G
def Lamp_1():
  while running==True:
      if int(get_presence(2))==1:
          state_multisensors[0,0]=1
          #print("Etat capteur 2 :" +str(get_presence(2))+"\n")
          if bulb_status[1] != 1:
              switch_on_lamp(1)
          bulb_status[1] = 1
          state_lamp[0,0]=bulb_status[1]
          #print("Lampe 1 allumée \n")
      else:
          state_multisensors[0,0]=0
          #print("Etat capteur 2 :" +str(get_presence(2))+"\n")
          if bulb_status[1] != 0:
              switch_off_lamp(1)
          bulb_status[1] = 0
          state_lamp[0,0]=bulb_status[1]
          #print("Lampe 1 éteinte \n")
#R
def Lamp_4():
  while running==True:
      if int(get_presence(3))==1:
          state_multisensors[1,0]=1
          #print("Etat capteur 3 " +str(get_presence(3))+"\n")
          if bulb_status[4] != 1:
              switch_on_lamp(4)
          bulb_status[4] = 1
          state_lamp[3,0]=bulb_status[4]
          #print("Lampe 4 allumée \n")
      else:
          state_multisensors[1,0]=0
          #print("Etat capteur 3 " +str(get_presence(3))+"\n")
          if bulb_status[4] != 0:
              switch_off_lamp(4)
          bulb_status[4] = 0
          state_lamp[3,0]=bulb_status[4]
          #print("Lampe 4 éteinte \n")
#BL
def Lamp_12():
  while running==True:
      if int(get_presence(4))==1:
          state_multisensors[1,1]=1
          #print("Etat capteur 4 :"+str(get_presence(4))+"\n")
          if bulb_status[12] != 1:
              switch_on_lamp(12)
          bulb_status[12] = 1
          state_lamp[3,2]=bulb_status[12]
          #print("Lampe 12 allumée \n")
      else:
          state_multisensors[1,1]=1
          #print("Etat capteur 4 :"+str(get_presence(4))+"\n")
          if bulb_status[12] != 0:
              switch_off_lamp(12)
          bulb_status[12] = 0
          state_lamp[3,2]=bulb_status[12]
          #print("Lampe 12 éteinte \n")
#Lamp8 is not working with Jeedom
def Lamp_8():
  while running==True:
      if int(get_presence(1))==1 & int(get_presence(2))==1:
          state_multisensors[0,1]=1
          state_multisensors[0,0]=1
          #print("Etat capteur 1 :"+str(get_presence(1))+"\n")
          #print("Etat capteur 2 :"+str(get_presence(2))+"\n")
          if bulb_status[8] != 1:
              switch_on_lamp(8)
          bulb_status[8] = 1
          state_lamp[0,1]=bulb_status[8]
          #print("Lampe 8 allumée \n")
      else:
          state_multisensors[0,1]=0
          state_multisensors[0,0]=0
          #print("Etat capteur 1 :"+str(get_presence(1))+"\n")
          #print("Etat capteur 2 :"+str(get_presence(2))+"\n")
          if bulb_status[8] != 0:
              switch_off_lamp(8)
          bulb_status[8] = 0
          state_lamp[0,1]=bulb_status[8]
          #print("Lampe 8 éteinte \n")
#G+R
def Lamp_2and3():
  while running==True:
      if int(get_presence(2))==1 & int(get_presence(3))==1:
          state_multisensors[0,0]=1
          state_multisensors[1,0]=1
          #print("Etat capteur 2 :"+str(get_presence(2))+"\n")
          #print("Etat capteur 3 :"+str(get_presence(3))+"\n")
          if bulb_status[2] != 1:
              switch_on_lamp(2)
          bulb_status[2] = 1
          state_lamp[1,0]=bulb_status[2]
          #print("Lampe 2 allumée \n")
          if bulb_status[3] != 1:
              switch_on_lamp(3)
          bulb_status[3] = 1
          state_lamp[2,0]=bulb_status[3]
          #print("Lampe 3 allumée \n")
      else:
          state_multisensors[0,0]=0
          state_multisensors[1,0]=0
          #print("Etat capteur 2 :"+str(get_presence(2))+"\n")
          #print("Etat capteur 3 :"+str(get_presence(3))+"\n")
          if bulb_status[2] != 0:
              switch_off_lamp(2)
          bulb_status[2] = 0
          state_lamp[1,0]=bulb_status[2]
          #print("Lampe 2 éteinte \n")
          if bulb_status[3] != 0:
              switch_off_lamp(3)
          bulb_status[3] = 0
          state_lamp[2,0]=bulb_status[3]
          #print("Lampe 3 éteinte \n")
def Lamp_5():
  while running==True:
      if int(get_presence(3))==1 & int(get_presence(4))==1:
          state_multisensors[1,1]=1
          state_multisensors[1,0]=1
          #print("Etat capteur 3 "+str(get_presence(3))+"\n")
          #print("Etat capteur 4 "+str(get_presence(4))+"\n")
          if bulb_status[5] != 1:
              switch_on_lamp(5)
          bulb_status[5] = 1
          state_lamp[3,1]=bulb_status[5]
          #print("Lampe 5 allumée \n")
      else:
          state_multisensors[1,1]=0
          state_multisensors[1,0]=0
          #print("Etat capteur 3 "+str(get_presence(3))+"\n")
          #print("Etat capteur 4 "+str(get_presence(4))+"\n")
          if bulb_status[5] != 0:
              switch_off_lamp(5)
          bulb_status[5] = 0
          state_lamp[3,1]=bulb_status[5]
          #print("Lampe 5 éteinte \n")
#BL+B
def Lamp_10and11():
  while running==True:
      if int(get_presence(1))==1 & int(get_presence(4))==1:
          state_multisensors[0,1]=1
          state_multisensors[1,1]=1
          #print("Etat capteur 1 :"+str(get_presence(1))+"\n")
          #print("Etat capteur 4 :"+str(get_presence(4))+"\n")
          if bulb_status[11] != 1:
              switch_on_lamp(11)
          bulb_status[11] = 1
          state_lamp[2,2]=bulb_status[11]
          #print("Lampe 11 allumée \n")
          if bulb_status[10] != 1:
              switch_on_lamp(10)
          bulb_status[10] = 1
          state_lamp[1,2]=bulb_status[10]
          #print("Lampe 10 allumée \n")
      else:
          state_multisensors[0,1]=0
          state_multisensors[1,1]=0
          #print("Etat capteur 1 :"+str(get_presence(1))+"\n")
          #print("Etat capteur 4 :"+str(get_presence(4))+"\n")
          if bulb_status[11] != 0:
              switch_off_lamp(11)
          bulb_status[11] = 0
          state_lamp[2,2]=bulb_status[11]
          #print("Lampe 11 éteinte \n")
          if bulb_status[10] != 0:
              switch_off_lamp(10)
          bulb_status[10] = 0
          state_lamp[1,2]=bulb_status[10]
          #print("Lampe 10 éteinte \n")
#G+B+R+BL
def Lamp_6and7():
  while running==True:
      if int(get_presence(2))==1 & int(get_presence(3))==1 & int(get_presence(4))==1 & int(get_presence(1))==1:
          state_multisensors[0,1]=1
          state_multisensors[1,1]=1
          state_multisensors[0,0]=1
          state_multisensors[1,0]=1
          #print("Etat capteur 2 "+str(get_presence(2))+"\n")
          #print("Etat capteur 3 "+str(get_presence(3))+"\n")
          #print("Etat capteur 4 "+str(get_presence(4))+"\n")
          #print("Etat capteur 1 "+str(get_presence(1))+"\n")
          if bulb_status[6] != 1:
              switch_on_lamp(6)
          bulb_status[6] = 1
          state_lamp[2,1]=bulb_status[6]
          #print("Lampe 6 allumée \n")
          if bulb_status[7] != 1:
              switch_on_lamp(7)
          bulb_status[7] = 1
          state_lamp[1,1]=bulb_status[7]
          #print("Lampe 7 allumée \n")
      else:
          state_multisensors[0,1]=0
          state_multisensors[1,1]=0
          state_multisensors[0,0]=0
          state_multisensors[1,0]=0
          ##print("Etat capteur 2 "+str(get_presence(2))+"\n")
          ##print("Etat capteur 3 "+str(get_presence(3))+"\n")
          ##print("Etat capteur 4 "+str(get_presence(4))+"\n")
          ##print("Etat capteur 1 "+str(get_presence(1))+"\n")
          if bulb_status[6] != 0:
              switch_off_lamp(6)
          bulb_status[6] = 0
          state_lamp[2,1]=bulb_status[6]
          ##print("Lampe 6 éteinte \n")
          if bulb_status[7] != 0:
              switch_off_lamp(7)
          bulb_status[7] = 0
          state_lamp[1,1]=bulb_status[7]
          #print("Lampe 7 éteinte \n")
#Algorythm

#thread creation
Lamp_9_thread = threading.Thread(target=Lamp_9)
Lamp_1_thread = threading.Thread(target=Lamp_1)
Lamp_4_thread = threading.Thread(target=Lamp_4)
Lamp_12_thread = threading.Thread(target=Lamp_12)
Lamp_8_thread = threading.Thread(target=Lamp_8)
Lamp_2and3_thread = threading.Thread(target=Lamp_2and3)
Lamp_5_thread = threading.Thread(target=Lamp_5)
Lamp_10and11_thread = threading.Thread(target=Lamp_10and11)
Lamp_6and7_thread = threading.Thread(target=Lamp_6and7)
print_state_thread = threading.Thread(target=print_state)

#switch_off all lamp
switch_off_all_lamp()
print(“All lamp are off”)
time.sleep(5)

#thread starting
Lamp_9_thread.start()
Lamp_1_thread.start()
Lamp_4_thread.start()
Lamp_12_thread.start()
Lamp_8_thread.start()
Lamp_2and3_thread.start()
Lamp_5_thread.start()
Lamp_10and11_thread.start()
Lamp_6and7_thread.start()
print_state_thread.start()
print(“All thread are working”)

QR Code
QR Code accueil:espaces:etudiants:etudiants:formation_initiale:module_ict_for_smart_grid:home_box_for_lighting_management (generated for current page)