!Glare + Solar irradiance + Illuminance + Occupancy
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Program,
    Set_Shade_Control_State,     ! Name
    	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ELSE,		
			IF Daylighting_Reference_Point_1_Glare_Index > 22,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
   			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Solar Irradiance
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    	ELSE,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	ENDIF;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_Operative_Temperature > 25 || Zone_Operative_Temperature < 20.5,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,   
    	ENDIF ;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Illuminance + Solar_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
    IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    ELSE,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
    	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,     				
SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ENDIF,    
ENDIF ;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Illuminance + Solar_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
    IF Daylighting_Reference_Point_1_Illuminance < 500,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    	ELSE,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
    	ENDIF,    
    ENDIF ;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Occupancy
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    	ELSE,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	ENDIF; 

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Occupancy + Illuminance
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
    IF Zone_People_Occupant_Count == 0 ,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
    ELSE,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,     		
    	ELSE,
     		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ENDIF,    
    ENDIF ;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Occupancy + Solar irradiance
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Zone_People_Occupant_Count == 0 ,
    		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
     			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
     			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ENDIF,   
    	ENDIF ;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Occupancy + Solar irradiance + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
    IF Zone_People_Occupant_Count > 0 ,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ENDIF,
	ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Occupancy + Solar irradiance + Illuminance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
    IF Zone_People_Occupant_Count > 0 ,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ENDIF,
	ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
		IF Zone_Operative_Temperature > 25 || Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,  
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Illuminance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
		IF Zone_Operative_Temperature > 25 || Zone_Operative_Temperature < 20.5 ||,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Illuminance_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,  
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Illuminance_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Daylighting_Reference_Point_1_Illuminance < 500,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!OperativeTemperature + Illuminance + Occupancy_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
   			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!OperativeTemperature + Illuminance + Occupancy_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
   			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,	
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
		ELSE,	
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

