Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[
[
{
"id": "7dd09f58.f305e",
"type": "tab",
"label": "BART Display",
"disabled": false,
"info": ""
},
{
"id": "5f0b8ee.a89df7",
"type": "inject",
"z": "7dd09f58.f305e",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 145,
"y": 388,
"wires": [
[
"3bd05714.4f59b8"
]
]
},
{
"id": "c12c8546.cba2a8",
"type": "openweathermap in",
"z": "7dd09f58.f305e",
"name": "",
"wtype": "current",
"lon": "",
"lat": "",
"city": "Hayward, California",
"country": "United States",
"language": "en",
"x": 133,
"y": 466,
"wires": [
[
"998a93fd.f4833",
"6b34d75b.367358"
]
]
},
{
"id": "998a93fd.f4833",
"type": "debug",
"z": "7dd09f58.f305e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 1078,
"y": 401,
"wires": []
},
{
"id": "3bd05714.4f59b8",
"type": "openweathermap",
"z": "7dd09f58.f305e",
"name": "",
"wtype": "current",
"lon": "",
"lat": "",
"city": "Hayward, California",
"country": "United States",
"language": "en",
"x": 338,
"y": 388,
"wires": [
[
"6b34d75b.367358",
"998a93fd.f4833"
]
]
},
{
"id": "76ceb20d.075cfc",
"type": "mqtt out",
"z": "7dd09f58.f305e",
"name": "",
"topic": "",
"qos": "",
"retain": "false",
"broker": "b558af9.9ad0b5",
"x": 1091,
"y": 523,
"wires": []
},
{
"id": "6b34d75b.367358",
"type": "function",
"z": "7dd09f58.f305e",
"name": "Extract Values",
"func": "var varnamePrefix = msg.varname_prefix || '';\n\nvar messages = [];\nconst addMessage = (varname, value) => { \n messages.push({\n topic: `template-displays/bart/${varnamePrefix}${varname}`,\n payload: value\n });\n};\n\nconst convertTemp = (c) => {\n if (c > 200) {\n c -= 273.15;\n }\n return ((c*9/5)+32);\n}\n\nconst { \n temp_max,\n temp_min,\n temp\n} = msg.data.main;\nconst icon = msg.data.weather[0].icon;\nconst convertTime = (t) => {\n var then = new Date(t).getTime();\n \n if (then > new Date().getTime()/100) {\n return then/1000;\n } else {\n return then;\n }\n};\n\n// addMessage('test', msg.data);\naddMessage('forecast_high', convertTemp(temp_max));\naddMessage('forecast_low', convertTemp(temp_min));\naddMessage('forecast_temp', convertTemp(temp));\naddMessage('weather_icon', icon);\naddMessage('timestamp', convertTime(msg.data.dt));\n\nreturn [ messages ];",
"outputs": 1,
"noerr": 0,
"x": 894,
"y": 480,
"wires": [
[
"76ceb20d.075cfc",
"998a93fd.f4833"
]
]
},
{
"id": "c83e93b5.032c2",
"type": "openweathermap",
"z": "7dd09f58.f305e",
"name": "",
"wtype": "forecast",
"lon": "",
"lat": "",
"city": "Hayward, California",
"country": "United States",
"language": "en",
"x": 315,
"y": 316,
"wires": [
[
"986b1975.717578"
]
]
},
{
"id": "9fe35092.cc07b",
"type": "inject",
"z": "7dd09f58.f305e",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "3600",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 142,
"y": 317,
"wires": [
[
"c83e93b5.032c2"
]
]
},
{
"id": "986b1975.717578",
"type": "function",
"z": "7dd09f58.f305e",
"name": "Extract Daily Forecasts",
"func": "const FORECAST_INTERVAL = 3; // hours\nconst NUM_FORECASTS = 5;\n\nconst forecasts = msg.payload;\nconst todaysDate = (new Date()).getDate();\n\nvar messages = [];\n\nconst addMessage = (varname, forecast) => {\n messages.push({\n varname_prefix: varname,\n data: Object.assign({}, forecast, {dt:forecast.dt*1000})\n });\n};\n\nconst addForecast = (index, forecast) => {\n addMessage(`daily_weather_slot${index}_`, forecast);\n};\n\nmessages.push('timestamps', {data: forecasts.map(v => (v.dt))});\n\n// Find first datapoint that's from tomorrow and is after 12pm\nconst firstForecast = forecasts.findIndex(v => {\n const date = new Date(v.dt * 1000);\n return date != todaysDate && date.getHours() >= 12;\n});\n\nvar slotNum = 0;\n\nfor (var i = firstForecast; slotNum < NUM_FORECASTS; i += 24 / FORECAST_INTERVAL) {\n addForecast(slotNum++, forecasts[i] || forecasts[forecasts.length - 1]);\n}\n\nreturn [ messages ];",
"outputs": 1,
"noerr": 0,
"x": 611,
"y": 316,
"wires": [
[
"998a93fd.f4833",
"6b34d75b.367358"
]
]
},
{
"id": "6f1354c2.45cdec",
"type": "debug",
"z": "7dd09f58.f305e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"x": 716,
"y": 636,
"wires": []
},
{
"id": "4fa824b7.77d8ec",
"type": "json",
"z": "7dd09f58.f305e",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 340.5,
"y": 590,
"wires": [
[
"b9c26cb1.fc39a"
]
]
},
{
"id": "b9c26cb1.fc39a",
"type": "function",
"z": "7dd09f58.f305e",
"name": "Format, add timestamp",
"func": "return [\n [\n {\n topic: 'template-displays/bart/outside_temp',\n payload: msg.payload.temperature\n },\n {\n topic: 'template-displays/bart/outside_temp_updated_at',\n payload: (new Date()).getTime()/1000\n }\n ]\n];",
"outputs": 1,
"noerr": 0,
"x": 546,
"y": 591,
"wires": [
[
"6f1354c2.45cdec",
"76ceb20d.075cfc"
]
]
},
{
"id": "b8c4741d.2c1c18",
"type": "inject",
"z": "7dd09f58.f305e",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "30",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 139,
"y": 747,
"wires": [
[
"613131e.469e2d"
]
]
},
{
"id": "613131e.469e2d",
"type": "http request",
"z": "7dd09f58.f305e",
"name": "Get BART Times",
"method": "GET",
"ret": "obj",
"url": "http://my-barttimes-source/estimates.json",
"tls": "",
"x": 319,
"y": 750,
"wires": [
[
"6f1354c2.45cdec",
"539a7ece.a6e5a"
]
]
},
{
"id": "539a7ece.a6e5a",
"type": "function",
"z": "7dd09f58.f305e",
"name": "Format",
"func": "var topic = 'template-displays/bart/next_train';\nvar message;\n\nif (msg.payload.length === 0) {\n message = 'No trains';\n} else {\n const minutes = msg.payload[0].map(v => (\n `${v.minutes == 'Leaving' ? 0 : v.minutes}m`\n ));\n \n message = minutes.slice(0,2).join(', ');\n}\n\nreturn {\n topic: topic,\n payload: message\n};",
"outputs": 1,
"noerr": 0,
"x": 592,
"y": 754,
"wires": [
[
"76ceb20d.075cfc"
]
]
},
{
"id": "d3616bb3.5e5a58",
"type": "openweathermap in",
"z": "7dd09f58.f305e",
"name": "",
"wtype": "current",
"lon": "",
"lat": "",
"city": "San Francisco, California",
"country": "United States",
"language": "en",
"x": 134,
"y": 514,
"wires": [
[
"3f955b81.b9e9f4"
]
]
},
{
"id": "3f955b81.b9e9f4",
"type": "template",
"z": "7dd09f58.f305e",
"name": "add sf_ prefix",
"field": "varname_prefix",
"fieldType": "msg",
"format": "handlebars",
"syntax": "plain",
"template": "sf_",
"output": "str",
"x": 364,
"y": 507,
"wires": [
[
"6b34d75b.367358"
]
]
},
{
"id": "6fd00cf.bb4d5f4",
"type": "mqtt in",
"z": "7dd09f58.f305e",
"name": "",
"topic": "sensors/temp/outside",
"qos": "0",
"broker": "b558af9.9ad0b5",
"x": 137,
"y": 587,
"wires": [
[
"4fa824b7.77d8ec"
]
]
},
{
"id": "b558af9.9ad0b5",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "mymqtt",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"willTopic": "",
"willQos": "0",
"willPayload": "",
"birthTopic": "",
"birthQos": "0",
"birthPayload": ""
}
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.