Créer un appareil virtuel comme suit dans Gladys dans l’intégration MQTT
Avec les fonctionnalités suivantes
Importer ce flow dans node-red
Code du Flow
[
{
"id": "2b792c822e8e46f1",
"type": "tab",
"label": "TEMPO EDF",
"disabled": false,
"info": "",
"env": []
},
{
"id": "42d67acc049f7425",
"type": "group",
"z": "2b792c822e8e46f1",
"name": "TEMPO EDF",
"style": {
"stroke": "#000000",
"fill": "#bfdbef",
"label": true,
"label-position": "n",
"color": "#000000"
},
"nodes": [
"3d684dcab20a9914",
"3645d0bfbb46151e",
"967e5501fcd58cdd",
"71a73d70ed628528",
"e87b67de861c3256",
"50e0c479b04cb23c",
"418c3a4174d195aa",
"e89633a377e594b8",
"0de6bf94f39e7f8b"
],
"x": 74,
"y": 39,
"w": 1052,
"h": 262
},
{
"id": "02e46bae52d39d3b",
"type": "group",
"z": "2b792c822e8e46f1",
"name": "TEMPO EDF - Nb Jours Blanc Rouge Bleu",
"style": {
"stroke": "#000000",
"fill": "#bfdbef",
"label": true,
"label-position": "n",
"color": "#000000"
},
"nodes": [
"c930bd12d3f44d91",
"9c8bd280de70d67b",
"590aa4f85a232830",
"6d3c60cbfc8197ad",
"4c96ef17847a98b3",
"25f4c2d57f2b9c3d",
"341b7ddd6a3eb996",
"25b74b7de9880f61",
"6c60d01b69c8beda"
],
"x": 74,
"y": 319,
"w": 1052,
"h": 262
},
{
"id": "3d684dcab20a9914",
"type": "inject",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "01 13 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 80,
"wires": [
[
"3645d0bfbb46151e"
]
]
},
{
"id": "3645d0bfbb46151e",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Génére Date ",
"func": "const date = new Date();\n\nlet day = date.getDate();\nlet month = date.getMonth() + 1;\nlet year = date.getFullYear();\n\nlet currentDate = `${year}-${month}-${day}`;\n\nmsg.query = currentDate;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 190,
"y": 140,
"wires": [
[
"967e5501fcd58cdd"
]
]
},
{
"id": "967e5501fcd58cdd",
"type": "http request",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Couleur_TEMPO",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant={{{query}}}",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 210,
"y": 200,
"wires": [
[
"e87b67de861c3256",
"418c3a4174d195aa",
"e89633a377e594b8",
"0de6bf94f39e7f8b"
]
]
},
{
"id": "71a73d70ed628528",
"type": "debug",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "debug 2",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 140,
"wires": []
},
{
"id": "e87b67de861c3256",
"type": "debug",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 420,
"y": 80,
"wires": []
},
{
"id": "50e0c479b04cb23c",
"type": "mqtt out",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Broker Mqtt IP Gladys:1883",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f4ab211ed11dc81c",
"x": 980,
"y": 200,
"wires": []
},
{
"id": "418c3a4174d195aa",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Envoi TEMPO JOURJ1 => Gladys:DEMAIN ...",
"func": "var tempo = msg.payload.couleurJourJ1;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"DEMAIN\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt:\" TEMPO-EDF /feature/mqtt:\" JOUR /text\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/text\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nif (tempo === \"TEMPO_BLEU\") {\n msg.payload = \"TEMPO BLEU\";\n node.status({ fill: \"blue\", shape: \"ring\", text: tempo });\n}\nif (tempo === \"TEMPO_BLANC\") {\n msg.payload = \"TEMPO BLANC\";\n node.status({ fill: \"white\", shape: \"ring\", text: tempo });\n}\n\nif (tempo === \"TEMPO_ROUGE\") {\n msg.payload = \"TEMPO ROUGE\";\n node.status({ fill: \"red\", shape: \"ring\", text: tempo });\n}\n\nif (tempo === \"NON_DEFINI\") {\n msg.payload = \"NOM DEFINI\";\n node.status({ fill: \"grey\", shape: \"ring\", text: tempo });\n}\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 200,
"wires": [
[
"50e0c479b04cb23c",
"71a73d70ed628528"
]
]
},
{
"id": "e89633a377e594b8",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Envoi TEMPO JOURJ => Gladys:JOUR ....",
"func": "var tempo = msg.payload.couleurJourJ;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"JOUR\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt:\" TEMPO-EDF /feature/mqtt:\" JOUR /text\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/text\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nif (tempo === \"TEMPO_BLEU\") {\n msg.payload = \"TEMPO BLEU\";\n node.status({ fill: \"blue\", shape: \"ring\", text: tempo });\n}\nif (tempo === \"TEMPO_BLANC\") {\n msg.payload = \"TEMPO BLANC\";\n node.status({ fill: \"white\", shape: \"ring\", text: tempo });\n}\n \nif (tempo === \"TEMPO_ROUGE\") {\n msg.payload = \"TEMPO ROUGE\";\n node.status({ fill: \"red\", shape: \"ring\", text: tempo });\n}\n\nif (tempo === \"NON_DEFINI\") {\n msg.payload = \"NOM DEFINI\";\n node.status({ fill: \"grey\", shape: \"ring\", text: tempo });\n}\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 530,
"y": 140,
"wires": [
[
"50e0c479b04cb23c",
"71a73d70ed628528"
]
]
},
{
"id": "0de6bf94f39e7f8b",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "42d67acc049f7425",
"name": "Envoi TEMPO JOURJ => Gladys:TEMPO-EDF-COULEUR-1-2-3",
"func": "var tempo = msg.payload.couleurJourJ;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"COULEUR-1-2-3\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt: TEMPO-EDF /feature/mqtt: TEMPO-EDF-COULEUR-1-2-3/state\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/state\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nif (tempo === \"TEMPO_BLEU\") {\n msg.payload = 1;\n node.status({ fill: \"blue\", shape: \"ring\", text: tempo });\n}\nif (tempo === \"TEMPO_BLANC\") {\n msg.payload = 2;\n node.status({ fill: \"white\", shape: \"ring\", text: tempo });\n}\n\nif (tempo === \"TEMPO_ROUGE\") {\n msg.payload = 3;\n node.status({ fill: \"red\", shape: \"ring\", text: tempo });\n}\n\nif (tempo === \"NON_DEFINI\") {\n msg.payload = 4;\n node.status({ fill: \"grey\", shape: \"ring\", text: tempo });\n}\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 260,
"wires": [
[
"50e0c479b04cb23c",
"71a73d70ed628528"
]
]
},
{
"id": "c930bd12d3f44d91",
"type": "inject",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "01 13 * * *",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 360,
"wires": [
[
"9c8bd280de70d67b"
]
]
},
{
"id": "9c8bd280de70d67b",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Génére Date ",
"func": "const date = new Date();\n\nlet day = date.getDate();\nlet month = date.getMonth() + 1;\nlet year = date.getFullYear();\n\nlet currentDate = `${year}-${month}-${day}`;\n\nmsg.query = currentDate;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 190,
"y": 420,
"wires": [
[
"590aa4f85a232830"
]
]
},
{
"id": "590aa4f85a232830",
"type": "http request",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Couleur_TEMPO",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://particulier.edf.fr/services/rest/referentiel/getNbTempoDays?TypeAlerte=TEMPO",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 210,
"y": 480,
"wires": [
[
"4c96ef17847a98b3",
"341b7ddd6a3eb996",
"25b74b7de9880f61",
"6c60d01b69c8beda"
]
]
},
{
"id": "6d3c60cbfc8197ad",
"type": "debug",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "debug 14",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 420,
"wires": []
},
{
"id": "4c96ef17847a98b3",
"type": "debug",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "debug 15",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 420,
"y": 360,
"wires": []
},
{
"id": "25f4c2d57f2b9c3d",
"type": "mqtt out",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Broker Mqtt IP Gladys:1883",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f4ab211ed11dc81c",
"x": 980,
"y": 480,
"wires": []
},
{
"id": "341b7ddd6a3eb996",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Envoi TEMPO PARAM_NB_J_BLANC",
"func": "var nbJour = msg.payload.PARAM_NB_J_BLANC;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"NbJourBlanc\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt:\" TEMPO-EDF /feature/mqtt:\" JOUR /text\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/text\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nmsg.payload = nbJour;\nnode.status({ fill: \"white\", shape: \"ring\", text: nbJour });\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 480,
"wires": [
[
"25f4c2d57f2b9c3d",
"6d3c60cbfc8197ad"
]
]
},
{
"id": "25b74b7de9880f61",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Envoi TEMPO PARAM_NB_J_BLEU",
"func": "var nbJour = msg.payload.PARAM_NB_J_BLEU;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"NbJourBleu\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt:\" TEMPO-EDF /feature/mqtt:\" JOUR /text\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/text\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nmsg.payload = nbJour;\nnode.status({ fill: \"white\", shape: \"ring\", text: nbJour });\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 420,
"wires": [
[
"25f4c2d57f2b9c3d",
"6d3c60cbfc8197ad"
]
]
},
{
"id": "6c60d01b69c8beda",
"type": "function",
"z": "2b792c822e8e46f1",
"g": "02e46bae52d39d3b",
"name": "Envoi TEMPO PARAM_NB_J_ROUGE",
"func": "var nbJour = msg.payload.PARAM_NB_J_ROUGE;\n\n// ** Début Bloc ***********************************************************************************************\n\n// Nom des appareils donnés dans Gladys\nvar nomAppareilGladys = \"TEMPO-EDF\"; // nom du device dans Gladys\nvar nomIdAppareilGladys = \"NbJourRouge\"; // nom de l'ID externe de la fonctionnalité\n\n// Valeur Topic et Payload à envoyer à Gladys\n// gladys/master/device/mqtt:\" TEMPO-EDF /feature/mqtt:\" JOUR /text\nmsg.topic = \"gladys/master/device/mqtt:\" + nomAppareilGladys + \"/feature/mqtt:\" + nomIdAppareilGladys + \"/text\";\n\n// Change le payload de sortie selon la valeur du payload envoyé par EDF\nmsg.payload = nbJour;\nnode.status({ fill: \"white\", shape: \"ring\", text: nbJour });\n\n// ** Fin Bloc ************************************************************************************************\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 540,
"wires": [
[
"25f4c2d57f2b9c3d",
"6d3c60cbfc8197ad"
]
]
},
{
"id": "f4ab211ed11dc81c",
"type": "mqtt-broker",
"name": "192.168.0.125:1883",
"broker": "192.168.0.125",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"autoUnsubscribe": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
}
]
(inspiré depuis Couleur EDF TEMPO dans Node Red)
Vous devez avoir cela maintenant dans Node-red
Adapter les paramètres du broker Mqtt à vos paramètres
Créez dans le dashboard de Gladys
Voila maintenant le TEMPO EDF est affiché dans votre dashboard.
Pour envoyer la couleur Tempo par Telegram avec une scène
Vous pouvez créer une scène
Voila maintenant vous pouvez recevoir LE TEMPO EDF via TELEGRAM tout les matins à 8h.
Vous pouvez conditionner l’envoi à la valeur de la couleur envoyée en créant une action « Continuer seulement si » à placer avant l’action envoyer un message
Les couleurs sont indiquées dans le code du node dans la valeur payload
// Change le payload de sortie selon la valeur du payload envoyé par EDF
if (tempo === "TEMPO_BLEU") {
msg.payload = 1;
node.status({ fill: "blue", shape: "ring", text: tempo });
}
if (tempo === "TEMPO_BLANC") {
msg.payload = 2;
node.status({ fill: "white", shape: "ring", text: tempo });
}
if (tempo === "TEMPO_ROUGE") {
msg.payload = 3;
node.status({ fill: "red", shape: "ring", text: tempo });
}
if (tempo === "NON_DEFINI") {
msg.payload = 4;
node.status({ fill: "grey", shape: "ring", text: tempo });
}
Voila de quoi faire des économies supplémentaires !
PS: 03/12/23 maj avec ajout du nombre de jours restants en Bleu, Blanc et Rouge
La récupération des infos TEMPO se fait via les noeuds inject à 13h01 (EDF les change à 13h)