dykandDK

HA - NR - Web request example

Nov 23rd, 2020 (edited)
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 5.81 KB | None | 0 0
  1. [
  2.     {
  3.         "id": "91d5c13c.e4d55",
  4.         "type": "tab",
  5.         "label": "Web request",
  6.         "disabled": false,
  7.         "info": "## Flow to retrieve data from website\n**By Anders Lukic**\n\n---\n\nFlow for retrieving data from Met.no API. \n\nRuns every hour to retrieve forecasted rain for the next hour in Copenhagen (using Latitude and \nLongitude).\n\nRemember to change Latitude and \nLongitude in the \"Set header\" node to retrieve date for your desired location.\n\nPlease refer to Met.no API documentation here:\nhttps://api.met.no/weatherapi/"
  8.     },
  9.     {
  10.         "id": "6d2f10bb.e4881",
  11.         "type": "inject",
  12.         "z": "91d5c13c.e4d55",
  13.         "name": "Run every hour",
  14.         "props": [
  15.             {
  16.                 "p": "payload"
  17.             }
  18.         ],
  19.         "repeat": "3600",
  20.         "crontab": "",
  21.         "once": true,
  22.         "onceDelay": "0.1",
  23.         "topic": "",
  24.         "payloadType": "date",
  25.         "x": 150,
  26.         "y": 100,
  27.         "wires": [
  28.             [
  29.                 "27c8b902.cf20a6"
  30.             ]
  31.         ]
  32.     },
  33.     {
  34.         "id": "34f89784.60b3f8",
  35.         "type": "http request",
  36.         "z": "91d5c13c.e4d55",
  37.         "name": "Met.no API request",
  38.         "method": "GET",
  39.         "ret": "txt",
  40.         "paytoqs": "query",
  41.         "url": "https://api.met.no/weatherapi/locationforecast/2.0/complete",
  42.         "tls": "",
  43.         "persist": false,
  44.         "proxy": "",
  45.         "authType": "",
  46.         "x": 510,
  47.         "y": 100,
  48.         "wires": [
  49.             [
  50.                 "e4d9037a.38784"
  51.             ]
  52.         ]
  53.     },
  54.     {
  55.         "id": "e4d9037a.38784",
  56.         "type": "json",
  57.         "z": "91d5c13c.e4d55",
  58.         "name": "To Array",
  59.         "property": "payload",
  60.         "action": "",
  61.         "pretty": true,
  62.         "x": 680,
  63.         "y": 100,
  64.         "wires": [
  65.             [
  66.                 "b05960f3.50e2b"
  67.             ]
  68.         ]
  69.     },
  70.     {
  71.         "id": "b05960f3.50e2b",
  72.         "type": "change",
  73.         "z": "91d5c13c.e4d55",
  74.         "name": "Get forecasted rain",
  75.         "rules": [
  76.             {
  77.                 "t": "set",
  78.                 "p": "forecasted_rain_next1hour",
  79.                 "pt": "msg",
  80.                 "to": "payload.properties.timeseries[0].data.next_1_hours.details.precipitation_amount",
  81.                 "tot": "msg"
  82.             }
  83.         ],
  84.         "action": "",
  85.         "property": "",
  86.         "from": "",
  87.         "to": "",
  88.         "reg": false,
  89.         "x": 850,
  90.         "y": 100,
  91.         "wires": [
  92.             [
  93.                 "fbbcaa31.fe3408",
  94.                 "b080bd18.c9d93",
  95.                 "24d3f959.8b4f36"
  96.             ]
  97.         ]
  98.     },
  99.     {
  100.         "id": "c793daa6.6a7ea8",
  101.         "type": "comment",
  102.         "z": "91d5c13c.e4d55",
  103.         "name": "Get forecasted rain for next hour",
  104.         "info": "",
  105.         "x": 170,
  106.         "y": 40,
  107.         "wires": []
  108.     },
  109.     {
  110.         "id": "fbbcaa31.fe3408",
  111.         "type": "debug",
  112.         "z": "91d5c13c.e4d55",
  113.         "name": "Full data",
  114.         "active": true,
  115.         "tosidebar": true,
  116.         "console": false,
  117.         "tostatus": false,
  118.         "complete": "payload",
  119.         "targetType": "msg",
  120.         "statusVal": "",
  121.         "statusType": "auto",
  122.         "x": 1020,
  123.         "y": 40,
  124.         "wires": []
  125.     },
  126.     {
  127.         "id": "27c8b902.cf20a6",
  128.         "type": "function",
  129.         "z": "91d5c13c.e4d55",
  130.         "name": "Set header",
  131.         "func": "msg.headers = {\n    \"Content-Type\": \"application/json\",\n    \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36\"\n}\nmsg.payload = { \"lat\": \"55.719437\", \"lon\": \"13.197304\"}\nreturn msg;",
  132.         "outputs": 1,
  133.         "noerr": 0,
  134.         "initialize": "",
  135.         "finalize": "",
  136.         "x": 330,
  137.         "y": 100,
  138.         "wires": [
  139.             [
  140.                 "34f89784.60b3f8"
  141.             ]
  142.         ]
  143.     },
  144.     {
  145.         "id": "b080bd18.c9d93",
  146.         "type": "debug",
  147.         "z": "91d5c13c.e4d55",
  148.         "name": "Forecasted rain",
  149.         "active": true,
  150.         "tosidebar": true,
  151.         "console": false,
  152.         "tostatus": false,
  153.         "complete": "forecasted_rain_next1hour",
  154.         "targetType": "msg",
  155.         "statusVal": "",
  156.         "statusType": "auto",
  157.         "x": 1040,
  158.         "y": 160,
  159.         "wires": []
  160.     },
  161.     {
  162.         "id": "24d3f959.8b4f36",
  163.         "type": "ha-entity",
  164.         "z": "91d5c13c.e4d55",
  165.         "name": "forecasted_rain_next1hour",
  166.         "server": "3bebce79.1e0962",
  167.         "version": 1,
  168.         "debugenabled": false,
  169.         "outputs": 1,
  170.         "entityType": "sensor",
  171.         "config": [
  172.             {
  173.                 "property": "name",
  174.                 "value": "forecasted_rain_next1hour"
  175.             },
  176.             {
  177.                 "property": "device_class",
  178.                 "value": ""
  179.             },
  180.             {
  181.                 "property": "icon",
  182.                 "value": "mdi:weather-rainy"
  183.             },
  184.             {
  185.                 "property": "unit_of_measurement",
  186.                 "value": "mm"
  187.             }
  188.         ],
  189.         "state": "forecasted_rain_next1hour",
  190.         "stateType": "msg",
  191.         "attributes": [],
  192.         "resend": true,
  193.         "outputLocation": "",
  194.         "outputLocationType": "none",
  195.         "inputOverride": "allow",
  196.         "x": 1080,
  197.         "y": 100,
  198.         "wires": [
  199.             []
  200.         ]
  201.     },
  202.     {
  203.         "id": "3bebce79.1e0962",
  204.         "type": "server",
  205.         "name": "Home Assistant",
  206.         "addon": true
  207.     }
  208. ]
Add Comment
Please, Sign In to add comment