!Operative temperature + Solar irradiance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
   		ENDIF,
   	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
			ENDIF,  
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    
			ENDIF,
		ENDIF,
    	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
 	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,     	
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
  			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ENDIF,  
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    	
		ENDIF,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
    IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
	IF Zone_Operative_Temperature > 25,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    	
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   	ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,  
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    	
		ENDIF,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,  
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
        SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
				ENDIF,
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   				ENDIF,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,			
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    					
        SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,				
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance + Occupancy_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ENDIF,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					IF Daylighting_Reference_Point_1_Illuminance < 500,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    				
            SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
					ENDIF,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,
			ENDIF,
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance + Occupancy_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
   			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,	
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Occupancy_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
		ELSE,	
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,   
   		ENDIF,
    	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
   		ENDIF,
   	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
			ENDIF,  
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    
			ENDIF,
		ENDIF,
    	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     ! Name
 	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off, 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,     	
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
  			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off , 
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
		ENDIF,  
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    	
		ENDIF,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State, 
    IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
	IF Zone_Operative_Temperature > 25,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    	
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   	ENDIF,
    ELSE,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ENDIF,  
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    	
		ENDIF,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,  
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    					
        SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
				ENDIF,
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   				ENDIF,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,			
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    					
        SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,				
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance + Occupancy_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ENDIF,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					IF Daylighting_Reference_Point_1_Illuminance < 500,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    				
            SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
					ENDIF,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,
			ENDIF,
		ENDIF,
   	ENDIF;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Operative temperature + Solar irradiance + Illuminance + Occupancy_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,
	IF Zone_People_Occupant_Count > 0,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ENDIF,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    				
            SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
					ENDIF,			
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,					
          ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
    		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,
			ENDIF,
		ENDIF,
   	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    IF Daylighting_Reference_Point_1_Glare_Index > 22,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    
    ELSE,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    IF Daylighting_Reference_Point_1_Glare_Index > 22,
	SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    
    ELSE,
	IF Daylighting_Reference_Point_1_Illuminance < 500, 
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ENDIF,
    ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Occupancy
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
    	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    
   		 ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500, 
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ENDIF,
		ENDIF,
    	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Occupancy + Operative temperature_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
        ENDIF,
		ELSE,
			IF Daylighting_Reference_Point_1_Glare_Index > 22,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
				ENDIF,
   			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Occupancy + Operative temperature_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
			ENDIF,
		ELSE,
			IF  Daylighting_Reference_Point_1_Glare_Index > 22,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
			ELSE,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,	
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
   				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Occupancy + Operative temperature_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Zone_Operative_Temperature > 25 ,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      				
        ELSE,
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance > 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Operative temperature_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Illuminance < 500,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	 	ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
    		ENDIF,
	ELSE,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,				
   			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Illuminance + Operative temperature_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Illuminance < 500,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
	ELSE,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,				
   			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Occupancy
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,    
   		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    		ENDIF,
	ELSE,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Occupancy + Operative temperature
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,				
   			ENDIF,
		ENDIF,
	ELSE,
		IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,			
      ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Glare_Index > 22,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,    
    	IF Daylighting_Reference_Point_1_Illuminance < 500,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,	
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    		ENDIF,
	ELSE,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,	
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Illuminance < 500,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
	ELSE,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,	
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Occupancy + Operative temperature
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ENDIF,
			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					IF Daylighting_Reference_Point_1_Illuminance > 500 && Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Occupancy + Operative temperature + User
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    SET OccupantOverriding = @RandomUniform 0 1,
    SET OccupantOverridingRound = @Round OccupantOverriding,

	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Illuminance < 500 && OccupantOverridingRound == 1, 
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
				IF Zone_Operative_Temperature > 25 ,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ENDIF,
			ELSE,
				IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
					IF Zone_Operative_Temperature < 20.5,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ELSE,
					IF Zone_Operative_Temperature > 25 && Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Operative temperature_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,		
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
   			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,		
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
   				ENDIF,
			ENDIF,
		ENDIF,	
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Operative temperature_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,		
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
   			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature > 25 || Zone_Operative_Temperature < 19,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,		
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
   				ENDIF,
			ENDIF,
		ENDIF,	
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Operative temperature_V03
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ELSE,
				IF Daylighting_Reference_Point_1_Illuminance < 500,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ELSE,
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,				
				ENDIF,
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Illuminance + Operative temperature_V04
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,      	
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   				ENDIF,
			ELSE,
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   				ENDIF,
			ENDIF,
		ENDIF,
    	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
			IF Zone_Operative_Temperature > 25,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,  
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
			ENDIF,
		ELSE,
			IF Daylighting_Reference_Point_1_Illuminance < 500,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On, 
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,    						
          SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off ,
				ENDIF,			
			ELSE,
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   				ENDIF,				
			ENDIF,
		ENDIF,
   	 ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Occupancy
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Zone_People_Occupant_Count > 0,
		IF Daylighting_Reference_Point_1_Glare_Index > 22,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    			ENDIF,
		ENDIF,
 	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
		ENDIF,
	ENDIF;
EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Occupancy + Operative temperature
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
	IF Zone_People_Occupant_Count > 0,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				IF Daylighting_Reference_Point_1_Glare_Index > 22,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					IF Daylighting_Reference_Point_1_Glare_Index > 22,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					ELSE,
						SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
						SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					ENDIF,
				ENDIF,
			ENDIF,
		ENDIF,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature > 25 ,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature < 20.5,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ENDIF,
			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Solar irradiance + Operative temperature
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Glare_Index > 22,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area > 150,
			IF Zone_Operative_Temperature < 20.5,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			ELSE,
				SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   			ENDIF,
		ELSE,
			IF Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area == 0,
				IF Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ENDIF,
			ELSE,
				IF Zone_Operative_Temperature < 20.5 || Zone_Operative_Temperature > 25,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
				ELSE,
					SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
					SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
    				ENDIF,
			ENDIF,
		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Operative temperature_V01
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Glare_Index > 22,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		IF Zone_Operative_Temperature < 20.5,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
   		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,	
    		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;

!Glare + Operative temperature_V02
Output:EnergyManagementSystem,
     Verbose,
     Verbose,
     Verbose;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Illuminance,
   Blocco1:Office,
   Daylighting Reference Point 1 Illuminance;

EnergyManagementSystem:Sensor,
   Daylighting_Reference_Point_1_Glare_Index,
   Blocco2:Office,
   Daylighting Reference Point 1 Glare Index;

