When to ventilate in summer

The goal is to determine if the ventilation is useful to decrease the temperature in a room in given time in summer.

The configuration parameters in the examples below can be changed in the configuration file config.ini that is described in section Configuration file.

"""When to ventilate in summer.
"""
from os.path import dirname, abspath, join
import sys
sys.path.append(abspath(join(dirname(__file__), '../..', '')))

from dm.ConnectionUtil import ConnectionUtil as cu
from dm.models.ModelsUtil import ModelsUtil
from dm.WundergroundCom import WundergroundCom
from dm.DateTimeUtil import DateTimeUtil


if __name__ == '__main__':
    cu.setup_logging()
    cls = cu.setup_clients()

    actual_time = int(DateTimeUtil.local_time_str_to_utc('2019/02/20 03:00:00').timestamp())
    lat = 49.1649894
    lon = 16.562262499999974

    w = WundergroundCom()
    w.api_key = cu.wunderground_api_key()

    devs = [
        {
            'db_column_name': 'temperature_in_celsius',
            'gateway_id': '1816820318180747',
            'device_id': '0xa900811026800001',
            'module_id': 0,
            'server_name': 'ant-work',
        },
        {
            'db_column_name': 'rh_in_percentage',
            'gateway_id': '1816820318180747',
            'device_id': '0xa900811026800001',
            'module_id': 1,
            'server_name': 'ant-work',
        }
    ]

    notification = ModelsUtil.when_ventilate_summer(devs, cls, lat, lon, actual_time, w, temperature_diff=4)
    ModelsUtil.json_to_file(notification, 'notification.doc.json', log_notification=True)

It is necessary to set clients that can communicate with a remote server using the function setup_clients. Current time is stored in the variable actual_time. Latitude and longitude that enable to get weather data according to a sensor position are stored in the variable lat and lon. The API key allows to get weather data and it is obtained by the function wunderground_api_key. The sensor used to gather data is stored in the variable devs. The determination if the ventilation is useful in current time is performed by the function when_ventilate_summer and the result is stored in the variable notification.

An output of the determination is a notification that contains basic information described in the section Notifications and the following information:

  • temp_in - indoor temperature,

  • temp_out - outside temperature,

  • type - what quantity is used for prediction,

  • ventilate - if the ventilation is useful,

  • 0 - ventilation is useless, the outside temperature is higher than the indoor temperature,

  • 1 - ventilation will be probably useless, the outside temperature is similar to indoor temperature,

  • 2 - ventilation is useful, the outside temperature is lower than the indoor temperature.

The example of a notification follows.

{
    "data": {
        "temp_in": 26.0,
        "temp_out": 3.0,
        "type": "when_ventilate_summer",
        "ventilate": 2
    },
    "device_id": "0xa900811026800001",
    "event": "env-notification-pre",
    "gateway_id": "1816820318180747",
    "raise": true,
    "raise_catch": false,
    "readable": "2019-02-20 03:00:00",
    "timestamp": 1550628000
}

The example of a command that can be used to determine if ventilation is useful to decrease the temperature in a room in the summer months is below.

python examples2/0303_when_to_ventilate/run.py