Trigger API according to the input

I'm building a weather dashboard and it has two options to get input. City/ Country name or Lattitude/ Longitude.
I want to update my dashboard every 30 seconds.
If City/ Country was given as input, I want to update the relevant OpenWeatherMap API every 30 seconds and get new data.
If Lattitude/ Longitude. was given as input, I want to update the relevant OpenWeatherMap API every 30 seconds and get new data.
The problem I'm facing is, that when I change the input type (ex: city/ county to lat/lon) in the middle, the program starts updating both APIs in 30-second intervals.

This is how my current flow looks

Combine the two into a trigger that sends "stop" then 50ms later sends latest msg object. follow that trigger with another trigger set to resend every x seconds, and reset if payload = "stop". then you would only require one openweather node.
e.g.

[{"id":"53d0947e.3a38e4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"brighton","payloadType":"str","x":130,"y":1380,"wires":[["e11d68b3.2fed58"]]},{"id":"e11d68b3.2fed58","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload = msg.payload + \"qwerty\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":1380,"wires":[["b3068fb3.5d7068"]]},{"id":"b3068fb3.5d7068","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"stop","op2":"","op1type":"str","op2type":"payl","duration":"50","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":490,"y":1420,"wires":[["14095796.cf6488"]]},{"id":"dd970f6d.bd2cd8","type":"function","z":"bf9e1e33.030598","name":"","func":"msg.payload = msg.payload + \"qwerty\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":1460,"wires":[["b3068fb3.5d7068"]]},{"id":"14095796.cf6488","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-5","extend":false,"overrideDelay":false,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":1420,"wires":[["8f20800d.7d01d8"]]},{"id":"75706316.d56be4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"lat/log","payloadType":"str","x":100,"y":1460,"wires":[["dd970f6d.bd2cd8"]]},{"id":"8f20800d.7d01d8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":1480,"wires":[]}]

Does the weather really change that fast ? Are there rate limits on hitting that API ?

This does not work as intended.
As long as I keep giving one type of input (say city/ country), it works. But, when I change the input type to (lat/ lon), the OpenWeather API keeps getting the last inputs from the previous input type.