EnergyManagementSystem:Sensor,
   Surface_Outside_Face_Incident_Solar_Radiation_Rate_per_Area,
   Blocco1:Office_Wall_2_0_0_0_0_0_Win,
   Surface Outside Face Incident Solar Radiation Rate per Area;

EnergyManagementSystem:Sensor,
   Zone_People_Occupant_Count,
   Blocco1:Office,
   Zone People Occupant Count;

EnergyManagementSystem:Sensor,
   Zone_Operative_Temperature,
   Blocco1:Office,
   Zone Operative Temperature;

EnergyManagementSystem:ProgramCallingManager,
   Window Shading Device EMS Controller,    ! Name
   BeginTimestepBeforePredictor , ! EnergyPlus Model Calling Point
   Set_Shade_Control_State ;         ! Program Name 

EnergyManagementSystem:Actuator,
    Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco1:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type

EnergyManagementSystem:Actuator,
    Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status,   ! Name
    Blocco2:Office_Wall_2_0_0_0_0_0_Win,    ! Component Name  Surface
name with shade controls
    Window Shading Control, ! Component Type
    Control Status;    ! Control Type
    
EnergyManagementSystem:Program,
    Set_Shade_Control_State,     
    	IF Daylighting_Reference_Point_1_Glare_Index > 22,
		SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
		SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
	ELSE,
		IF Zone_Operative_Temperature > 25,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Off,
   		ELSE,
			SET Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
			SET Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status = Shade_Status_Exterior_Blind_On,
    		ENDIF,
	ENDIF;

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status, ! Name
     Blocco1_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

EnergyManagementSystem:OutputVariable,
     Erl Shading Control Status 2, ! Name
     Blocco2_Office_Wall_2_0_0_0_0_0_Win_Shading_Deploy_Status, ! EMS Variable Name
     Averaged, ! Type of Data in Variable
     ZoneTimeStep ; ! Update Frequency

Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Hourly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, Monthly;
Output:Variable, *, Daylighting Reference Point 1 Daylight Illuminance Setpoint Exceeded Time, RunPeriod;

Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Timestep;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Hourly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, Monthly;
Output:Variable, *, Surface Outside Face Incident Solar Radiation Rate per Area, RunPeriod;

Output:Variable, *, Daylighting Reference Point 1 Illuminance, Timestep;
Output:Variable, *, Zone People Occupant Count, Timestep;

Output:Variable, *, Zone Air Temperature, Timestep;
Output:Variable, *, Zone Operative Temperature, Timestep;
Output:Variable, *, Daylighting Reference Point 1 Glare Index, Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status,
    Timestep;

  Output:Variable,
    *,
    Erl Shading Control Status 2,
    Timestep;

  EnergyManagementSystem:ProgramCallingManager,
    Init Window Shading Device Control Constants,    ! Name
    BeginNewEnvironment , ! EnergyPlus Model Calling Point
    InitializeShadeControlFlags ;         ! Program Name 1

   EnergyManagementSystem:GlobalVariable,    Shade_Status_None;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Off ;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Switchable_Dark;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Interior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Exterior_Blind_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Shade_On;
   EnergyManagementSystem:GlobalVariable,    Shade_Status_Between_Glass_Blind_On;

   EnergyManagementSystem:Program,
      InitializeShadeControlFlags,
      Set Shade_Status_None = 0.0 - 1.0,
            !   0: if shading device is off
      Set Shade_Status_Off = 0.0,
            !   1: if interior shade is on
      Set Shade_Status_Interior_Shade_On = 1.0,
            !   2: if glazing is switched to darker state
      Set Shade_Status_Switchable_Dark = 2.0,
            !   3: if exterior shade is on
      Set Shade_Status_Exterior_Shade_On = 3.0,
            !   6: if interior blind is on
      Set Shade_Status_Interior_Blind_On = 6.0,
            !   7: if exterior blind is on
      Set Shade_Status_Exterior_Blind_On = 7.0,
            !   8: if between-glass shade is on
      Set Shade_Status_Between_Glass_Shade_On = 8.0,
            !   9: if between-glass blind is on
      Set Shade_Status_Between_Glass_Blind_On = 9.0;
