Gå til innhold
  • Bli medlem
Støtt hjemmeautomasjon.no!

Anbefalte innlegg

Skrevet

Noen som kan hjelpe meg videre?  Ønsker å vise timesprisen på strømmen, gjerne i en graf slik som Tibber. Vil da ha prisene vist så langt fram som de er tilgjengelig. 

Dette er så langt jeg er kommet: 

Fått hentet inn priser fra Tibber, splittet de opp og leser da kun timesprisen for alle tilgjengelige timer. Alt bra så langt. Men hvordan kan jeg presentere dette i en graf som også viser prisene frem i tid? 

 

 

Skrevet

Nokså nybegynner i NodeRed jeg og men har funnet litt på nett. Kan dette være til noe hjelp?

 

[{"id":"7b554e4669b367f9","type":"ui_chart","z":"d49bfe3335c3f7c9","name":"","group":"188f564c824c87cd","order":1,"width":"8","height":"6","label":"kWh/h + pris (2d)","chartType":"line","legend":"true","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#00e68c","#2d2da8","#cc0000","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":930,"y":1400,"wires":[[]]},{"id":"078aa7c160ce1cd4","type":"function","z":"d49bfe3335c3f7c9","name":"Siste 2d","func":"var timeE = msg.payload;\n//Restrict the query to pull the last 24hrs\n//of data instead of the whole db\nvar d=new Date();\nd.setDate(d.getDate() - 2);\nvar aar=d.getFullYear();\nvar mnd=d.getMonth()+1; //Month er 0-11\nvar dag=d.getDate();\nvar tim=d.getHours();\n\nts = (aar*10000000000)+(mnd*100000000)+(dag*1000000)+(tim*10000);\n//msg.payload = (timeE - (1000*60*60*24));\nmsg.payload = ts;\n    node.status({text:msg.payload});\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1380,"wires":[["38c38a3dabaa53dc"]]},{"id":"38c38a3dabaa53dc","type":"template","z":"d49bfe3335c3f7c9","name":"Format query 1","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"SELECT DatoTid, kWh_hour, CurrentPrice, PID_SP FROM Energi WHERE Timestamp > {{payload}}","output":"str","x":500,"y":1400,"wires":[["0a3c6d550a427301"]]},{"id":"b6b43742bb23be7f","type":"change","z":"d49bfe3335c3f7c9","name":"Format data","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t  $series := [\t    { \"field\": \"DateTime\", \"label\": \"DatoTid\" },\t    { \"field\": \"kWh_hour\", \"label\": \"kWh\" },\t    { \"field\": \"CurrentPrice\", \"label\": \"Pris\" },\t    { \"field\": \"PID_SP\", \"label\": \"SP\" }\t  ];\t  $xaxis := \"DatoTid\";\t  [\t    {\t      \"series\": $series.label,\t      \"data\": $series.[\t        (\t          $yaxis := $.field;\t          $$.payload.{\t            \"x\": $lookup($, $xaxis),\t            \"y\": $lookup($, $yaxis)\t          }\t        )\t      ]\t    }\t  ]\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":1360,"wires":[["7b554e4669b367f9"]]},{"id":"324130bee0fc15b3","type":"Stackhero-MySQL","z":"d49bfe3335c3f7c9","server":"c919f77e07994edc","name":"","x":700,"y":1400,"wires":[["b6b43742bb23be7f"]]},{"id":"0a3c6d550a427301","type":"function","z":"d49bfe3335c3f7c9","name":"Add dummy payload","func":"msg.payload = \"Whatever\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":580,"y":1360,"wires":[["324130bee0fc15b3"]]},{"id":"188f564c824c87cd","type":"ui_group","name":"Chart","tab":"bbe9ae4be8e5f235","order":4,"disp":false,"width":"30","collapse":false,"className":""},{"id":"c919f77e07994edc","type":"Stackhero-MySQL-Server","name":"","host":"172.16.0.98","port":"3306","tls":false,"database":"NodeRedEnergi"},{"id":"bbe9ae4be8e5f235","type":"ui_tab","name":"Energi","icon":"receipt","order":2,"disabled":false,"hidden":false}]

 

image.png.80b8b6585cb7f963196e94b80a78a2f6.png

 

Det er nok "Format data" biten som er interressant. Jeg henter data fra SQL og presenterer grafisk slik, flowen her gir høyre del av grafen:

 

image.thumb.png.ac6f00da23d722314d999eca483fb5f1.png

 

Skrevet
[
    {
        "id": "7aa23003bb64f180",
        "type": "tab",
        "label": "Prisgraf",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b753794980e1f482",
        "type": "tibber-query",
        "z": "7aa23003bb64f180",
        "name": "",
        "active": true,
        "apiEndpointRef": "3bd7e7a52f99a463",
        "x": 710,
        "y": 200,
        "wires": [
            [
                "45a2c63548d8b018"
            ]
        ]
    },
    {
        "id": "597e9ec9d75635da",
        "type": "inject",
        "z": "7aa23003bb64f180",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "04b64236c28d833e"
            ]
        ]
    },
    {
        "id": "45a2c63548d8b018",
        "type": "debug",
        "z": "7aa23003bb64f180",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 910,
        "y": 200,
        "wires": []
    },
    {
        "id": "04b64236c28d833e",
        "type": "template",
        "z": "7aa23003bb64f180",
        "name": "current prices query",
        "field": "payload",
        "fieldType": "msg",
        "format": "text",
        "syntax": "plain",
        "template": "{\n  viewer {\n    homes {\n      currentSubscription {\n        priceInfo {\n          current {\n            total\n            energy\n            tax\n            startsAt\n            level\n          }\n          today {\n            total\n            energy\n            tax\n            startsAt\n            level\n          }\n          tomorrow {\n            total\n            energy\n            tax\n            startsAt\n            level\n          }\n         }\n      }\n    }\n  }\n}",
        "output": "str",
        "x": 480,
        "y": 200,
        "wires": [
            [
                "b753794980e1f482"
            ]
        ]
    },
    {
        "id": "3bd7e7a52f99a463",
        "type": "tibber-api-endpoint",
        "feedUrl": "wss://api.tibber.com/v1-beta/gql/subscriptions",
        "queryUrl": "https://api.tibber.com/v1-beta/gql",
        "name": ""
    }
]



