Tutorial - Recuperar el precio de tu suscripción de electricidad a través del sitio web data.gouv.fr - Tarifas fuera de horario

Hola,

Os veo presentar aquí cómo recuperar el precio de la electricidad con node-red a través del archivo: https://www.data.gouv.fr/fr/datasets/r/c13d05e5-9e55-4d03-bf7e-042a2ade7e49 y luego transferirlo a un tema MQTT para usarlo en Gladys :wink:

Este archivo se encuentra aquí: https://www.data.gouv.fr/fr/datasets/historique-des-tarifs-reglementes-de-vente-delectricite-pour-les-consommateurs-residentiels/

Este tutorial es compatible solo con la opción « Base » ya que es la opción asociada a mi contrato :slight_smile:
Pero creo que es bastante fácil de implementar para la opción « Horas pico/Horas valle ».

El resultado final:

image

Aquí está el flujo de Node-Red:

Aquí está el flujo en formato JSON para importarlo a su Node-Red:
(El valor se recupera todas las noches a las 3:00)

[
    {
        "id": "d6333988d9cfb817",
        "type": "tab",
        "label": "Flujo - Costo EDF",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "d79ac3d249808c33",
        "type": "mqtt out",
        "z": "d6333988d9cfb817",
        "name": "",
        "topic": "gladys/master/device/mqtt:edf/feature/mqtt:cout-abonnement/state",
        "qos": "2",
        "retain": "true",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "0ee77e0f90aa9681",
        "x": 830,
        "y": 400,
        "wires": []
    },
    {
        "id": "1852e9b329fd3f44",
        "type": "http request",
        "z": "d6333988d9cfb817",
        "name": "Descargar CSV",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "https://www.data.gouv.fr/fr/datasets/r/c13d05e5-9e55-4d03-bf7e-042a2ade7e49",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 240,
        "y": 160,
        "wires": [
            [
                "24804ed33b7a2cd6"
            ]
        ]
    },
    {
        "id": "24804ed33b7a2cd6",
        "type": "csv",
        "z": "d6333988d9cfb817",
        "name": "Conversión CSV a tabla",
        "sep": ";",
        "hdrin": true,
        "hdrout": "none",
        "multi": "mult",
        "ret": "\\n",
        "temp": "DATE_DEBUT;DATE_FIN;P_SOUSCRITE;PART_FIXE_HT;PART_FIXE_TTC;PART_VARIABLE_HT;PART_VARIABLE_TTC",
        "skip": "0",
        "strings": false,
        "include_empty_strings": false,
        "include_null_values": false,
        "x": 400,
        "y": 220,
        "wires": [
            [
                "8576856348eb0e34"
            ]
        ]
    },
    {
        "id": "8576856348eb0e34",
        "type": "function",
        "z": "d6333988d9cfb817",
        "name": "Extracción de la PART_VARIABLE_TTC más reciente según P_SOUSCRITE",
        "func": "// Filtrar los datos para P_SOUSCRITE = 6 y DATE_FIN ausente o vacío\nmsg.payload = msg.payload.filter(item => item.P_SOUSCRITE === \"6\" && (!item.DATE_FIN || item.DATE_FIN.trim() === \"\"));\n\n// Reemplazar las comas por puntos en los valores de PART_VARIABLE_TTC\nmsg.payload = msg.payload.map(item => {\n    // Reemplazar las comas por puntos en el valor de PART_VARIABLE_TTC\n    item.PART_VARIABLE_TTC = item.PART_VARIABLE_TTC.replace(/,/g, '.');\n    // Convertir PART_VARIABLE_TTC a número\n    item.PART_VARIABLE_TTC = parseFloat(item.PART_VARIABLE_TTC);\n    return item.PART_VARIABLE_TTC;\n});\nreturn msg;\n\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 630,
        "y": 280,
        "wires": [
            [
                "644a3870177af55a"
            ]
        ]
    },
    {
        "id": "644a3870177af55a",
        "type": "function",
        "z": "d6333988d9cfb817",
        "name": "Conversión a número",
        "func": "msg.payload = parseFloat(msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 340,
        "wires": [
            [
                "d79ac3d249808c33"
            ]
        ]
    },
    {
        "id": "1943b35881c8a2fa",
        "type": "cronplus",
        "z": "d6333988d9cfb817",
        "name": "Cron diario",
        "outputField": "payload",
        "timeZone": "",
        "storeName": "",
        "commandResponseMsgOutput": "output1",
        "defaultLocation": "",
        "defaultLocationType": "default",
        "outputs": 1,
        "options": [
            {
                "name": "schedule1",
                "topic": "topic1",
                "payloadType": "default",
                "payload": "",
                "expressionType": "cron",
                "expression": "0 0 01 * * *",
                "location": "",
                "offset": "0",
                "solarType": "all",
                "solarEvents": "sunrise,sunset"
            }
        ],
        "x": 140,
        "y": 100,
        "wires": [
            [
                "1852e9b329fd3f44"
            ]
        ]
    },
    {
        "id": "670838a9edef0758",
        "type": "catch",
        "z": "d6333988d9cfb817",
        "name": "Errores",
        "scope": null,
        "uncaught": false,
        "x": 110,
        "y": 60,
        "wires": [
            [
                "c097dad994334b5e"
            ]
        ]
    },
    {
        "id": "c097dad994334b5e",
        "type": "e-mail",
        "z": "d6333988d9cfb817",
        "server": "monsmtp.a.remplacer",
        "port": "465",
        "authtype": "BASIC",
        "saslformat": false,
        "token": "oauth2Response.access_token",
        "secure": true,
        "tls": true,
        "name": "aremplacer@monmail.fr",
        "dname": "Correo",
        "x": 250,
        "y": 60,
        "wires": []
    },
    {
        "id": "0ee77e0f90aa9681",
        "type": "mqtt-broker",
        "name": "Gladys",
        "broker": "mqtt://192.168.x.x",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

Recuerda modificar el valor de P_SOUSCRITE en la función « Extracción de la PART_VARIABLE_TTC más reciente según P_SOUSCRITE »
Y también la dirección IP de tu broker MQTT

Aquí está el dispositivo MQTT con la funcionalidad:


image

Si tienes preguntas/comentarios, no dudes en decírmelo :slight_smile:

Changelog por venir:

  • Ninguno (¡A tus comentarios :slight_smile: )

Edición 23/04/2024:

  • Añadido capturas de pantalla para el dispositivo MQTT
  • Añadido un catch all para la gestión de errores y ser notificado por correo electrónico

¡Tutorial excelente! Gracias @prohand :slight_smile:

Actualización del tutorial :slight_smile:
Ver el registro de cambios :wink:

Tutorial para la tarifa Tempo con actualización automática disponible: