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

Anbefalte innlegg

Skrevet (endret)
Spoiler

[{"id":"e8b27adfc8ec718e","type":"subflow","name":"update-tab","info":"","category":"","in":[],"out":[{"x":1160,"y":130,"wires":[{"id":"025a6b3d0bfb3691","port":0}]}],"env":[{"name":"Active Tab","type":"str","value":"tab-name"},{"name":"Delay Time","type":"num","value":"10"},{"name":"Resend Payload","type":"str","value":"resend"}],"meta":{},"color":"#D8BFD8","icon":"node-red-contrib-chronos/chronos_repeat.svg","status":{"x":1160,"y":230,"wires":[{"id":"762e13d2891f1303","port":0}]}},{"id":"55eeaaf3e6733c20","type":"junction","z":"e8b27adfc8ec718e","x":440,"y":40,"wires":[["66b0ea96cbc08f0b"]]},{"id":"66b0ea96cbc08f0b","type":"junction","z":"e8b27adfc8ec718e","x":740,"y":40,"wires":[["4e37c3c8cfec0b7c"]]},{"id":"69cf0b4d38d5693f","type":"function","z":"e8b27adfc8ec718e","name":"update-tab","func":"// Function node code\nconst activeTabName = msg.name; // Active tab name from the incoming message\nconst resendPayload = env.get(\"Resend Payload\"); // Environment variable for the payload to resend\nconst delayTime = env.get(\"Delay Time\"); // Environment variable for the delay time in seconds\nconst activeTab = env.get(\"Active Tab\"); // Environment variable for the active tab name\n\n// Check if the message is a control signal to prevent infinite loops\nif (msg.controlSignal) {\n    return [null, msg, null]; // Only pass the message through to output 2 to continue the loop\n}\n\n// Initialize delay and rate messages\nlet delayMsg = {};\nlet rateMsg = {};\n\n// Determine if the active tab name matches the active tab environment variable\nif (activeTabName === activeTab) {\n    // If the current tab name is the active tab\n    delayMsg = { delay: delayTime * 1000, payload: resendPayload, controlSignal: true }; // Set delay time in milliseconds\n    rateMsg = { rate: (delayTime - 1) * 1000, controlSignal: true }; // Set rate time in milliseconds\n    return [{ payload: \"open\", topic: \"control\" }, [delayMsg], [rateMsg]]; // Send \"open\" message\n} else {\n    // If the current tab name is not the active tab\n    delayMsg = { reset: true, controlSignal: true }; // Reset the delay message\n    rateMsg = { reset: true, controlSignal: true }; // Reset the rate message\n    return [{ payload: \"close\", topic: \"control\" }, [delayMsg], [rateMsg]]; // Send \"close\" message\n}","outputs":3,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":130,"wires":[["21e47a40ce8098c1","4965b69dcf394aca"],["7198158a42995953","4965b69dcf394aca"],["55eeaaf3e6733c20"]]},{"id":"762e13d2891f1303","type":"function","z":"e8b27adfc8ec718e","name":"status","func":"// Retrieve the gate state from flow variable\nconst gateState = flow.get(\"gateState\") || \"unknown\";\n\n// Retrieve the active tab name from environment variables\nconst inputValueName = env.get(\"Active Tab\") || \"tab-name\";\n\n// Determine the color based on the gate state\nlet color = \"grey\"; // Default color for unknown state\nif (gateState === \"open\") {\n    color = \"green\";\n} else if (gateState === \"close\") {\n    color = \"red\";\n}\n\n// Combine gate state and active tab name in the text\nlet statusText = `${inputValueName}`;\n\n// Create status message with color and text\nmsg.payload = {\n    fill: color, // Set the background color\n    shape: \"ring\", // Shape of the status indicator\n    text: statusText // Display active tab name and gate state\n};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":230,"wires":[[]]},{"id":"a354ce26599ab0ae","type":"inject","z":"e8b27adfc8ec718e","name":"","props":[],"repeat":"1","crontab":"","once":false,"onceDelay":"1","topic":"","x":120,"y":230,"wires":[["762e13d2891f1303"]]},{"id":"ebb2ab61603bd8d1","type":"delay","z":"e8b27adfc8ec718e","name":"","pauseType":"queue","timeout":"5","timeoutUnits":"seconds","rate":"2","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":870,"y":130,"wires":[["025a6b3d0bfb3691"]]},{"id":"4e37c3c8cfec0b7c","type":"delay","z":"e8b27adfc8ec718e","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"9","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":true,"outputs":1,"x":860,"y":70,"wires":[["69cf0b4d38d5693f"]]},{"id":"7198158a42995953","type":"delay","z":"e8b27adfc8ec718e","name":"","pauseType":"delayv","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":500,"y":70,"wires":[["4e37c3c8cfec0b7c"]]},{"id":"4965b69dcf394aca","type":"change","z":"e8b27adfc8ec718e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":130,"wires":[["500ed83a330da6ae"]]},{"id":"21e47a40ce8098c1","type":"switch","z":"e8b27adfc8ec718e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"close","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":490,"y":170,"wires":[["965639c50ed6da8d"]]},{"id":"965639c50ed6da8d","type":"change","z":"e8b27adfc8ec718e","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":170,"wires":[["ebb2ab61603bd8d1","c8e3fe355d303fb7"]]},{"id":"500ed83a330da6ae","type":"switch","z":"e8b27adfc8ec718e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"istype","v":"undefined","vt":"undefined"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":130,"wires":[["ebb2ab61603bd8d1","c8e3fe355d303fb7"],[]]},{"id":"025a6b3d0bfb3691","type":"gate","z":"e8b27adfc8ec718e","name":"gate","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"default","x":1050,"y":130,"wires":[[]]},{"id":"02e0ccf6fe5fd0cc","type":"ui_ui_control","z":"e8b27adfc8ec718e","name":"","events":"change","x":110,"y":130,"wires":[["69cf0b4d38d5693f"]]},{"id":"c8e3fe355d303fb7","type":"switch","z":"e8b27adfc8ec718e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"open","vt":"str"},{"t":"eq","v":"close","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":170,"wires":[["ee2ae7161424dc47"],["ee2ae7161424dc47"]]},{"id":"ee2ae7161424dc47","type":"change","z":"e8b27adfc8ec718e","name":"","rules":[{"t":"set","p":"gateState","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":170,"wires":[[]]}]

 

Har laget ein subflow for å oppdatere data når eg åpner forskjellige "tabs" i Dashboard 🙂

 

Active Tab: Identifierer navnet på den aktive taben i Dashboard.
Delay Time: Definerer ventetiden før payload sendes på nytt i sekunder.
Resend Payload: Payload som sendes både når ein tab blir åpnet i Dashboard og deretter på nytt etter den angitte ventetiden.

 

Trenger noden "Simple Gate" https://flows.nodered.org/node/node-red-contrib-simple-gate for å virke.

 

Eksempel:

Du går inn på "Server"-taben i Dashboard, update-tab vil da sende "option_0" som trigger til ein multistate switch. Denne switchen henter deretter siste tilgjengelige data fra InfluxDB. Når "Server"-taben ikkje lenger er aktiv, vil ikkje systemet forespørre nye data fra InfluxDB. Dette reduserer unødvendig datahenting og belastning på databasen.

image.thumb.png.efd4bfaa278c92eaf8002e4a612c4543.png

 

image.thumb.png.eae1df8cc2715b024b6dbd79d805532b.png

 

Endret av hflatoey

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.