[
    {
        "id": "b9a073da.96b51",
        "type": "ui_button",
        "z": "58e87bcc.806654",
        "name": "",
        "group": "4f271a00.762388",
        "order": 0,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Submit",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "",
        "topicType": "str",
        "x": 120,
        "y": 900,
        "wires": [
            [
                "3bff49e4.cede06"
            ]
        ]
    },
    {
        "id": "880489b6.8264e8",
        "type": "ui_button",
        "z": "58e87bcc.806654",
        "name": "",
        "group": "212c669d.fce9ba",
        "order": 4,
        "width": "6",
        "height": "1",
        "passthru": false,
        "label": "Submit",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "",
        "x": 120,
        "y": 1100,
        "wires": [
            [
                "e4190363.4d1d7"
            ]
        ]
    },
    {
        "id": "3bff49e4.cede06",
        "type": "function",
        "z": "58e87bcc.806654",
        "name": "",
        "func": "if(msg.payload){\n    return{\n        location : {\n            country : flow.get(\"country\"),\n            city : flow.get(\"city\")\n        }\n    }\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 240,
        "y": 840,
        "wires": [
            [
                "51c93547576fdd44"
            ]
        ]
    },
    {
        "id": "e4190363.4d1d7",
        "type": "function",
        "z": "58e87bcc.806654",
        "name": "",
        "func": "if(msg.payload){\n    return{\n        location : {\n            lat : flow.get(\"lat\"),\n            lon : flow.get(\"lon\")\n        }\n    }\n}\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 1100,
        "wires": [
            [
                "51c93547576fdd44"
            ]
        ]
    },
    {
        "id": "51c93547576fdd44",
        "type": "trigger",
        "z": "58e87bcc.806654",
        "name": "",
        "op1": "stop",
        "op2": "",
        "op1type": "str",
        "op2type": "payl",
        "duration": "50",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 210,
        "y": 980,
        "wires": [
            [
                "f5ac289be727292e"
            ]
        ]
    },
    {
        "id": "f5ac289be727292e",
        "type": "trigger",
        "z": "58e87bcc.806654",
        "name": "",
        "op1": "",
        "op2": "0",
        "op1type": "pay",
        "op2type": "str",
        "duration": "-15",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "stop",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 410,
        "y": 900,
        "wires": [
            [
                "f185e542.8805d8"
            ]
        ]
    },
    {
        "id": "f185e542.8805d8",
        "type": "openweathermap",
        "z": "58e87bcc.806654",
        "name": "",
        "wtype": "current",
        "lon": "",
        "lat": "",
        "city": "",
        "country": "",
        "language": "en",
        "credentials": {},
        "x": 650,
        "y": 900,
        "wires": [
            [
                "b40b4212.24744",
                "2a93c6c.1de5b3a",
                "f1e080e1.05dd7",
                "49e145d4.08f73c",
                "185166fe.2e4809",
                "b9e23bd0.ea7e08",
                "901e6ec.4740a9",
                "805abd3a.ac498",
                "dd02eca8.d6e4f",
                "8625b310c621b660",
                "11219d2e62e0dbf6",
                "9446411facaa23a2",
                "cc7905cae328210c"
            ]
        ]
    },
    {
        "id": "cc7905cae328210c",
        "type": "debug",
        "z": "58e87bcc.806654",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 700,
        "y": 780,
        "wires": []
    },
    {
        "id": "4f271a00.762388",
        "type": "ui_group",
        "name": "Input city/country",
        "tab": "152c952d.14cc0b",
        "order": 1,
        "disp": true,
        "width": "5",
        "collapse": false
    },
    {
        "id": "212c669d.fce9ba",
        "type": "ui_group",
        "name": "Input latitude/longitude",
        "tab": "152c952d.14cc0b",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "152c952d.14cc0b",
        "type": "ui_tab",
        "name": "Weather",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Then Use a switch and filter if has property city, and have two openweather nodes, or use a http request node and construct the http request
here is a http request example add you api key in the function node.

[{"id":"fef87284.5ebdd8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":820,"y":3600,"wires":[["3bff49e4.cede06"]]},{"id":"3bff49e4.cede06","type":"function","z":"bf9e1e33.030598","name":"","func":"if(msg.payload){\n    return{\n        location : {\n            country : \"United Kingdom\",\n            city : \"London\"\n        }\n    }\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":3600,"wires":[["51c93547576fdd44"]]},{"id":"51c93547576fdd44","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"stop","op2":"","op1type":"str","op2type":"payl","duration":"50","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":960,"y":3660,"wires":[["f5ac289be727292e"]]},{"id":"e4190363.4d1d7","type":"function","z":"bf9e1e33.030598","name":"","func":"if(msg.payload){\n    return{\n        location : {\n            lat : 44.34,\n            lon : 10.99\n        }\n    }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1010,"y":3780,"wires":[["51c93547576fdd44"]]},{"id":"f5ac289be727292e","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-15","extend":false,"overrideDelay":false,"units":"min","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":1170,"y":3660,"wires":[["67eab181.8c77c8"]]},{"id":"cdabaa2.2d25a58","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":850,"y":3780,"wires":[["e4190363.4d1d7"]]},{"id":"4b9a26d8.17852","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":900,"y":3540,"wires":[["f5ac289be727292e"]]},{"id":"67eab181.8c77c8","type":"function","z":"bf9e1e33.030598","name":"","func":"const apikey =\"add your api key\";\n\nif (msg.location.hasOwnProperty(\"city\")){\n    msg.url = `https://api.openweathermap.org/data/2.5/weather?q=${msg.location.city},${msg.location.country}&appid=${apikey}`\n} else {\n    msg.url = `https://api.openweathermap.org/data/2.5/weather?lat=${msg.location.lat}&lon=${msg.location.lon}&appid=${apikey}`\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1370,"y":3660,"wires":[["1ab9af65.c64731"]]},{"id":"1ab9af65.c64731","type":"http request","z":"bf9e1e33.030598","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1560,"y":3660,"wires":[["cc7905cae328210c"]]},{"id":"cc7905cae328210c","type":"debug","z":"bf9e1e33.030598","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1690,"y":3500,"wires":[]}]

The free call limit is -

60 calls/minute
1,000,000 calls/month

The weather does not change that fast, but this is a requirement of the project I'm working on.
The rate limits are not mentioned. I use the current weather data free version

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.