The following Python script defines a simple absolute profile call ‘HeatingSetpointControl’. The profile could be used to maintain the temperature of a space 2 C above the outside air temperature.
1.import apache
2.
3.
4.class HeatingSetpointControl(apache.Profile):
5.
6. category = apache.Absolute
7.
8.def evaluate(self):
9.# outside air temp (C)
10. toa = self.context.weather.ta
11.
12.# heating setpoint is 2 degrees higher than outside air temp
13.#
14. val = toa + 2.0
15.
16.return val
17.
Line 4, defines the profile class, and as required, it is derived from the base class ‘Profile’. Line 6, is used to indicate that the profile is an Absolute profile. If no profile category is specified a scripted profile is assumed to be modulating. The evaluate method begins on line 8 and on line 10 it uses the context item to obtains the outside air temperature. The profile then determines its return value on line 14.
The use of contexts is demonstrated further in the following example. The scripted profile shown aims to control the opening of a window.
Return values from the evaluate routine are True and False. These will be automatically converted to 1 and 0 to fit with the current profile evaluation mechanism.
The profile checks 4 conditions that must be satisfies before the window can be opened.
1. It is not raining. [line 9]
The check uses the weather variable for relative humidity (%). When the relative humidity is greater than 95% it is assumed to be raining.
2. It is not too cold outside. [line 13]
When the outside air temperature is less than 10 C then the window should not be opened.
3. There is a need for cooling in the space. [line 16]
If the room temperature if less than 20 C then we don’t need to cool the space.
4. It is not an internal window. [line 21]
If there is a secondary room associated with the window, it is an internal window and should not be opened.
5. The window is opened to the full extent permitted by the MacroFlo opening type, when the room temperature is 5 C higher than the outside air temperature. [line 26].
1.import apache
2.
3.class WindowOpeningProfile(apache.Profile):
4.
5.def evaluate(self):
6.# windows closed if raining,
7.# relative humidity greater than 95%
8.# used as a measure of precipitation
9.if self.context.weather.rh >= 95:
10.return False
11.
12.# outside air temperature must be greater than 10 C
13.if self.context.weather.ta < 10:
14.return False
15.
16.# room air temperature must be greater than 20 C
17.if self.context.space.ta < 20:
18.return False
19.
20.# an internal window cannot be opened
21.if self.context.surface.adjacent_space:
22.return False
23.
24.# sufficient difference in temperature
25.# for a beneficial cooling effect, open the window