Besoin d'aide pour une fonction node red

Mon problème

bonjour à tous.

j’ai une batterie solaire pylontech us5000, j’ai reussi à recuperer les donnée « SOC » via le port console de la batterie et, avec node red, à les afficher dans HA sans trop de problèmes en adaptant un code existant à ma configuration TCP IP. Par contre je n’y arrive pas pour la commande SOH. je suppose que c’est parce que le format de mon tableau de valeurs (15 entités contenant 3 valeurs variables, mais pas uniquement numériques…) ne correspond pas à ce qu’attend HA.

si jamais quelqu’un peux m’aider… voici en exemple un des 15 objets que je vois dans mon debug : « {« Battery »:8,« Voltage »:3.301,« SOHCount »:0,« SOHStatus »:« Normal »} », on voit que les données sont correctement extraites par cellules composant ma batterie. Maintenant je bloque pour envoyer ces données dans HA, n’étant pas codeur pour un sou. voici mon flux JSON complet si nécessaire : « [
{
« id »: « d05ce6c13f22f4ee »,
« type »: « tab »,
« label »: « pylontech stable »,
« disabled »: false,
« info »: «  »
},
{
« id »: « 52cdecbf1e0d074c »,
« type »: « group »,
« z »: « d05ce6c13f22f4ee »,
« name »: « envoi commandes »,
« style »: {
« label »: true
},
« nodes »: [
« 5907c51a84840677 »,
« 293f7a04d14433d0 »,
« e1eff34249ff9ea5 »,
« 4ca4e7ee589b8b45 »,
« 15cb9410fd369d70 »,
« 060bbaefb18bf7d9 »
],
« x »: 254,
« y »: 79,
« w »: 752,
« h »: 162
},
{
« id »: « db52b972e708638d »,
« type »: « group »,
« z »: « d05ce6c13f22f4ee »,
« name »: « récéption et redirection cmd »,
« style »: {
« label »: true
},
« nodes »: [
« 1dbe93994797eb87 »,
« 76873ef0a587cc9b »,
« 0eb42c30caf110e2 »,
« e99d0369c311d6e1 »
],
« x »: 14,
« y »: 279,
« w »: 442,
« h »: 129.5
},
{
« id »: « 128de371bfb73a68 »,
« type »: « group »,
« z »: « d05ce6c13f22f4ee »,
« name »: « traitement cmd "PWR" »,
« style »: {
« label »: true
},
« nodes »: [
« b20e61b890673ef4 »,
« 3e0e164d9fda0456 »,
« 1327c101ba35d890 »,
« fa28b3aa4474b393 »,
« e5ceef85e58934a0 »,
« a2c4d977b0c2fd8e »,
« 221bd1bc0a05b0a7 »
],
« x »: 804,
« y »: 279,
« w »: 622,
« h »: 242
},
{
« id »: « 5907c51a84840677 »,
« type »: « inject »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « pwr - get power data »,
« props »: [
{
« p »: « payload »
},
{
« p »: « baudrate »,
« v »: « 115200 »,
« vt »: « num »
}
],
« repeat »: « 2 »,
« crontab »: «  »,
« once »: false,
« onceDelay »: « 0 »,
« topic »: «  »,
« payload »: « pwr »,
« payloadType »: « str »,
« x »: 400,
« y »: 120,
« wires »: [
[
« 293f7a04d14433d0 »
]
]
},
{
« id »: « 293f7a04d14433d0 »,
« type »: « simple-queue »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « Queue »,
« firstMessageBypass »: true,
« bypassInterval »: « 1000 »,
« x »: 590,
« y »: 160,
« wires »: [
[
« e1eff34249ff9ea5 »
]
]
},
{
« id »: « e1eff34249ff9ea5 »,
« type »: « function »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « add \n »,
« func »: « msg.payload += "\n";\nreturn msg; »,
« outputs »: 1,
« timeout »: «  »,
« noerr »: 0,
« initialize »: «  »,
« finalize »: «  »,
« libs »: ,
« x »: 710,
« y »: 160,
« wires »: [
[
« 4ca4e7ee589b8b45 »
]
]
},
{
« id »: « 4ca4e7ee589b8b45 »,
« type »: « tcp request »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « gw TCPIP Pylontech »,
« server »: « 192.168.1.77 »,
« port »: « 7774 »,
« out »: « time »,
« ret »: « string »,
« splitc »: « 0 »,
« newline »: «  »,
« trim »: false,
« tls »: «  »,
« x »: 880,
« y »: 160,
« wires »: [

]
},
{
« id »: « 15cb9410fd369d70 »,
« type »: « inject »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « soh - get soh data »,
« props »: [
{
« p »: « payload »
},
{
« p »: « baudrate »,
« v »: « 115200 »,
« vt »: « num »
}
],
« repeat »: « 2 »,
« crontab »: «  »,
« once »: false,
« onceDelay »: « 5 »,
« topic »: «  »,
« payload »: « soh »,
« payloadType »: « str »,
« x »: 410,
« y »: 160,
« wires »: [
[
« 293f7a04d14433d0 »
]
]
},
{
« id »: « 060bbaefb18bf7d9 »,
« type »: « inject »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 52cdecbf1e0d074c »,
« name »: « info »,
« props »: [
{
« p »: « payload »
},
{
« p »: « baudrate »,
« v »: « 115200 »,
« vt »: « num »
}
],
« repeat »: «  »,
« crontab »: «  »,
« once »: false,
« onceDelay »: «  »,
« topic »: «  »,
« payload »: « info »,
« payloadType »: « str »,
« x »: 450,
« y »: 200,
« wires »: [
[
« 293f7a04d14433d0 »
]
]
},
{
« id »: « 1dbe93994797eb87 »,
« type »: « tcp in »,
« z »: « d05ce6c13f22f4ee »,
« g »: « db52b972e708638d »,
« name »: « TCP Pylontech »,
« server »: « client »,
« host »: « 192.168.1.77 »,
« port »: « 7774 »,
« datamode »: « stream »,
« datatype »: « utf8 »,
« newline »: «  »,
« topic »: «  »,
« trim »: false,
« base64 »: false,
« tls »: «  »,
« x »: 120,
« y »: 360,
« wires »: [
[
« 76873ef0a587cc9b »
]
]
},
{
« id »: « 76873ef0a587cc9b »,
« type »: « switch »,
« z »: « d05ce6c13f22f4ee »,
« g »: « db52b972e708638d »,
« name »: «  »,
« property »: « payload »,
« propertyType »: « msg »,
« rules »: [
{
« t »: « cont »,
« v »: « pwr »,
« vt »: « str »
},
{
« t »: « cont »,
« v »: « soh »,
« vt »: « str »
},
{
« t »: « cont »,
« v »: « info »,
« vt »: « str »
}
],
« checkall »: « true »,
« repair »: true,
« outputs »: 3,
« x »: 280,
« y »: 360,
« wires »: [
[
« 0eb42c30caf110e2 »
],
[
« e99d0369c311d6e1 »
],

]
},
{
« id »: « 0eb42c30caf110e2 »,
« type »: « link out »,
« z »: « d05ce6c13f22f4ee »,
« g »: « db52b972e708638d »,
« name »: « link out 3 »,
« mode »: « link »,
« links »: [
« 32aa6230239a7ec2 »,
« 221bd1bc0a05b0a7 »
],
« x »: 395,
« y »: 320,
« wires »:
},
{
« id »: « e99d0369c311d6e1 »,
« type »: « link out »,
« z »: « d05ce6c13f22f4ee »,
« g »: « db52b972e708638d »,
« name »: « link out 4 »,
« mode »: « link »,
« links »: [
« 5bbd77aa6465816b »,
« 1e8e0b3c2b03d5a6 »
],
« x »: 415,
« y »: 360,
« wires »:
},
{
« id »: « b20e61b890673ef4 »,
« type »: « split »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « Split into rows »,
« splt »: « \n »,
« spltType »: « str »,
« arraySplt »: 1,
« arraySpltType »: « len »,
« stream »: false,
« addname »: «  »,
« x »: 960,
« y »: 320,
« wires »: [
[
« 3e0e164d9fda0456 »
]
]
},
{
« id »: « 3e0e164d9fda0456 »,
« type »: « function »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « Row to Array »,
« func »: « var a = msg.payload;\nvar array = ;\narray[0] = new Array(parseInt(a.toString().substr(0, 6)), "BattID", null, null);\narray[1] = new Array(parseInt(a.toString().substr(6, 7)) / 1000, "Volt", "V", "voltage", array[0][0]);\narray[2] = new Array(parseInt(a.toString().substr(13, 7)) / 1000, "Curr", "A", "current", array[0][0]);\narray[3] = new Array(parseInt(a.toString().substr(20, 7)) / 1000, "Tempr", "°C", "temperature", array[0][0]);\narray[4] = new Array(parseInt(a.toString().substr(27, 7)) / 1000, "Tlow", "°C", "temperature", array[0][0]);\narray[5] = new Array(parseInt(a.toString().substr(34, 7)) / 1000, "Thigh", "°C", "temperature", array[0][0]);\narray[6] = new Array(parseInt(a.toString().substr(41, 7)) / 1000, "Vlow", "V", "voltage", array[0][0]);\narray[7] = new Array(parseInt(a.toString().substr(48, 7)) / 1000, "Vhigh", "V", "voltage", array[0][0]);\narray[8] = new Array(a.substr(55, 9).trim(), "BaseSt", null, null, array[0][0]);\narray[9] = new Array(a.substr(64, 9).trim(), "VoltSt", null, null, array[0][0]);\narray[10] = new Array(a.substr(73, 9).trim(), "CurrSt", null, null, array[0][0]);\narray[11] = new Array(a.substr(82, 9).trim(), "TempSt", null, null, array[0][0]);\narray[12] = new Array(parseInt(a.toString().substr(91, 9)), "SOC", "%", "battery", array[0][0]);\nif (array[8][0] !== "Absent" && array[8][0] !== "" && array[8][0] !== "Base.St") {\n msg.payload = array;\n return msg;\n} »,
« outputs »: 1,
« timeout »: «  »,
« noerr »: 0,
« initialize »: «  »,
« finalize »: «  »,
« libs »: ,
« x »: 950,
« y »: 360,
« wires »: [
[
« 1327c101ba35d890 »
]
]
},
{
« id »: « 1327c101ba35d890 »,
« type »: « split »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « Split Array »,
« splt »: « \n »,
« spltType »: « str »,
« arraySplt »: 1,
« arraySpltType »: « len »,
« stream »: false,
« addname »: «  »,
« x »: 950,
« y »: 400,
« wires »: [
[
« fa28b3aa4474b393 »
]
]
},
{
« id »: « fa28b3aa4474b393 »,
« type »: « function »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « Assemble Value »,
« func »: « var v = msg.payload;\nif (v[1] !== "BattID") {\n msg.payload = v[0];\n msg.shorttopic = v[1];\n if (v[2] !== null) {\n msg.unit = v[2];\n }\n if (v[3] !== null) {\n msg.deviceclass = v[3];\n }\n msg.deviceid = v[4];\n msg.topic = homeassistant/sensor/Pylontech${msg.deviceid}/${msg.shorttopic}/value;\n msg.topic = msg.topic.replace("//", "/");\n return msg;\n} »,
« outputs »: 1,
« timeout »: «  »,
« noerr »: 0,
« initialize »: «  »,
« finalize »: «  »,
« libs »: ,
« x »: 960,
« y »: 440,
« wires »: [
[
« e5ceef85e58934a0 »,
« a2c4d977b0c2fd8e »
]
]
},
{
« id »: « e5ceef85e58934a0 »,
« type »: « function »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « Assemble Config »,
« func »: « msg.topic = homeassistant/sensor/Pylontech${msg.deviceid}/${msg.shorttopic}/config.replace("//", "/");\nmsg.payload = {\n "unit_of_measurement": msg.unit || undefined,\n "device_class": msg.deviceclass || undefined,\n "state_topic": homeassistant/sensor/Pylontech${msg.deviceid}/${msg.shorttopic}/value.replace("//", "/"),\n "name": Pylontech${msg.deviceid}_${msg.shorttopic}, \n "unique_id": ${msg.shorttopic}${msg.deviceid}, \n "device": {\n "identifiers": ["Pylontech"], \n "name": msg.shorttopic, \n "model": "US5000", \n "manufacturer": "Pylontech"\n }\n};\nreturn msg; »,
« outputs »: 1,
« timeout »: «  »,
« noerr »: 0,
« initialize »: «  »,
« finalize »: «  »,
« libs »: ,
« x »: 970,
« y »: 480,
« wires »: [
[
« a2c4d977b0c2fd8e »
]
]
},
{
« id »: « a2c4d977b0c2fd8e »,
« type »: « mqtt out »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « serveur SOC Pylontech »,
« topic »: «  »,
« qos »: «  »,
« retain »: «  »,
« respTopic »: «  »,
« contentType »: «  »,
« userProps »: «  »,
« correl »: «  »,
« expiry »: «  »,
« broker »: « 3a91ca19b1c57cd3 »,
« x »: 1290,
« y »: 460,
« wires »:
},
{
« id »: « 221bd1bc0a05b0a7 »,
« type »: « link in »,
« z »: « d05ce6c13f22f4ee »,
« g »: « 128de371bfb73a68 »,
« name »: « link in 3 »,
« links »: [
« b1db3d877f3f200b »,
« 0eb42c30caf110e2 »
],
« x »: 845,
« y »: 320,
« wires »: [
[
« b20e61b890673ef4 »
]
]
},
{
« id »: « 8125df221599f012 »,
« type »: « function »,
« z »: « d05ce6c13f22f4ee »,
« name »: « extract SOH data »,
« func »: « var mqttString = msg.payload;\nvar lines = mqttString.split(‹ \n ›);\nvar sohData = ;\nvar regex = /\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/;\nfor (var i = 4; i < lines.length - 3; i++) {\n var matches = lines[i].match(regex);\n if (matches) {\n var entry = {\n Battery: parseInt(matches[1]),\n Voltage: parseFloat(matches[2]) / 1000,\n SOHCount: parseInt(matches[3]),\n SOHStatus: matches[4].trim()\n };\n sohData.push(entry);\n }\n}\nmsg.payload = { SOH: sohData };\nreturn msg; »,
« outputs »: 1,
« timeout »: «  »,
« noerr »: 0,
« initialize »: «  »,
« finalize »: «  »,
« libs »: ,
« x »: 350,
« y »: 620,
« wires »: [
[
« 5994a2e71ac1e5e0 »,
« ed533080245ee91d »
]
]
},
{
« id »: « 5994a2e71ac1e5e0 »,
« type »: « debug »,
« z »: « d05ce6c13f22f4ee »,
« name »: « debug SOH data »,
« active »: false,
« console »: « false »,
« complete »: « payload »,
« x »: 630,
« y »: 620,
« wires »:
},
{
« id »: « 1e8e0b3c2b03d5a6 »,
« type »: « link in »,
« z »: « d05ce6c13f22f4ee »,
« name »: « link in 4 »,
« links »: [
« 29fe78fd2b9afd56 »,
« e99d0369c311d6e1 »
],
« x »: 225,
« y »: 620,
« wires »: [
[
« 8125df221599f012 »
]
]
},
{
« id »: « ed533080245ee91d »,
« type »: « split »,
« z »: « d05ce6c13f22f4ee »,
« name »: « Split into rows »,
« splt »: « \n »,
« spltType »: « str »,
« arraySplt »: 1,
« arraySpltType »: « len »,
« stream »: false,
« addname »: «  »,
« x »: 340,
« y »: 660,
« wires »: [
[
« 2f16980de94c25d6 »,
« 75f07db228b111d4 »
]
]
},
{
« id »: « 2f16980de94c25d6 »,
« type »: « split »,
« z »: « d05ce6c13f22f4ee »,
« name »: « Split into cells »,
« splt »: « , »,
« spltType »: « str »,
« arraySplt »: « 1 »,
« arraySpltType »: « len »,
« stream »: false,
« addname »: «  »,
« x »: 320,
« y »: 700,
« wires »: [
[
« 1bad0c3a8b3c3b70 »,
« 340cf59c079a67d9 »
]
]
},
{
« id »: « 75f07db228b111d4 »,
« type »: « debug »,
« z »: « d05ce6c13f22f4ee »,
« name »: « debug 72 »,
« active »: false,
« tosidebar »: true,
« console »: false,
« tostatus »: false,
« complete »: « false »,
« statusVal »: «  »,
« statusType »: « auto »,
« x »: 600,
« y »: 660,
« wires »:
},
{
« id »: « 1bad0c3a8b3c3b70 »,
« type »: « debug »,
« z »: « d05ce6c13f22f4ee »,
« name »: « debug 73 »,
« active »: false,
« tosidebar »: true,
« console »: false,
« tostatus »: false,
« complete »: « false »,
« statusVal »: «  »,
« statusType »: « auto »,
« x »: 600,
« y »: 700,
« wires »:
},
{
« id »: « 643dbb8995f7e2af »,
« type »: « debug »,
« z »: « d05ce6c13f22f4ee »,
« name »: « debug 74 »,
« active »: false,
« tosidebar »: true,
« console »: false,
« tostatus »: false,
« complete »: « false »,
« statusVal »: «  »,
« statusType »: « auto »,
« x »: 600,
« y »: 740,
« wires »:
},
{
« id »: « 340cf59c079a67d9 »,
« type »: « mqtt out »,
« z »: « d05ce6c13f22f4ee »,
« name »: «  »,
« topic »: « homeassistant/sensor/Pylontech/SOH »,
« qos »: «  »,
« retain »: «  »,
« respTopic »: «  »,
« contentType »: «  »,
« userProps »: «  »,
« correl »: «  »,
« expiry »: «  »,
« broker »: « 3a91ca19b1c57cd3 »,
« x »: 310,
« y »: 780,
« wires »:
},
{
« id »: « 3a91ca19b1c57cd3 »,
« type »: « mqtt-broker »,
« name »: «  »,
« broker »: « core-mosquitto »,
« 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 »: «  »
}
] ».

