homebridge-smart-irrigation icon indicating copy to clipboard operation
homebridge-smart-irrigation copied to clipboard

[BUG] Not pulling sunrise data from API call, retrying every minute

Open jlg89 opened this issue 1 year ago • 3 comments

Describe the bug

The plugin is throwing a warning message to the log, seemingly whenever it hits the OpenWeatherMap API:

WARNING Error getting weather data or Cannot read properties of undefined (reading 'sunrise')

After the error, the plugin waits a minute and then retries, with the same result. So it's hitting the API every minute, which is probably going to cause it to exceed the OpenWeatherMap usage limits.

To Reproduce

Steps or config to reproduce the behaviour:

{
    "accessories": [
        {
            "accessory": "SmartSprinklers",
            "name": "Irrigation",
            "exposeControls": true,
            "recheckTime": "15",
            "latitude": ***,
            "longitude": ***,
            "altitude": 115,
            "keyAPI": "***",
            "cycles": 2,
            "sunriseOffset": 90,
            "lowThreshold": 5,
            "highThreshold": 10,
            "senderName": "***",
            "smtpPort": 587,
            "priorityPO": 0,
            "soundPO": "pushover",
            "pcWeatherCheckedSound": "system",
            "pcWateringStartSound": "system",
            "pcWateringEndSound": "jobDone",
            "JanRad": 3.06,
            "FebRad": 3.89,
            "MarRad": 4.82,
            "AprRad": 5.4,
            "MayRad": 5.91,
            "JunRad": 6.61,
            "JulRad": 6.77,
            "AugRad": 6.28,
            "SepRad": 5.24,
            "OctRad": 4.51,
            "NovRad": 3.34,
            "DecRad": 2.73,
            "zones": [
                {
                    "zoneName": "North",
                    "defDuration": 5,
                    "maxDuration": 20,
                    "rainThreshold": 6,
                    "tweakFactor": 100,
                    "dripLPH": 800,
                    "dripNos": 4,
                    "dripArea": 150,
                    "efficiency": 85,
                    "cropCoef": 0.5,
                    "plantDensity": 1,
                    "expFactor": 0.6,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Monday"
                    ],
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true
                },
                {
                    "zoneName": "West",
                    "defDuration": 5,
                    "maxDuration": 20,
                    "rainThreshold": 6,
                    "tweakFactor": 100,
                    "dripLPH": 800,
                    "dripNos": 4,
                    "dripArea": 90,
                    "efficiency": 85,
                    "cropCoef": 0.5,
                    "plantDensity": 1,
                    "expFactor": 0.5,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Tuesday"
                    ],
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true
                },
                {
                    "zoneName": "South",
                    "defDuration": 5,
                    "maxDuration": 20,
                    "rainThreshold": 6,
                    "tweakFactor": 100,
                    "dripLPH": 800,
                    "dripNos": 4,
                    "dripArea": 145,
                    "efficiency": 85,
                    "cropCoef": 0.5,
                    "plantDensity": 1,
                    "expFactor": 1,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Monday"
                    ],
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true
                },
                {
                    "zoneName": "East",
                    "defDuration": 5,
                    "maxDuration": 20,
                    "rainThreshold": 6,
                    "tweakFactor": 100,
                    "dripLPH": 800,
                    "dripNos": 4,
                    "dripArea": 80,
                    "efficiency": 85,
                    "cropCoef": 0.5,
                    "plantDensity": 1,
                    "expFactor": 0.9,
                    "wateringMonths": [
                        "Jan",
                        "Feb",
                        "Mar",
                        "Apr",
                        "May",
                        "Jun",
                        "Jul",
                        "Aug",
                        "Sep",
                        "Oct",
                        "Nov",
                        "Dec"
                    ],
                    "wateringWeekdays": [
                        "Tuesday"
                    ],
                    "enabled": true,
                    "adaptive": true,
                    "rainFactoring": true
                }
            ],
            "senderEmail": "***",
            "sendTo": "***",
            "smtpHost": "***",
            "portSecure": false,
            "userPwd": "***",
            "userID": "***",
            "emailEnable": true,
            "plugin_map": {
                "plugin_name": "homebridge-smart-irrigation"
            }
        }
    ]
}

Expected behavior

The plugin shouldn't be throwing this warning, or it should at least wait longer than a minute to hit the API again. I'm assuming that, if it can't determine when "sunrise" is, then the "sunriseOffset" feature probably won't work, and if it hits the API too often, the OpenWeatherMap server will cut off access.

**Screenshots or logs **

This is repeating every minute:

5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationlight rain on Sunday 5/7/2023 with 100% clouds & 76% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:4.96mm|Rain:1.4mm|Min:20.07°C|Max:28.05°C|Wind:8.89m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationlight rain on Monday 5/8/2023 with 94% clouds & 81% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:4.40mm|Rain:1.55mm|Min:19.59°C|Max:28.97°C|Wind:5.64m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationmoderate rain on Tuesday 5/9/2023 with 97% clouds & 71% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:5.04mm|Rain:7.95mm|Min:19.14°C|Max:27.65°C|Wind:6.21m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationmoderate rain on Wednesday 5/10/2023 with 87% clouds & 86% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:3.50mm|Rain:14.75mm|Min:18.18°C|Max:23.08°C|Wind:7.8m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationmoderate rain on Thursday 5/11/2023 with 100% clouds & 79% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:4.28mm|Rain:7.68mm|Min:18.48°C|Max:25.74°C|Wind:7.05m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationlight rain on Friday 5/12/2023 with 88% clouds & 72% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:4.72mm|Rain:4.3mm|Min:18.02°C|Max:28.35°C|Wind:4.34m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationlight rain on Saturday 5/13/2023 with 100% clouds & 72% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:5.07mm|Rain:2.87mm|Min:20.65°C|Max:28.48°C|Wind:5.68m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigation-----------------------------------------------------
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationlight rain on Sunday 5/14/2023 with 100% clouds & 66% RH
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationETo:5.38mm|Rain:2.74mm|Min:20.47°C|Max:27.7°C|Wind:5.54m/s
5/7/2023, 8:04:52 AMIrrigation BridgeIrrigationWARNINGError getting weather data or Cannot read properties of undefined (reading 'sunrise')

Platform (please complete the following information):

  • Platform: HOOBS 4.3.0, Homebridge 1.6.0, Node 16.20.0

jlg89 avatar May 07 '23 13:05 jlg89