Dette hadde nok hjulpet meg hvis jeg kunne litt mer om node red ser jeg. Er dette jeg er ute etter, men ikke hvordan jeg får satt det opp mot mitt system. Er det meningen at jeg bruker alle nodene du har i ditt oppsett eller skal jeg bare bruke den som heter "Format data"? Jeg må vel tilpasse function noden til mitt oppsett? 
Er på tynn is her merker jeg. 
 

2021-12-20-173109_1920x1080_scrot.png

Skrevet (endret)

Da har jeg bygget litt videre på løsningen til @oevensen og det er blitt seende slik ut:

image.thumb.png.4a0af8c6f6f709f5c4caa8016e6ea24e.png

Jeg har valgt å ha faste y-akse grenser fordi det gir et renere bildet av prisen, spesielt  viktig å ha fast 0-punkt. Max er 12 i dette tilfellet og det bør nå holde noen dager... Markeringen av inneværende time har enten verdien -1 eller 100 for å bevisst gå utenfor skalaen. Om en setter opp dynamisk skala bør disse verdiene endres. I bildet her "mangler" timen fra 23:00 til 23:59 så der er en liten quick and dirty fix for det i flowen nå...

 

image.png.3543b1e0498c689bddbc8aec27a8f82c.png

Timestamp injektoren oppdaterer i ny og ne og er vel egentlig helt unødvendig bortsett fra i den timen nye priser dukker opp (litt over kl 13) mens cron-plus trigger hvert timeskift.

 

 