Ma configuration

Citation

///////

System Information

version core-2024.2.0b0
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.1
os_name Linux
os_version 6.1.63-haos-raspi
arch aarch64
timezone Europe/Paris
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.34.0
Stage running
Available Repositories 1386
Downloaded Repositories 3
HACS Data ok
Home Assistant Cloud
logged_in true
subscription_expiration 20 février 2024 à 01:00
relayer_connected true
relayer_region eu-central-1
remote_enabled true
remote_connected true
alexa_enabled true
google_enabled true
remote_server eu-central-1-16.ui.nabu.casa
certificate_status ready
instance_id f9782c5b0999479dab3ed020769217da
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 11.5.rc3
update_channel beta
supervisor_version supervisor-2024.01.1
agent_version 1.6.0
docker_version 24.0.7
disk_total 116.7 GB
disk_used 8.3 GB
healthy true
supported true
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Terminal & SSH (9.8.1), File editor (5.7.0), Mosquitto broker (6.4.0), Node-RED (17.0.3), MariaDB (2.6.1), Studio Code Server (5.15.0)
Dashboards
dashboards 2
resources 0
views 1
mode storage
Recorder
oldest_recorder_run 27 janvier 2024 à 21:51
current_recorder_run 1 février 2024 à 00:12
estimated_db_size 50.76 MiB
database_engine sqlite
database_version 3.44.2
//////////