1. Introduction
In recent years, the Internet of Things (IoT) has become an increasingly prominent tool for data collection and device interconnectivity, driving innovation across various industries—including agriculture and livestock farming [
1].
In precision livestock farming, particularly in dairy operations, IoT technology has proven to be fundamental, enabling more efficient monitoring systems, supporting informed decision-making, and optimizing farm [
2]. The adoption of devices such as sensors allows for the collection and access to real-time data on various parameters—from environmental conditions to animal health, welfare, reproduction, and productivity—promoting improvements in animal health and welfare, productivity gains, and a reduction in environmental [
3,
4].
These data play a vital role in optimizing farm management, enabling farmers to make informed, data-driven decisions. This approach enhances animal health and welfare, improves both reproductive and productive performance, and supports the overall sustainability of the system [
4,
5]. In this context, and particularly within dairy farming operations, it is essential to monitor the housing environment using sensors. The internal conditions of livestock facilities are influenced by their structural characteristics, which in turn affect variables such as temperature, humidity, and solar radiation. These factors have a direct impact on gas concentrations and the Temperature-Humidity Index (THI) [
6]. THI is an indicator that combines ambient temperature and relative humidity to provide a comprehensive measure of environmental heat load. It is widely used to assess heat stress in both humans and animals [
7,
8].
In the livestock sector, and especially in dairy production, the THI has emerged as a critical parameter. According to Neves et al. [
9], dairy cattle are particularly susceptible to heat stress due to the elevated metabolic rate required for milk production. Consequently, several researchers argue that heat stress in cattle is highly detrimental, underscoring the importance of environmental monitoring and the implementation of microclimate control strategies [
10]. The impact of heat stress, as measured by the Temperature-Humidity Index (THI), has been extensively studied, particularly regarding its adverse effects on production [
8,
10,
11], reproduction [
7,
8], and animal health [
2,
8]. Gernand et al. [
12] investigated the influence of heat stress on a variety of variables, linking THI to milk yield and quality, fertility, and overall animal health. Their findings revealed that beyond declines in production and fertility, cows exposed to thermal stress also showed increased susceptibility to certain health conditions, including mastitis, retained placenta, and postpartum disorders. Similarly, a study conducted by Liu et al. [
13] on dairy cattle concluded that increases in ambient temperature and humidity negatively affect both body temperature regulation and feed intake. In addition to heat stress, exposure to elevated levels of ammonia has also been linked to the development of health issues, primarily respiratory conditions, as air pollution compromises the animals’ respiratory systems. Previous research has shown associations between housing climate parameters—such as temperature and ammonia concentration—and increased mortality rates and the frequency of medical treatments [
2,
6]. As a result, the combination of impaired animal health and welfare, along with elevated THI and resulting heat stress, has also been associated with a rise in antibiotic usage [
2,
14]. The use of IoT technologies such as environmental monitoring sensors can therefore enable farm owners to anticipate and prevent issues related to heat stress, thereby lowering the incidence of associated health problems. These solutions help safeguard animal welfare and productivity, which in turn contributes to a reduction in the reliance on antibiotics [
14].
In this study, the aim was to demonstrate the benefit of implementing IoT sensors in the daily routine of a dairy farm, highlighting their contribution to a more efficient environmental management of the facilities, based on real-time data.
Despite the extensive literature on the impacts of heat stress on dairy farming, most studies focus on short periods or extreme weather events such as heat waves. In contrast, this work covers a complete annual cycle, making it possible to assess the seasonal and cumulative effects of thermal variations over time. This continuous temporal approach, applied to a region with a continental Mediterranean climate such as the Alentejo, represents a relevant contribution to a more realistic understanding of the challenges faced by dairy farms in environments with high climatic variability. In addition to the above, the integration of IoT sensors with the use of 7-day moving averages of the Temperature and Humidity Index (THI) is still little explored, as is the use of non-linear analyses of production variables, representing a relevant methodological gap.
The originality of this study, therefore, lies in the application of a combined and continuous approach to evaluate the effects of thermal variations on the productive performance of animals over the course of a year. The main indicators analyzed were total milk production, energy-corrected milk (ECM), somatic cell count (SCC), fat and protein content, and urea concentrations.
Thus, the specific objectives of this study were: (i) to continuously monitor the climatic conditions of the environment using IoT sensors; (ii) to assess seasonal fluctuations in THI and their relationship with variables associated with milk production and quality; and (iii) to characterize the impact of heat stress on the productive performance of dairy cows in a region with a hot, dry climate.
3. Results
Table 3 presents the descriptive statistics for dependent and independent variables during the one-year period of this trial. Values are presented for all variables (even those not included in the regression analysis).
Table 4 presents the multiple linear regression results for daily milk yield as the dependent variable. Linear regression slopes (Beta values) show a positive association between milk yield and DMI and linear THI, and a negative association with the quadratic term. The estimation of the inflection point indicated an increase in milk yield up to a 7-day THI value of 68.9, followed by a decline beyond this point.
Figure 5 presents regression scatter plots and fit lines for milk yield according to the model’s predictors, visually evidencing the non-linear relationship between 7-day THI and milk yield, and the fact that both lower and higher 7-day THI values are associated with lower milk yield values. The positive association between milk yield and DMI is also visually noticeable.
The results for multiple regression analysis for fat and protein content in milk are presented in
Table 5 and
Table 6, respectively.
The estimation of the inflection point for milk fat concentration indicated a decrease up to a 7-day THI value of 70.3, followed by an increase beyond this value. Regarding milk protein concentration, although the coefficient of the quadratic term was b2 = 0.000 (rounded), it was retained in the model due to its statistical significance and because its inclusion improved the adjusted R2 and reduced the standard error of the estimate.
Figure 6 and
Figure 7 present regression scatter plots and fit lines for fat and protein contents, respectively, according to the model’s predictors. The non-linear relationships between 7-day THI and fat and protein contents are visually subtle. There is a negative association between linear THI and both fat and protein content. Dry matter intake shows a positive relationship with fat content and a slightly negative one with protein content.
Figure 8 presents the average monthly values of milk yield (left) and fat and protein content (right) throughout the year.
Daily milk yield was higher in Spring months, with intermediate 7-day THI values and higher DM intakes. Fat content was higher in the Winter months (November to February). Protein content had its highest value in October and its lowest value in July. Both graphs show a coinciding peak in the 7-day THI value and the lowest DM intake in August.
Several regression models, computed to associate the variation in THI (daily, 2-day, 3-day and 7-day, with and without inclusion of the quadratic term) and somatic cell count (SCC), resulted in very low, though significant, adjusted regression coefficients (ranging between 0.034 and 0.041,
p values between 0.001 and 0.008).
Figure 9 presents a frequency histogram of daily bulk SCC values in this trial (valid N = 324). The vast majority (81.2%) of recorded values were under 200 cells/µL.
4. Discussion
The ombrothermic diagram for the 2024–2025 study period revealed consistently higher temperatures and reduced precipitation compared to the 1971–2000 climatological normal, reflecting the typical Mediterranean climate and posing challenges to dairy production due to increased thermal stress on animals. Climate change has intensified these effects, with rising global temperatures and more frequent extreme events like heatwaves, which negatively impact milk yield, reduce fat and protein content, and increase somatic cell count, ultimately affecting animal health and productivity [
26,
27]. Despite the adverse external environmental conditions, a notable and original finding of this study was the thermal stability maintained within the monitored facilities. This was achieved through the implementation of automated ventilation and sprinkler systems, which were activated based on internal THI values and maintained a favorable microclimate throughout the year (
Figure 4). These systems, shown to be effective in reducing heat stress, promote air circulation and evaporative cooling, helping to regulate cow body temperature and stabilize milk production [
28,
29].
Recently, Jannat and colleagues [
30] have published the results of air quality monitoring at a commercial dairy farm located in northern Colorado, between April and December 2023. These authors presented THI, CO
2, and NH
3 values measured at a tunnel-ventilated barn with an automated air quality sensor platform. THI values (55.30 ± 0.48) were considerably lower than in our study and less variable (63.79 ± 8.03), which may reflect surrounding environmental conditions and/or efficiency of the ventilation system. Nevertheless, CO
2 and NH
3 levels (642.70 ± 170.97 ppm and 6.66 ± 3.56 ppm, respectively) were consistently higher than those found in our trial (545.38 ± 52.93 ppm CO
2 and 0.31 ± 0.27 ppm NH
3). These results are probably associated with the number of animals present (6000 cows vs. approximately 600 cows in our trial) and different management practices, but can probably help to explain the negligible effects of CO
2 and NH
3 on our dependent variables, which led to their exclusion from the regression models.
In this trial, although no sharp variations in THI levels were recorded throughout the year, the results revealed a significant relationship between the 7-day moving average THI and daily milk production, as well as certain milk quality parameters. A 7-day moving average was used, as previous studies have shown that the effects of heat stress are not immediate but cumulative, requiring a dynamic assessment of thermal exposure. Li et al. [
31] demonstrated that production impacts may show a delay of 1 to 3 days, with effects persisting for up to a week. Likewise, Maggiolino et al. [
20] observed that the duration of heatwaves directly influences the magnitude of productive losses in dairy cows. A study conducted in dairy farms in Galicia (Spain) [
32] reported the estimated weighted value of the maximum THI derived from segmented regression up to 12 days prior to the test day, with peak R
2 values at the 7th day prior to testing for milk yield, fat, and protein percentage. Despite the apparently efficient indoor environmental control, our results seem to concur with this cumulative effect of THI over a 7-day period on milk yield, fat, and protein content.
Based on the formula described earlier to determine the THI, several studies, including those by Habeeb et al. [
33] and Ji et al. [
34], classify THI values as follows: values up to 74 are considered normal, 75–78 indicate an alert state, 79–83 represent danger, and values equal to or above 84 denote thermal emergency. Data obtained in this study showed that THI only occasionally exceeded the 74 threshold throughout the year, providing evidence for the effectiveness of the mitigation strategies implemented.
Nevertheless, even with average values generally below the classical threshold, multiple linear regression analysis revealed a non-linear relationship between the 7-day moving average THI and daily milk yield, with an estimated inflection point at THI = 68.9 (
Table 4), lower than commonly reported. Below this threshold, production tended to increase, followed by a progressive decline beyond that point. These results suggest that moderate levels of temperature and humidity may initially benefit productivity but become detrimental once the ideal range is surpassed. This pattern is consistent with the findings of M’Hamdi et al. [
35], where the highest milk yields in Holstein cows were observed for THI values between 68 and 72, with significant reductions above and below this range. These data reinforce, as observed in this trial, that milk production is sensitive to deviations from the optimal thermal range—not only to excessive heat—indicating a clearly non-linear response to the thermal environment.
Furthermore, the model identified dry matter intake (DMI) as the most influential predictor of milk yield, with the highest standardized coefficient (β = 0.668;
p < 0.001). This finding strengthens the hypothesis of an indirect mechanism, whereby heat stress reduces feed intake, which in turn compromises the energy supply required for milk synthesis. This relationship is supported by the literature and is considered one of the principal physiological mechanisms through which heat adversely affects productivity. Li et al. [
31] reported an approximate 19.5% reduction in DMI under high THI conditions, accompanied by a 33.7% decrease in milk production. Similarly, Rieger et al. [
24] identified a significant negative correlation between indoor THI and DMI, as well as a positive correlation between DMI and milk yield, highlighting the importance of this parameter. It should be noted that in this trial, although peak THI coincided with the lowest average DM intake in August, this was not the month with the lowest average milk yield (November). Although data concerning parity and phase of lactation of lactating cows in each month were not available, we can speculate that these factors can ultimately justify milk yield variation not explainable by our predictors.
Regarding milk quality, several studies have reported a continuous reduction in fat and protein content with increasing THI. In the study by Besteiro et al. [
32], a linear decrease in both fat and protein content was observed during the hottest months, coinciding with higher THI periods. As previously stated, these authors also reported a cumulative effect of THI on fat and protein content. Other authors [
27,
33] also report that heat stress compromises the synthesis of milk components—namely, fat and protein—due to metabolic and endocrine changes. Similar findings were reported by M’Hamdi et al. [
35] who demonstrated a continuous linear decline in both fat and protein in Holstein milk with increasing THI, with statistically significant reductions above the thermal comfort threshold (THI > 72).
The effects of heat stress on milk fat and protein content remain inconclusive, with studies reporting contradictory results—ranging from reductions to increases or no change. Some researchers suggest that rising THI may lead to higher fat percentages not due to increased secretion, but as a concentration effect caused by reduced milk volume under heat stress [
36,
37,
38,
39].
In the present study, a non-linear relationship was observed between THI and fat content, with an estimated inflection point at THI = 70.3. From this threshold onwards, a percentage increase in fat content was recorded, following a period of progressive decline. This pattern, although less frequently reported, may be explained by the same concentration effect described by Habimana et al. [
38] and Corazzin et al. [
39], although this contrasts with studies reporting only linear declines. These discrepancies may be related to differences in animal genotype, diet type, production levels, or management practices—factors highlighted as determinants of milk production and composition responses to heat stress [
38]. Moreover, it is essential to consider the modelling approach used to represent heat stress. While some studies use simple THI values [
27,
38], the present study employed a 7-day moving average with a quadratic term, enabling the detection of a non-linear quadratic relationship with an inflection point. This approach is more sensitive to cumulative and delayed effects, as demonstrated by Mbuthia et al. [
40], who observed different milk fat patterns depending on the model applied.
Regarding protein content, this study’s results revealed a negative and non-linear relationship between the 7-day moving average THI and milk protein content. The inclusion of a quadratic term in the regression model allowed for the detection of a slight curve in this response, although without a clear inflection point. This suggests that rising THI progressively compromises protein content, with a slower rate of decline at higher thermal levels. This methodological approach contrasts with previous studies that predominantly used linear models [
20,
38]. Nevertheless, trials such as that by Maggiolino et al. [
20] describe similar behaviors, reporting a significant and progressive reduction in protein with an increasing duration of heatwaves. Likewise, Habimana et al. [
38] and M’Hamdi et al. [
35] described a significant linear decrease in protein content when THI exceeded 72, as previously reported in review articles [
13].
In line with this, other authors [
31] observed a decrease in protein during summer (high THI period), associated with metabolic changes and increased oxidative stress. Our findings agree with an association of lower protein content in hotter months (April to August). These findings show that milk protein content is sensitive to heat stress and is likely influenced by a combination of factors, including reduced DMI, limited amino acid availability, and metabolic prioritization for thermoregulation. Nevertheless, in our trial, we found no association between reduced protein content and reduced DMI. The use of a quadratic model and a 7-day moving average proved particularly suitable for capturing the complexity of these responses, offering greater sensitivity than linear or point-based THI models.
Somatic cell count (SCC) is widely used as an indicator of udder health and milk quality and is highly sensitive to factors such as intramammary infections. Heat stress has been associated with a higher risk of subclinical mastitis, partly due to compromised immune function in cattle. Tao et al. [
11] observed a higher incidence of mastitis—and consequently, increased SCC—during the summer months. Similarly, Wankar et al. [
27] noted that mastitis incidence tends to rise in hot and humid environments, favoring pathogen proliferation. Similar findings were reported by Herbut et al. [
21] and Li et al. [
25], reinforcing the association between elevated THI values and SCC increases.
However, in this study, multiple regression models were calculated to associate THI variation with SCC, yielding relatively low adjusted R2 values, ranging from 0.034 to 0.041, although statistically significant (p between 0.001 and 0.008). These results indicate that although a clear association exists between THI and SCC, the thermal index explains only a small proportion of the observed variability. This may be due to the absence of very intense or prolonged thermal stress during this study, as well as the influence of variables not included in this analysis, such as stage of lactation and parity.
The present study was limited by the absence of individual animal data recorded daily. The lack of daily individual information prevented control for key factors such as lactation stage, parity, and health history, all of which are well known to influence milk production and quality. Furthermore, the restricted seasonal variation in THI limited the ability to assess the effects of extreme heat stress. Becker et al. [
36] point out that infection status is the primary factor contributing to SCC increases, although variables such as age (number of lactations) and lactation stage also play important roles. SCC tends to rise as cows age or progress through lactation. Consequently, several studies have included these effects in their statistical models [
12,
35,
36].
Furthermore, it is plausible that good management practices implemented on the farm—such as appropriate milking routines, proper bedding maintenance, early detection of clinical mastitis, discarding of infected milk, and effective health control—helped stabilize SCC values even during periods of higher thermal load. This can be inferred from the moderately low (under 20%) number of daily bulk SCC of 200,000 cells/mL or higher, regardless of parity, lactation stage, or yield, is generally considered for intervention level [
41].
Although this study focused mainly on environmental monitoring at the facility level, integration with individual sensor technologies represents a promising avenue for future work. Lamanna et al. [
42] and Cavallini et al. [
43] analyzed the application of smart collars and electronic earring devices, respectively, and observed that these systems allow for continuous, real-time monitoring of each animal’s behavior, health, and activity on an individual basis. These technologies have proved to be particularly advantageous, as they can record key animal health parameters such as rumination time, locomotion, lying time, and feeding behavior, providing relevant data on the response to heat stress, metabolic changes, and reproductive events. In this sense, integrating these data streams with environmental metrics such as THI could enable the development of more precise, individual-centered mitigation strategies, reinforcing the potential of digital environmental management applied to dairy production.
In contrast to many previous studies that focused exclusively on the influence of external climatic conditions, the present work provides new evidence of the effectiveness of internal microclimate control systems in maintaining thermal comfort and production stability in Mediterranean dairy environments. This represents a relevant contribution for farms operating under similar climatic conditions. While the findings are particularly applicable to Mediterranean settings, they may also offer valuable insights for other regions facing rising temperatures as a result of climate change. However, local adaptation is required, given the variability in local production practices, management systems, genetic backgrounds, and housing conditions across different production contexts.
5. Conclusions
This study integrated environmental data, obtained from sensors installed in dairy cattle facilities, with productive and milk quality indicators, with the aim of understanding the impact of heat stress in the context of a dairy farming operation. The results show that the temperature-humidity index (THI) has a significant impact on both milk production and composition, directly affecting fat and protein content. An inflection point was observed at THI = 68.9 for milk yield, with production decreasing beyond this value, while milk fat content increased slightly above THI = 70.3, possibly due to a concentration effect.
Despite the clear association between THI and the parameters evaluated in this trial, the observed relationships were non-linear. Some inconsistencies in relation to the existing literature highlight the need for a deeper understanding of the physiological interactions involved. Dry matter intake stands out as a central predictive variable, emphasizing the importance of considering nutritional factors when assessing productive performance under conditions of heat stress.
The results emphasize the importance of continuous environmental monitoring and the implementation of effective heat stress mitigation strategies in dairy production systems. Management decisions, such as improving ventilation and cooling systems or monitoring dry matter intake, can be guided by THI-based models.
However, this study was limited by the lack of individual animal data and the fact that it was conducted on a single farm in the Mediterranean region, so caution is recommended when extrapolating these results to different production systems or climates.
Future research should explore predictive models based on non-linear approaches, such as quadratic regressions, capable of capturing complex relationships between environmental and physiological variables. The use of indices such as the moving average THI, which is more sensitive to the cumulative effects of heat stress, has proved particularly suitable and should be considered in future studies. In addition, it would be valuable to examine these parameters across different climatic regions, as well as to conduct similar studies adapted to other breeds, both dairy and beef cattle, in order to assess the generalizability of the results and performance under varying production conditions.
Additionally, individual monitoring technologies, such as smart collars and electronic ear tags, have shown particular promise in providing real-time data on animal behavior, health, and activity. Integrating these technologies with environmental data can make digital management systems more precise and personalized, contributing to the resilience of farms in the face of climate change.