[{"id":"c62340730470ca2c","type":"function","z":"7aa23003bb64f180","name":"","func":"var d = new Date();\nd.setDate(d.getDate());\nlet currHour = d.getHours();\n\n\nmsg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\",\"\"], \"data\": [[],[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today ){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total;\n  // Add \"Now\" marker\n  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour)\n    msg.payload[0].data[1][i] = 100;\n  else\n    msg.payload[0].data[1][i] = -1;\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[23].total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":120,"wires":[["b4e71d585aa269bc"]]},{"id":"b4e71d585aa269bc","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag","group":"f92abb1b.7c98d8","order":1,"width":"15","height":"10","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"12","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#73d216","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":850,"y":120,"wires":[[]]},{"id":"a6ace43237857ffb","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":490,"y":120,"wires":[["c62340730470ca2c"]]},{"id":"eaf8dbce27c1d3f5","type":"function","z":"7aa23003bb64f180","name":"","func":"msg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\"], \"data\": [[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].total;\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[23].total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":160,"wires":[["c59a5b5038bdf489"]]},{"id":"c59a5b5038bdf489","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen","group":"f92abb1b.7c98d8","order":2,"width":"15","height":"10","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"12","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":870,"y":160,"wires":[[]]},{"id":"f31f9d17a8603b23","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":490,"y":160,"wires":[["eaf8dbce27c1d3f5"]]},{"id":"f3e66847271be197","type":"change","z":"7aa23003bb64f180","name":"I dag","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          today {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"tod","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":120,"wires":[["a6ace43237857ffb"]]},{"id":"7d0b8eb209428eeb","type":"inject","z":"7aa23003bb64f180","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":110,"y":120,"wires":[["f3e66847271be197","025c7b81cb113a53"]]},{"id":"025c7b81cb113a53","type":"change","z":"7aa23003bb64f180","name":"I morgen","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          tomorrow {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"tom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":160,"wires":[["f31f9d17a8603b23"]]},{"id":"a4b2b795ecb5b85e","type":"cronplus","z":"7aa23003bb64f180","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":100,"y":160,"wires":[["f3e66847271be197","025c7b81cb113a53"]]},{"id":"f92abb1b.7c98d8","type":"ui_group","name":"Strømpris","tab":"69a5e334.ac1d1c","order":4,"disp":true,"width":"30","collapse":false,"className":""},{"id":"3235237809bb894f","type":"tibber-api-endpoint","feedUrl":"wss://api.tibber.com/v1-beta/gql/subscriptions","queryUrl":"https://api.tibber.com/v1-beta/gql","name":"Dale"},{"id":"69a5e334.ac1d1c","type":"ui_tab","name":"Hem","icon":"attach_money","order":1,"disabled":false,"hidden":false}]

 

Endret av SveinHa
Skrevet

Ser prisgrafen til TibberSeer har dynamisk skala og gir et annet bilde av prisutviklingen så jeg laget begge variantene i NodeRed for sammenligning:

bilde.thumb.png.8bfc78eb980b6f2b47dfea13eae0f889.png

 

bilde.thumb.png.14ffd5b6d37838ccb747ab6e8ac5fb5c.png

 

[{"id":"c62340730470ca2c","type":"function","z":"7aa23003bb64f180","name":"","func":"var d = new Date();\nd.setDate(d.getDate());\nlet currHour = d.getHours();\n\n\nmsg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\",\"\"], \"data\": [[],[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today ){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total;\n  // Add \"Now\" marker\n  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour)\n    msg.payload[0].data[1][i] = 100;\n  else\n    msg.payload[0].data[1][i] = -1;\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[23].total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":120,"wires":[["b4e71d585aa269bc"]]},{"id":"b4e71d585aa269bc","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag","group":"f92abb1b.7c98d8","order":3,"width":"15","height":"7","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"6","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#73d216","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1050,"y":120,"wires":[[]]},{"id":"a6ace43237857ffb","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":690,"y":120,"wires":[["c62340730470ca2c","0215a6e0c99061b7"]]},{"id":"eaf8dbce27c1d3f5","type":"function","z":"7aa23003bb64f180","name":"","func":"msg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\"], \"data\": [[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].total;\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[23].total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":220,"wires":[["c59a5b5038bdf489","7f3ff9455e7af2f8"]]},{"id":"c59a5b5038bdf489","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen","group":"f92abb1b.7c98d8","order":4,"width":"15","height":"7","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"6","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1070,"y":220,"wires":[[]]},{"id":"f31f9d17a8603b23","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":690,"y":220,"wires":[["eaf8dbce27c1d3f5"]]},{"id":"f3e66847271be197","type":"change","z":"7aa23003bb64f180","name":"I dag","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          today {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"tod","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":120,"wires":[["a6ace43237857ffb"]]},{"id":"025c7b81cb113a53","type":"change","z":"7aa23003bb64f180","name":"I morgen","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          tomorrow {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"tom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":220,"wires":[["f31f9d17a8603b23"]]},{"id":"a4b2b795ecb5b85e","type":"cronplus","z":"7aa23003bb64f180","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"date","payload":"","expressionType":"cron","expression":"0 0 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":100,"y":160,"wires":[["c92a61e1962e10a2"]]},{"id":"c92a61e1962e10a2","type":"delay","z":"7aa23003bb64f180","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":280,"y":140,"wires":[["f3e66847271be197","025c7b81cb113a53"]]},{"id":"0215a6e0c99061b7","type":"function","z":"7aa23003bb64f180","name":"","func":"var d = new Date();\nd.setDate(d.getDate());\nlet currHour = d.getHours();\n\n\nmsg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\",\"\"], \"data\": [[],[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today ){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total;\n  // Add \"Now\" marker\n/*  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour)\n    msg.payload[0].data[1][i] = 2;\n  else\n    msg.payload[0].data[1][i] = 0;*/\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[23].total;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":160,"wires":[["e2eb38f705911a33"]]},{"id":"e2eb38f705911a33","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag dyn y","group":"f92abb1b.7c98d8","order":1,"width":"15","height":"7","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#73d216","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1070,"y":160,"wires":[[]]},{"id":"7f3ff9455e7af2f8","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen dyn y","group":"f92abb1b.7c98d8","order":2,"width":"15","height":"7","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#3465a4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1080,"y":260,"wires":[[]]},{"id":"f92abb1b.7c98d8","type":"ui_group","name":"Strømpris","tab":"69a5e334.ac1d1c","order":4,"disp":true,"width":"30","collapse":false,"className":""},{"id":"3235237809bb894f","type":"tibber-api-endpoint","feedUrl":"wss://api.tibber.com/v1-beta/gql/subscriptions","queryUrl":"https://api.tibber.com/v1-beta/gql","name":"Dale"},{"id":"69a5e334.ac1d1c","type":"ui_tab","name":"Hem","icon":"attach_money","order":1,"disabled":false,"hidden":false}]

 

Skrevet
1 hour ago, SveinHa said:

Ser prisgrafen til TibberSeer har dynamisk skala

Jepp. Det ble nødvendig fordi prisene er så syke. Det er første gang på 3 år det har vært behov for det, men den går over til det vanlige når prisene blir mer normale. Det var direkte kjedelig å se på en tom graf...

Skrevet
Moskus skrev (1 minutt siden):

Det var direkte kjedelig å se på en tom graf...

Jepp, skjønner den. Det var ikke ment som kritikk, bare at jeg mener bildet blir litt misvisende slik TibberSeer viser det.

  • 7 måneder senere...
Skrevet (endret)

Har pynta litt på prisgrafen.

  • Morgendagen er borte helt til data er tilgjengelige i stedet for at dagens data ble liggende fra i går.
  • Pynta litt på time 23-00 slik at den blir like synlig som de andre timene.
  • Henter ut strømpris nå, neste time og dagssnitt som jeg viser i headingen på de fleste bilder.
  • Justert litt på timere. Morgendagens pris dukker ofte opp kl 13:00:00 men også ofte10-20 sekund senere. Andre ganger myyyye senere.
  • En enkel variabel for strømsparing: 0=pris lik eller lavere enn dagssnitt, 1=høyere enn dagssnitt og 2= 5% høyere enn dagssnitt. Enkelt å bruke for uprioriterte laster.

image.thumb.png.886659e03297d5585441b9a5f257294e.png

image.thumb.png.865fdc627880c69dce1c7382ed9fec42.png

 

[{"id":"c62340730470ca2c","type":"function","z":"7aa23003bb64f180","name":"","func":"var d = new Date();\nd.setDate(d.getDate());\nlet currHour = d.getHours();\nvar PrisSum = 0;\nvar n=0;\n\nmsg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nnode.warn(msg.topic);\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\",\"\"], \"data\": [[],[]], \"labels\": []}];\n\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today ){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total;\n  // Summer timeprisene\n  PrisSum += msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total\n  n +=1;\n  // Add \"Now\" marker og lagre prisdata\n  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour){\n    msg.payload[0].data[1][i] = 100;\n    flow.set(\"PrisNaa\",msg.payload[0].data[0][i]);}\n  else\n    msg.payload[0].data[1][i] = -1;\n  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour + 1)\n    flow.set(\"PrisNeste\",msg.payload[0].data[0][i]);\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13);\n}\n\n// Quick and dirty fix: legg til time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[23].total;\nmsg.payload[0].labels[24] = \"00\";\nmsg.payload[0].data[1][24] = -1;\n//msg.payload[0].data[1][0] = -1;\n\nflow.set(\"PriceAvg\", PrisSum/n);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":120,"wires":[["b4e71d585aa269bc"]]},{"id":"b4e71d585aa269bc","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag","group":"f92abb1b.7c98d8","order":3,"width":"14","height":"6","label":"I dag","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"8","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#73d216","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1050,"y":120,"wires":[["e98fe74987589f75","e90d64e507ffdc96","bd3a84f84ea86368","ff70c1508766dfca"]]},{"id":"a6ace43237857ffb","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":690,"y":120,"wires":[["c62340730470ca2c","0215a6e0c99061b7"]]},{"id":"eaf8dbce27c1d3f5","type":"function","z":"7aa23003bb64f180","name":"","func":"\nif (msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow != 0) {\n    msg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\n    msg.payloadorg = msg.payload;\n    msg.payload = [{\"series\":[\"Totals\"], \"data\": [[]], \"labels\": []}];\n    for ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow){\n        msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].total;\n        msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[i].startsAt.slice(11,13);\n    }\n// Quick and dirty fix: legg till time #24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.tomorrow[23].total;\nmsg.payload[0].labels[24] = \"00\";\n}\nelse{\n    msg.payload = [];   // Slett graf når data ikke er tilgjengelige\n    node.warn(\"Graf for i morgen slettet\")\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":220,"wires":[["c59a5b5038bdf489","7f3ff9455e7af2f8"]]},{"id":"c59a5b5038bdf489","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen","group":"f92abb1b.7c98d8","order":4,"width":"14","height":"6","label":"I morgen","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"8","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1070,"y":260,"wires":[[]]},{"id":"f31f9d17a8603b23","type":"tibber-query","z":"7aa23003bb64f180","name":"","active":true,"apiEndpointRef":"3235237809bb894f","x":690,"y":220,"wires":[["eaf8dbce27c1d3f5"]]},{"id":"f3e66847271be197","type":"change","z":"7aa23003bb64f180","name":"I dag","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          today {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"tod","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":120,"wires":[["a6ace43237857ffb"]]},{"id":"025c7b81cb113a53","type":"change","z":"7aa23003bb64f180","name":"I morgen","rules":[{"t":"set","p":"payload","pt":"msg","to":"{  viewer {    homes {      currentSubscription {        priceInfo {          tomorrow {            total            energy            tax            startsAt          }        }      }    }  }}","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Data ikke tilgjengelig enda...","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":220,"wires":[["f31f9d17a8603b23"]]},{"id":"a4b2b795ecb5b85e","type":"cronplus","z":"7aa23003bb64f180","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"date","payload":"","expressionType":"cron","expression":"0 0 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":100,"y":120,"wires":[["c92a61e1962e10a2"]]},{"id":"c92a61e1962e10a2","type":"delay","z":"7aa23003bb64f180","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":360,"y":120,"wires":[["f3e66847271be197","76c760b3b1d7016d"]]},{"id":"0215a6e0c99061b7","type":"function","z":"7aa23003bb64f180","name":"","func":"var d = new Date();\nd.setDate(d.getDate());\nlet currHour = d.getHours();\n\n\nmsg.topic = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today[0].startsAt.split(\":00+\")[0].split(\"T\")[0];\nmsg.payloadorg = msg.payload;\nmsg.payload = [{\"series\":[\"Totals\",\"\"], \"data\": [[],[]], \"labels\": []}];\nfor ( var i in msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today ){\n  msg.payload[0].data[0][i]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].total;\n  // Add \"Now\" marker\n/*  if (msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13) == currHour)\n    msg.payload[0].data[1][i] = 2;\n  else\n    msg.payload[0].data[1][i] = 0;*/\n  msg.payload[0].labels[i] = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[i].startsAt.slice(11,13);\n}\n// Quick and dirty fix: legg till time 24\nmsg.payload[0].data[0][24]  = msg.payloadorg.viewer.homes[0].currentSubscription.priceInfo.today[23].total;\nmsg.payload[0].labels[24] = \"00\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":80,"wires":[["e2eb38f705911a33"]]},{"id":"e2eb38f705911a33","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag dyn y","group":"f92abb1b.7c98d8","order":1,"width":"14","height":"6","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#73d216","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1070,"y":80,"wires":[[]]},{"id":"7f3ff9455e7af2f8","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen dyn y","group":"f92abb1b.7c98d8","order":2,"width":"14","height":"6","label":"{{msg.topic}}","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"","dot":true,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1080,"y":220,"wires":[[]]},{"id":"63a33d9e2d6e490f","type":"comment","z":"7aa23003bb64f180","name":"Prisgraf strøm","info":"","x":90,"y":80,"wires":[]},{"id":"a2a8866baa615d79","type":"inject","z":"7aa23003bb64f180","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"*/15 13-22 * * *","once":true,"onceDelay":0.1,"topic":"xx","payload":"","payloadType":"date","x":120,"y":220,"wires":[["025c7b81cb113a53"]]},{"id":"e98fe74987589f75","type":"change","z":"7aa23003bb64f180","name":"PrisNå","rules":[{"t":"set","p":"payload","pt":"msg","to":"PrisNaa","tot":"flow"},{"t":"set","p":"topic","pt":"msg","to":"Energi/PrisNaa","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":80,"wires":[["f06ca3bb6a70bc1f"]]},{"id":"f06ca3bb6a70bc1f","type":"mqtt out","z":"7aa23003bb64f180","name":"","topic":"","qos":"","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6db118ed1b0c56de","x":1450,"y":110,"wires":[]},{"id":"e90d64e507ffdc96","type":"change","z":"7aa23003bb64f180","name":"PrisNeste","rules":[{"t":"set","p":"payload","pt":"msg","to":"PrisNeste","tot":"flow"},{"t":"set","p":"topic","pt":"msg","to":"Energi/PrisNeste","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":110,"wires":[["f06ca3bb6a70bc1f"]]},{"id":"bd3a84f84ea86368","type":"change","z":"7aa23003bb64f180","name":"PrisAvg","rules":[{"t":"set","p":"payload","pt":"msg","to":"PriceAvg","tot":"flow"},{"t":"set","p":"topic","pt":"msg","to":"Energi/PrisSnitt","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":140,"wires":[["f06ca3bb6a70bc1f"]]},{"id":"ff70c1508766dfca","type":"function","z":"7aa23003bb64f180","name":"Sett global.reduserteffekt","func":"//Ved strømpris høyere enn dagens gjennomsnitt settes \"Redusert\"\n//Ved strø,pris større enn 5% over dagens gjennomsnitt settes \"Minimum\"\n\nPriceAvg = flow.get(\"PriceAvg\")||0;\nPriceNow = flow.get(\"PrisNaa\")||0;\n\nif ((PriceNow - PriceAvg) > (PriceNow * 0.05)){\n    global.set(\"reduserteffekt\", \"Minimum\");\n    global.set(\"reduserteffekt_value\", 2);\n    }\nelse if ((PriceNow - PriceAvg) > 0){\n    global.set(\"reduserteffekt\", \"Redusert\");\n    global.set(\"reduserteffekt_value\", 1);\n    }\nelse{\n    global.set(\"reduserteffekt\", \"Normal\");\n    global.set(\"reduserteffekt_value\", 0);\n    }\n    \nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1320,"y":170,"wires":[[]]},{"id":"76c760b3b1d7016d","type":"delay","z":"7aa23003bb64f180","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":360,"y":190,"wires":[["025c7b81cb113a53"]]},{"id":"f92abb1b.7c98d8","type":"ui_group","name":"Strømpris","tab":"69a5e334.ac1d1c","order":2,"disp":false,"width":"28","collapse":false,"className":""},{"id":"3235237809bb894f","type":"tibber-api-endpoint","feedUrl":"wss://api.tibber.com/v1-beta/gql/subscriptions","queryUrl":"https://api.tibber.com/v1-beta/gql","feedTimeout":"","name":"Dale"},{"id":"6db118ed1b0c56de","type":"mqtt-broker","name":"DaleMQTT","broker":"172.16.0.94","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"69a5e334.ac1d1c","type":"ui_tab","name":"Strømpris","icon":"attach_money","order":4,"disabled":false,"hidden":false}]

 

 

 

Endret av SveinHa
  • 3 måneder senere...
Skrevet (endret)

Pynta litt på prisgrafen min med tilleggsgrafer fra strompris.no

image.thumb.png.5beb95a1779b02e1953a1a0ada6fabb5.png

Jeg har valgt å manuelt skalere grafene ut fra dagens maxpris fordi da blir begge grafene likt skalert.

Gul er strømpris inkl nettleie og oransje er også inkl strømstøtte.

 

NodeRed flow for strompris.no:

image.thumb.png.b77c378eee1a7a59b7ff081b3a8cdb85.png

[{"id":"98a1f14badcc52d4","type":"inject","z":"7aa23003bb64f180","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":590,"wires":[["b75cb9337453b567"]]},{"id":"b75cb9337453b567","type":"http request","z":"7aa23003bb64f180","name":"Prisdata fra strompris.no","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://www.strompris.no/api/spotprice/dayprice","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"x":490,"y":570,"wires":[["5af895dfdebfa5f0","b6c7050f8421f228","1de4bfd3e92dce19"]]},{"id":"5c1057a587cd508c","type":"comment","z":"7aa23003bb64f180","name":"Alternative prisdata","info":"","x":100,"y":560,"wires":[]},{"id":"5862895d457e1a88","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i dag (strompris.no)","group":"f92abb1b.7c98d8","order":18,"width":14,"height":"9","label":"I dag (strompris.no)","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"wait","dot":false,"ymin":"-2","ymax":"6","removeOlder":"24","removeOlderPoints":"100","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#aec7e8","#ff7f0e","#f7f7f7","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1240,"y":530,"wires":[[]]},{"id":"5af895dfdebfa5f0","type":"function","z":"7aa23003bb64f180","name":"Prepare for alt. chart","func":"var d = new Date();\nd.setDate(d.getDate());\nvar currHour = d.getHours();\nvar weekDay = d.getDay()+1;\nvar pdt=0; //PrisDenneTime for kalkulasjoner\nvar sst = flow.get(\"sst\") || 0; //Strømstøtte\nvar nld = flow.get(\"nld\") ||0.51; //NettLeieDag 06-22\nvar nlnh = flow.get(\"nlnh\") || 0.41; //NettLeieNatt 22-06 + Helg\nvar priceHour = 0;\n//var priceHourTimestamp = new Date();\nvar msg2 = [[],[],[],[]];\nmsg2.payload = [{\"series\":[\"Råpris+nl\",\".\",\"Jonaspris\",\"0\"], \"data\": [[],[],[],[]], \"labels\": []}];\n\n//node.warn(msg.payload.today.hourly[0].NO2);\n\nif (msg.payload.today.hourly != null) {\n    //msg2.topic = msg.payload.today.hourly[0].Hours;\n    //node.warn(msg.payload);\n\n    for ( var i in msg.payload.today.hourly){\n        priceHour = msg.payload.today.hourly[i].Hours;\n        pdt = msg.payload.today.hourly[i].NO2;\n        \n        var priceHourTimestamp = new Date(2022,10,10,priceHour,0,0,0); //Spiller ingen rolle hvilken dato, bruker bare timen uansett\n        //node.warn(priceHourTimestamp + \" \" + pdt);\n    msg2.topic = priceHour;\n        //{topic:\"temperature\", payload:22}\n        //{topic:\"humidity\", payload:66}\n        //msg2.payload[0].data[0][i]  = {\"x\": Number(priceHourTimestamp), \"y\": pdt};\n        //msg2.payload[0].data[1][i] = {\"x\": Number(priceHour), \"y\": priceHour};\n        //msg2.payload[0].data[2][i]  = {\"x\": Number(priceHour), \"y\": 0};\n        //msg2.payload[0].data[3][i]  = {\"x\": Number(priceHourTimestamp), \"y\": 0};\n        //msg2.payload[0].labels[i] = priceHourTimestamp;\n    \n    //Beregn reel pris medregnet nettleie og strømstøtte\n    if ((priceHour > 6) && (priceHour <= 22) && weekDay < 6) {\n        msg2.payload[0].data[0][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nld).toFixed(2)};\n        msg2.payload[0].data[2][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nld).toFixed(2)};\n    //    node.warn(\"Dag: \" + priceHour + \" \" + msg.payload[0].data[2][i] + \"pdt: \" + pdt);\n    }\n    else{\n        msg2.payload[0].data[0][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nlnh).toFixed(2)};\n        msg2.payload[0].data[2][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nlnh).toFixed(2)};\n    //    node.warn(\"Natt: \" + priceHour + \" \" + msg.payload[0].data[2][i] + \"pdt: \" + pdt);\n    }\n      // Add \"Now\" marker og lagre prisdata\n    if (priceHour == currHour){\n        msg2.payload[0].data[1][i] = {\"x\": Number(priceHourTimestamp), \"y\": 3};\n    }\n    else{\n        msg2.payload[0].data[1][i] = {\"x\": Number(priceHourTimestamp), \"y\": 0};\n    }\n\n}\n\n\n// Quick and dirty fix: legg till time #24\npriceHourTimestamp = new Date(2022,10,10,24,0,0,0);\nmsg2.payload[0].data[0][24]  = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nlnh).toFixed(2)};\nmsg2.payload[0].data[2][24]  = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nlnh).toFixed(2)};\n//msg.payload[0].labels[24] = \"00\";\nmsg2.payload[0].data[1][24]  = {\"x\": Number(priceHourTimestamp), \"y\": 0};\n  \n}\nelse{\n    msg2.payload = [];   // Slett graf når data ikke er tilgjengelige\n    node.warn(\"Graf for i morgen slettet\")\n\n}\nmsg.payload = msg2.payload;\nnode.warn(msg.payload);\nreturn msg;    \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":530,"wires":[["5862895d457e1a88"]]},{"id":"70381f110be599d2","type":"inject","z":"7aa23003bb64f180","name":"Eksempeldata","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"today\":{\"average\":{\"NO1\":1.4548520833333332,\"NO2\":1.4713010416666668,\"NO3\":0.4447307291666666,\"NO4\":0.2162920833333333,\"NO5\":1.4548520833333332},\"hourly\":[{\"NO1\":1.1531,\"NO2\":1.1531,\"NO3\":0.41159999999999997,\"NO4\":0.22135,\"NO5\":1.1531,\"Hours\":\"0\"},{\"NO1\":1.2058,\"NO2\":1.2058,\"NO3\":0.3741875,\"NO4\":0.21378999999999998,\"NO5\":1.2058,\"Hours\":\"1\"},{\"NO1\":1.2313125,\"NO2\":1.2313125,\"NO3\":0.38712499999999994,\"NO4\":0.20902,\"NO5\":1.2313125,\"Hours\":\"2\"},{\"NO1\":1.2045124999999999,\"NO2\":1.2045124999999999,\"NO3\":0.4208,\"NO4\":0.20695,\"NO5\":1.2045124999999999,\"Hours\":\"3\"},{\"NO1\":1.2337624999999999,\"NO2\":1.2337624999999999,\"NO3\":0.43956249999999997,\"NO4\":0.20944,\"NO5\":1.2337624999999999,\"Hours\":\"4\"},{\"NO1\":1.3723125,\"NO2\":1.3723125,\"NO3\":0.5101375,\"NO4\":0.21514,\"NO5\":1.3723125,\"Hours\":\"5\"},{\"NO1\":1.5556375,\"NO2\":1.5556375,\"NO3\":0.5535,\"NO4\":0.22902,\"NO5\":1.5556375,\"Hours\":\"6\"},{\"NO1\":1.6693250000000002,\"NO2\":2.019425,\"NO3\":0.5159625,\"NO4\":0.24972999999999998,\"NO5\":1.6693250000000002,\"Hours\":\"7\"},{\"NO1\":1.7406625,\"NO2\":1.7853374999999998,\"NO3\":0.44177500000000003,\"NO4\":0.28257,\"NO5\":1.7406625,\"Hours\":\"8\"},{\"NO1\":1.6901625,\"NO2\":1.6901625,\"NO3\":0.4040875,\"NO4\":0.25926,\"NO5\":1.6901625,\"Hours\":\"9\"},{\"NO1\":1.6341,\"NO2\":1.6341,\"NO3\":0.38907499999999995,\"NO4\":0.24972999999999998,\"NO5\":1.6341,\"Hours\":\"10\"},{\"NO1\":1.4919375,\"NO2\":1.4919375,\"NO3\":0.39813750000000003,\"NO4\":0.23979,\"NO5\":1.4919375,\"Hours\":\"11\"},{\"NO1\":1.3544375,\"NO2\":1.3544375,\"NO3\":0.41237499999999994,\"NO4\":0.22021000000000002,\"NO5\":1.3544375,\"Hours\":\"12\"},{\"NO1\":1.26795,\"NO2\":1.26795,\"NO3\":0.43658749999999996,\"NO4\":0.22072999999999998,\"NO5\":1.26795,\"Hours\":\"13\"},{\"NO1\":1.3290625,\"NO2\":1.3290625,\"NO3\":0.43775000000000003,\"NO4\":0.21317,\"NO5\":1.3290625,\"Hours\":\"14\"},{\"NO1\":1.5034625,\"NO2\":1.5034625,\"NO3\":0.4573,\"NO4\":0.21565,\"NO5\":1.5034625,\"Hours\":\"15\"},{\"NO1\":1.6104125,\"NO2\":1.6104125,\"NO3\":0.48682499999999995,\"NO4\":0.21317,\"NO5\":1.6104125,\"Hours\":\"16\"},{\"NO1\":1.56095,\"NO2\":1.56095,\"NO3\":0.5022375,\"NO4\":0.20446999999999999,\"NO5\":1.56095,\"Hours\":\"17\"},{\"NO1\":1.5821874999999999,\"NO2\":1.5821874999999999,\"NO3\":0.528775,\"NO4\":0.19390000000000002,\"NO5\":1.5821874999999999,\"Hours\":\"18\"},{\"NO1\":1.599275,\"NO2\":1.599275,\"NO3\":0.5116875000000001,\"NO4\":0.18696000000000002,\"NO5\":1.599275,\"Hours\":\"19\"},{\"NO1\":1.566525,\"NO2\":1.566525,\"NO3\":0.45381249999999995,\"NO4\":0.18581999999999999,\"NO5\":1.566525,\"Hours\":\"20\"},{\"NO1\":1.6041999999999998,\"NO2\":1.6041999999999998,\"NO3\":0.42882499999999996,\"NO4\":0.18550999999999998,\"NO5\":1.6041999999999998,\"Hours\":\"21\"},{\"NO1\":1.4839125,\"NO2\":1.4839125,\"NO3\":0.4195,\"NO4\":0.18384999999999999,\"NO5\":1.4839125,\"Hours\":\"22\"},{\"NO1\":1.2714500000000002,\"NO2\":1.2714500000000002,\"NO3\":0.35191249999999996,\"NO4\":0.18178,\"NO5\":1.2714500000000002,\"Hours\":\"23\"}]},\"tomorrow\":{\"average\":{\"NO1\":1.289360416666667,\"NO2\":1.289360416666667,\"NO3\":0.3947151041666666,\"NO4\":0.18364291666666666,\"NO5\":1.289360416666667},\"hourly\":[{\"NO1\":1.1393125000000002,\"NO2\":1.1393125000000002,\"NO3\":0.3283,\"NO4\":0.18047,\"NO5\":1.1393125000000002,\"Hours\":\"0\"},{\"NO1\":1.1433125,\"NO2\":1.1433125,\"NO3\":0.252725,\"NO4\":0.18006,\"NO5\":1.1433125,\"Hours\":\"1\"},{\"NO1\":1.1393125000000002,\"NO2\":1.1393125000000002,\"NO3\":0.24987499999999999,\"NO4\":0.17984999999999998,\"NO5\":1.1393125000000002,\"Hours\":\"2\"},{\"NO1\":1.1375,\"NO2\":1.1375,\"NO3\":0.2563375,\"NO4\":0.17984999999999998,\"NO5\":1.1375,\"Hours\":\"3\"},{\"NO1\":1.1526125,\"NO2\":1.1526125,\"NO3\":0.2462625,\"NO4\":0.18016,\"NO5\":1.1526125,\"Hours\":\"4\"},{\"NO1\":1.2523624999999998,\"NO2\":1.2523624999999998,\"NO3\":0.2956125,\"NO4\":0.18056999999999998,\"NO5\":1.2523624999999998,\"Hours\":\"5\"},{\"NO1\":1.3335,\"NO2\":1.3335,\"NO3\":0.353375,\"NO4\":0.18078,\"NO5\":1.3335,\"Hours\":\"6\"},{\"NO1\":1.483375,\"NO2\":1.483375,\"NO3\":0.43437499999999996,\"NO4\":0.18243,\"NO5\":1.483375,\"Hours\":\"7\"},{\"NO1\":1.5264,\"NO2\":1.5264,\"NO3\":0.44187499999999996,\"NO4\":0.18356999999999998,\"NO5\":1.5264,\"Hours\":\"8\"},{\"NO1\":1.54475,\"NO2\":1.54475,\"NO3\":0.43761249999999996,\"NO4\":0.18419,\"NO5\":1.54475,\"Hours\":\"9\"},{\"NO1\":1.395,\"NO2\":1.395,\"NO3\":0.438775,\"NO4\":0.18512,\"NO5\":1.395,\"Hours\":\"10\"},{\"NO1\":1.3172249999999999,\"NO2\":1.3172249999999999,\"NO3\":0.43955,\"NO4\":0.18553,\"NO5\":1.3172249999999999,\"Hours\":\"11\"},{\"NO1\":1.2539125000000002,\"NO2\":1.2539125000000002,\"NO3\":0.4491125,\"NO4\":0.18584,\"NO5\":1.2539125000000002,\"Hours\":\"12\"},{\"NO1\":1.115275,\"NO2\":1.115275,\"NO3\":0.447175,\"NO4\":0.18594999999999998,\"NO5\":1.115275,\"Hours\":\"13\"},{\"NO1\":1.1564875000000001,\"NO2\":1.1564875000000001,\"NO3\":0.45039999999999997,\"NO4\":0.18625999999999998,\"NO5\":1.1564875000000001,\"Hours\":\"14\"},{\"NO1\":1.2064875000000002,\"NO2\":1.2064875000000002,\"NO3\":0.46267499999999995,\"NO4\":0.18584,\"NO5\":1.2064875000000002,\"Hours\":\"15\"},{\"NO1\":1.323675,\"NO2\":1.323675,\"NO3\":0.4655125,\"NO4\":0.18584,\"NO5\":1.323675,\"Hours\":\"16\"},{\"NO1\":1.35895,\"NO2\":1.35895,\"NO3\":0.447175,\"NO4\":0.18594999999999998,\"NO5\":1.35895,\"Hours\":\"17\"},{\"NO1\":1.47355,\"NO2\":1.47355,\"NO3\":0.45880000000000004,\"NO4\":0.18574000000000002,\"NO5\":1.47355,\"Hours\":\"18\"},{\"NO1\":1.5599874999999999,\"NO2\":1.5599874999999999,\"NO3\":0.45143749999999994,\"NO4\":0.18543,\"NO5\":1.5599874999999999,\"Hours\":\"19\"},{\"NO1\":1.3972000000000002,\"NO2\":1.3972000000000002,\"NO3\":0.44471249999999996,\"NO4\":0.18491,\"NO5\":1.3972000000000002,\"Hours\":\"20\"},{\"NO1\":1.279625,\"NO2\":1.279625,\"NO3\":0.439675,\"NO4\":0.18502000000000002,\"NO5\":1.279625,\"Hours\":\"21\"},{\"NO1\":1.1813,\"NO2\":1.1813,\"NO3\":0.42301250000000007,\"NO4\":0.18428999999999998,\"NO5\":1.1813,\"Hours\":\"22\"},{\"NO1\":1.0735375,\"NO2\":1.0735375,\"NO3\":0.3588,\"NO4\":0.18378,\"NO5\":1.0735375,\"Hours\":\"23\"}]}}","payloadType":"json","x":530,"y":520,"wires":[["5af895dfdebfa5f0","b6c7050f8421f228"]]},{"id":"08a94de73356bad5","type":"ui_chart","z":"7aa23003bb64f180","name":"elpriser i morgen (strompris.no)","group":"f92abb1b.7c98d8","order":19,"width":14,"height":"9","label":"I morgen (strompris.no)","chartType":"line","legend":"false","xformat":"HH","interpolate":"step","nodata":"Data ikke tilgjengelig før ca kl 14","dot":false,"ymin":"-2","ymax":"6","removeOlder":"24","removeOlderPoints":"100","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"useUTC":false,"colors":["#edd400","#aec7e8","#ff7f0e","#f7f7f7","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1250,"y":570,"wires":[[]]},{"id":"b6c7050f8421f228","type":"function","z":"7aa23003bb64f180","name":"Prepare for alt. chart","func":"var d = new Date();\nd.setDate(d.getDate());\nvar currHour = d.getHours();\nvar weekDay = d.getDay()+1;\nvar pdt=0; //PrisDenneTime for kalkulasjoner\nvar sst = flow.get(\"sst\") || 0; //Strømstøtte\nvar nld = flow.get(\"nld\") ||0.5; //NettLeieDag 06-22\nvar nlnh = flow.get(\"nlnh\") || 0.4; //NettLeieNatt 22-06 + Helg\nvar priceHour = 0;\n//var priceHourTimestamp = new Date();\nvar msg2 = [[],[],[],[]];\nmsg2.payload = [{\"series\":[\"Råpris+nl\",\".\",\"Jonaspris\",\"0\"], \"data\": [[],[],[],[]], \"labels\": []}];\n\n//node.warn(msg.payload.tomorrow.hourly[0].NO2);\n\nif (msg.payload.tomorrow.hourly != null) {\n    //msg2.topic = msg.payload.tomorrow.hourly[0].Hours;\n    //node.warn(msg.payload);\n\n    for ( var i in msg.payload.tomorrow.hourly){\n        priceHour = msg.payload.tomorrow.hourly[i].Hours;\n        pdt = msg.payload.tomorrow.hourly[i].NO2;\n        \n        var priceHourTimestamp = new Date(2022,10,10,priceHour,0,0,0); //Spiller ingen rolle hvilken dato, bruker bare timen uansett\n        //node.warn(priceHourTimestamp + \" \" + pdt);\n    msg2.topic = priceHour;\n        //{topic:\"temperature\", payload:22}\n        //{topic:\"humidity\", payload:66}\n        //msg2.payload[0].data[0][i]  = {\"x\": Number(priceHourTimestamp), \"y\": pdt};\n        //msg2.payload[0].data[1][i] = {\"x\": Number(priceHour), \"y\": priceHour};\n        //msg2.payload[0].data[2][i]  = {\"x\": Number(priceHour), \"y\": 0};\n        msg2.payload[0].data[1][i]  = {\"x\": Number(priceHourTimestamp), \"y\": 0};\n        //msg2.payload[0].labels[i] = priceHourTimestamp;\n    \n    //Beregn reel pris medregnet nettleie og strømstøtte\n    if ((priceHour > 6) && (priceHour <= 22) && weekDay < 6) {\n        msg2.payload[0].data[0][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nld).toFixed(2)};\n        msg2.payload[0].data[2][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nld).toFixed(2)};\n    //    node.warn(\"Dag: \" + priceHour + \" \" + msg.payload[0].data[2][i] + \"pdt: \" + pdt);\n    }\n    else{\n        msg2.payload[0].data[0][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nlnh).toFixed(2)};\n        msg2.payload[0].data[2][i] = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nlnh).toFixed(2)};\n    //    node.warn(\"Natt: \" + priceHour + \" \" + msg.payload[0].data[2][i] + \"pdt: \" + pdt);\n    }\n    \n}\n\n\n// Quick and dirty fix: legg till time #24\npriceHourTimestamp = new Date(2022,10,10,24,0,0,0);\nmsg2.payload[0].data[0][24]  = {\"x\": Number(priceHourTimestamp), \"y\": (pdt + nld).toFixed(2)};\nmsg2.payload[0].data[2][24]  = {\"x\": Number(priceHourTimestamp), \"y\": (pdt - sst + nlnh).toFixed(2)};\n//msg.payload[0].labels[24] = \"00\";\nmsg2.payload[0].data[1][24]  = {\"x\": Number(priceHourTimestamp), \"y\": 0};\n  \n}\nelse{\n    msg2.payload = [];   // Slett graf når data ikke er tilgjengelige\n    node.warn(\"Graf for i morgen slettet\")\n}\nmsg.payload = msg2.payload;\nnode.warn(msg.payload);\nreturn msg;    \n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":570,"wires":[["08a94de73356bad5"]]},{"id":"93cfa42f8c601b6d","type":"change","z":"7aa23003bb64f180","name":"ymax","rules":[{"t":"move","p":"payload","pt":"msg","to":"ui_control.ymax","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":760,"wires":[["5862895d457e1a88","08a94de73356bad5","6a1eeb159b2050c8","c59a5b5038bdf489"]]},{"id":"945313483ce5e841","type":"change","z":"7aa23003bb64f180","name":"ymin","rules":[{"t":"move","p":"payload","pt":"msg","to":"ui_control.ymin","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":790,"wires":[["08a94de73356bad5","5862895d457e1a88","c59a5b5038bdf489","6a1eeb159b2050c8"]]},{"id":"2b110e282046b94a","type":"switch","z":"7aa23003bb64f180","name":"Maxpris","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"6","vt":"num"},{"t":"btwn","v":"6","vt":"num","v2":"3","v2t":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":530,"y":660,"wires":[["ed7b449d13c78695","4fbac75657e85d88"],["7f45054b08d918ef","f6d9b45c4b01dbb8"],["ca958f076b9061c0","7c0ee7a1de5bc55e"]]},{"id":"ed7b449d13c78695","type":"change","z":"7aa23003bb64f180","name":"12","rules":[{"t":"set","p":"payload","pt":"msg","to":"12","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":710,"wires":[["93cfa42f8c601b6d"]]},{"id":"4fbac75657e85d88","type":"change","z":"7aa23003bb64f180","name":"-4","rules":[{"t":"set","p":"payload","pt":"msg","to":"-4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":740,"wires":[["945313483ce5e841"]]},{"id":"ca958f076b9061c0","type":"change","z":"7aa23003bb64f180","name":"3","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":850,"wires":[["93cfa42f8c601b6d"]]},{"id":"7c0ee7a1de5bc55e","type":"change","z":"7aa23003bb64f180","name":"-1","rules":[{"t":"set","p":"payload","pt":"msg","to":"-1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":880,"wires":[["945313483ce5e841"]]},{"id":"7f45054b08d918ef","type":"change","z":"7aa23003bb64f180","name":"6","rules":[{"t":"set","p":"payload","pt":"msg","to":"6","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":780,"wires":[["93cfa42f8c601b6d"]]},{"id":"f6d9b45c4b01dbb8","type":"change","z":"7aa23003bb64f180","name":"-2","rules":[{"t":"set","p":"payload","pt":"msg","to":"-2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":810,"wires":[["945313483ce5e841"]]},{"id":"a256c34817bfaad6","type":"comment","z":"7aa23003bb64f180","name":"Skalering prisgrafer","info":"","x":560,"y":610,"wires":[]},{"id":"1de4bfd3e92dce19","type":"debug","z":"7aa23003bb64f180","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":610,"wires":[]},{"id":"f92abb1b.7c98d8","type":"ui_group","name":"Strømpris","tab":"69a5e334.ac1d1c","order":2,"disp":false,"width":"28","collapse":false,"className":""},{"id":"69a5e334.ac1d1c","type":"ui_tab","name":"Strømpris","icon":"attach_money","order":5,"disabled":false,"hidden":false}]

Som vanlig ligger der igjen litt rot i funksjonsnodene men de virker nå like godt for det...

 

Edit: En liten bugfix for nettleie i flow...

Endret av SveinHa
  • Like 1

Bli med i samtalen

Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.

Gjest
Skriv svar til emnet...

×   Du har limt inn tekst med formatering.   Lim inn uten formatering i stedet

  Du kan kun bruke opp til 75 smilefjes.

×   Lenken din har blitt bygget inn på siden automatisk.   Vis som en ordinær lenke i stedet

×   Tidligere tekst har blitt gjenopprettet.   Tøm tekstverktøy

×   Du kan ikke lime inn bilder direkte. Last opp eller legg inn bilder fra URL.

×
×
  • Opprett ny...

Viktig informasjon

Vi har plassert informasjonskapsler/cookies på din enhet for å gjøre denne siden bedre. Du kan justere dine innstillinger for informasjonskapsler, ellers vil vi anta at dette er ok for deg.