Baseado no Fluxo do Walber eu fiz como o @davidalben sugeriu e criei mais uma entidate com a soma do valor da bandeira + o valor kw/h:
[
{
"id": "b207558ffc3b9392",
"type": "tab",
"label": "CPFL",
"disabled": false,
"info": "",
"env": []
},
{
"id": "1b8cad127ef24c75",
"type": "group",
"z": "b207558ffc3b9392",
"style": {
"stroke": "#999999",
"stroke-opacity": "1",
"fill": "none",
"fill-opacity": "1",
"label": true,
"label-position": "nw",
"color": "#a4a4a4"
},
"nodes": [
"d55786dbd3ac33e1",
"6ae5a081bb19593a",
"b0653a2b6c994944",
"fbd9b0308694c3e6",
"43303e313139716c",
"7f4cc2583ed5eefb",
"adb080097466b597",
"ead4a3d6d2b590be",
"f62c086ecdeeeed3",
"9df30f4e7e88772f",
"01ab11545ee6b79f",
"605da46785594dec",
"e3d4be17dc19253d",
"515d77a8aae560de",
"c286628c12b0f522",
"29ca378404f11b5c"
],
"x": 114,
"y": 199,
"w": 1892,
"h": 262
},
{
"id": "d55786dbd3ac33e1",
"type": "inject",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"props": [],
"repeat": "3600",
"crontab": "",
"once": true,
"onceDelay": "15",
"topic": "",
"x": 210,
"y": 380,
"wires": [
[
"fbd9b0308694c3e6",
"adb080097466b597"
]
]
},
{
"id": "6ae5a081bb19593a",
"type": "function",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "Tarifa",
"func": "if (msg.payload.success) {\n\n let record = msg.payload.result.records[0];\n\n let vlr_tusd = parseFloat(record.VlrTUSD.replace(\",\", \".\"));\n let vlr_te = parseFloat(record.VlrTE.replace(\",\", \".\"));\n let unidade = record.DscUnidadeTerciaria;\n\n if (unidade === \"MWh\") {\n vlr_tusd /= 1000;\n vlr_te /= 1000;\n }\n\n let valor_total = vlr_tusd + vlr_te;\n\n msg.payload = {\n vlr_tusd,\n vlr_te,\n //unidade,\n valor_total\n };\n\n return msg;\n } else {\n msg.payload = { error: \"Erro na resposta da API\" };\n // return msg;\n\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 340,
"wires": [
[
"ead4a3d6d2b590be"
]
]
},
{
"id": "b0653a2b6c994944",
"type": "http request",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 590,
"y": 340,
"wires": [
[
"6ae5a081bb19593a"
]
]
},
{
"id": "fbd9b0308694c3e6",
"type": "function",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "URL Tarifa",
"func": "let operadora = (\"CPFL-PAULISTA\");\nlet hoje = new Date().toISOString().split('T')[0];\n\nmsg.url = `https://dadosabertos.aneel.gov.br/api/3/action/datastore_search_sql?sql=SELECT * from \"fcf2906c-7c32-4b9b-a637-054e7a5234f4\" where \"SigAgente\"= '${operadora}' and \"DscBaseTarifaria\"='Tarifa de Aplicação' and \"DscSubGrupo\"='B1' and \"DscClasse\"='Residencial' and \"DscModalidadeTarifaria\"='Convencional' and \"DscSubClasse\"='Residencial' and \"DscDetalhe\"='Não se aplica' and \"DatFimVigencia\" > '${hoje}'`;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 390,
"y": 340,
"wires": [
[
"b0653a2b6c994944"
]
]
},
{
"id": "43303e313139716c",
"type": "function",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "Bandeira",
"func": "if (msg.payload.success) {\n let record = msg.payload.result.records[0];\n let bandeira = record.NomBandeiraAcionada;\n let VlrAdicionalBandeira = parseFloat(record.VlrAdicionalBandeira.replace(\",\", \".\")) / 1000;\n\n msg.payload = {\n bandeira,\n VlrAdicionalBandeira\n\n };\n\n return msg;\n} else {\n msg.payload = { error: \"Erro na resposta da API\" };\n // return msg;\n\n}\n\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 760,
"y": 420,
"wires": [
[
"f62c086ecdeeeed3"
]
]
},
{
"id": "7f4cc2583ed5eefb",
"type": "http request",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 590,
"y": 420,
"wires": [
[
"43303e313139716c"
]
]
},
{
"id": "adb080097466b597",
"type": "function",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "URL Bandeira",
"func": "let data = new Date();\nlet anomes = data.getFullYear() + \"-\" + String(data.getMonth() + 1).padStart(2, '0') + '-%';\n\nmsg.url = `https://dadosabertos.aneel.gov.br/api/3/action/datastore_search_sql?sql=SELECT * from \"0591b8f6-fe54-437b-b72b-1aa2efd46e42\" where \"DatCompetencia\" like '${anomes}'`;\n\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 420,
"wires": [
[
"7f4cc2583ed5eefb"
]
]
},
{
"id": "ead4a3d6d2b590be",
"type": "ha-sensor",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "CPFL Preço KWh",
"entityConfig": "ee05fe2fc71504c5",
"version": 0,
"state": "payload.valor_total",
"stateType": "msg",
"attributes": [
{
"property": "vlr_tusd",
"value": "payload.vlr_tusd",
"valueType": "msg"
},
{
"property": "vlr_te",
"value": "payload.vlr_te",
"valueType": "msg"
}
],
"inputOverride": "allow",
"outputProperties": [],
"x": 950,
"y": 340,
"wires": [
[
"605da46785594dec"
]
]
},
{
"id": "f62c086ecdeeeed3",
"type": "ha-sensor",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "CPFL Bandeira Tarifaria",
"entityConfig": "574512a222a0f352",
"version": 0,
"state": "payload.bandeira",
"stateType": "msg",
"attributes": [
{
"property": "VlrAdicionalBandeira",
"value": "payload.VlrAdicionalBandeira",
"valueType": "msg"
}
],
"inputOverride": "allow",
"outputProperties": [],
"x": 970,
"y": 420,
"wires": [
[
"e3d4be17dc19253d"
]
]
},
{
"id": "9df30f4e7e88772f",
"type": "server-events",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "HA Restart",
"server": "eaa13fce560d37e9",
"version": 3,
"exposeAsEntityConfig": "",
"eventType": "home_assistant_client",
"eventData": "",
"waitForRunning": true,
"outputProperties": [
{
"property": "entity_id",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "$outputData(\"eventData\").event_type",
"valueType": "jsonata"
},
{
"property": "event_type",
"propertyType": "msg",
"value": "$outputData(\"eventData\").event_type",
"valueType": "jsonata"
}
],
"x": 200,
"y": 240,
"wires": [
[
"01ab11545ee6b79f"
]
]
},
{
"id": "01ab11545ee6b79f",
"type": "switch",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ready",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 210,
"y": 300,
"wires": [
[
"fbd9b0308694c3e6",
"adb080097466b597"
]
]
},
{
"id": "605da46785594dec",
"type": "change",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"rules": [
{
"t": "set",
"p": "parts",
"pt": "msg",
"to": "1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1200,
"y": 340,
"wires": [
[
"515d77a8aae560de"
]
]
},
{
"id": "e3d4be17dc19253d",
"type": "change",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"rules": [
{
"t": "set",
"p": "parts",
"pt": "msg",
"to": "1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1200,
"y": 420,
"wires": [
[
"515d77a8aae560de"
]
]
},
{
"id": "515d77a8aae560de",
"type": "join",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"mode": "custom",
"build": "array",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"useparts": true,
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "num",
"reduceFixup": "",
"x": 1410,
"y": 380,
"wires": [
[
"c286628c12b0f522"
]
]
},
{
"id": "c286628c12b0f522",
"type": "change",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "$sum(payload[0].VlrAdicionalBandeira+payload[1].valor_total)\t",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1620,
"y": 380,
"wires": [
[
"29ca378404f11b5c"
]
]
},
{
"id": "29ca378404f11b5c",
"type": "ha-sensor",
"z": "b207558ffc3b9392",
"g": "1b8cad127ef24c75",
"name": "CPFL Preço Total KWh",
"entityConfig": "346a8982ba1e71fe",
"version": 0,
"state": "payload",
"stateType": "msg",
"attributes": [],
"inputOverride": "allow",
"outputProperties": [],
"x": 1880,
"y": 380,
"wires": [
[]
]
},
{
"id": "ee05fe2fc71504c5",
"type": "ha-entity-config",
"server": "eaa13fce560d37e9",
"deviceConfig": "",
"name": "CPFL Preço KWh",
"version": 6,
"entityType": "sensor",
"haConfig": [
{
"property": "name",
"value": "CPFL Preço KWh"
},
{
"property": "icon",
"value": "mdi:transmission-tower"
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "device_class",
"value": ""
},
{
"property": "unit_of_measurement",
"value": "R$"
},
{
"property": "state_class",
"value": ""
}
],
"resend": false,
"debugEnabled": false
},
{
"id": "574512a222a0f352",
"type": "ha-entity-config",
"server": "eaa13fce560d37e9",
"deviceConfig": "",
"name": "CPFL Bandeira Tarifaria",
"version": 6,
"entityType": "sensor",
"haConfig": [
{
"property": "name",
"value": "CPFL Bandeira Tarifaria"
},
{
"property": "icon",
"value": "mdi:transmission-tower"
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "device_class",
"value": ""
},
{
"property": "unit_of_measurement",
"value": ""
},
{
"property": "state_class",
"value": ""
}
],
"resend": false,
"debugEnabled": false
},
{
"id": "eaa13fce560d37e9",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": false,
"heartbeat": false,
"heartbeatInterval": "30",
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": ": ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "default",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": false
},
{
"id": "346a8982ba1e71fe",
"type": "ha-entity-config",
"server": "eaa13fce560d37e9",
"deviceConfig": "",
"name": "CPFL Preço total",
"version": 6,
"entityType": "sensor",
"haConfig": [
{
"property": "name",
"value": "CPFL Preço total BRL/kWh"
},
{
"property": "icon",
"value": "mdi:transmission-tower"
},
{
"property": "entity_picture",
"value": ""
},
{
"property": "entity_category",
"value": ""
},
{
"property": "device_class",
"value": ""
},
{
"property": "unit_of_measurement",
"value": "BRL/kWh"
},
{
"property": "state_class",
"value": ""
}
],
"resend": false,
"debugEnabled": false
}
]