Extraire donnéé json avec node-red

bonjour a tous
j’ai un apareil ou je peux recuperer les données en json par une requette http,
je vous passe la partie authetification creation du token, j’y suis arrivé,
mais maintenant ou je bloque c’est pour la mise en forme et pourvoir extraire mes données, pour les injecter dans HA

"{"data":{"pioneerCitizenName":"***@***","pioneerCitizenNumber":685,"productionUnitVersion":null,"productionUnitType":"Family22 - Original","picturePath":null,"productionUnitOptions":"","onlineSinceWeeks":16,"averageMonthlyProduction":12,"averageMonthlySparedCO2":3.5999999999999996,"currentPhValue":6.30,"currentPhCaptureTime":"2023-05-04T13:08:21Z","averageHourPhValue":6.3,"averageDayPhValue":6.3,"lastDayPhCaptureTime":"2023-05-03T13:08:21Z","currentWaterTempValue":20.40,"currentWaterTempCaptureTime":"2023-05-04T13:08:21Z","averageHourWaterTempValue":20.1,"averageDayWaterTempValue":19.5,"lastDayWaterTempCaptureTime":"2023-05-03T13:08:21Z","currentAirTempValue":29.20,"currentAirTempCaptureTime":"2023-05-04T13:08:21Z","averageHourAirTempValue":28.2,"averageDayAirTempValue":22.1,"lastDayAirTempCaptureTime":"2023-05-03T13:08:21Z","currentHumidityValue":29.50,"currentHumidityCaptureTime":"2023-05-04T13:08:21Z","averageHourHumidityValue":31.3,"averageDayHumidityValue":51.6,"lastDay..."

je tente de sortir currentPhValue
je tente plusieurs choses mais sans succes

Salut,
Il te faut récupérer les valeurs avec cette syntaxe:

payload.data.currentPhValue

pour la valeur du PH par exemple

et ensuite les injecter dans HA en passant par le node sensor
image

sur quel node je dois mettre la syntaxe :sweat_smile:, directement sur le « edit json » sur le « change node »
image

Difficile de te dire du moment où on ne sait pas d’où arrive ton json.
On ne sais même pas quelle(s) valeur(s) tu veux extraire.
Je peux te faire les mêmes capture d’écran avec rien dans les nodes alors si tu veux un peux plus d’aide, il faut faire le ménage dans ton flow en supprimant les node qui ne servent à rien et faire un export du flow.

j’ai teste plusieru chose, les donné extaite dans mon 1er port c’est sorti du note json avec juste « . payload »
si je met .payload.data.ph c’est l’imahe ci dessous erreur de propriete,
j’ai aussi teste de garde mon node json avec mon extration de data qui fonctionne avec d’autre node en suivant les infos que je trouve sur internet mais toujours en succes,
je tourne au tour de la solution mais je la vois pas encore :laughing: :sweat_smile:

Encore une fois, Ton export STP !
Et arrêtes les captures d’écran qui ne servent à rien

Désolé je viens de tomber sur la possibilité sur les export et import et comprendre comment on pouvait partager nos flow, :upside_down_face:

[{"id":"4c839c6278082f14","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"feb9aedbe466c818","type":"json","z":"4c839c6278082f14","name":"","property":"payload.data.currentPhValue","action":"str","pretty":true,"x":370,"y":280,"wires":[["dac0da81c328094f"]]},{"id":"b11cc9687a4208cd","type":"http request","z":"4c839c6278082f14","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://hub.myfood.eu/api/v1/ProductionUnit/GetProductionUnitDetailForUser?id=702","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Authorization","keyValue":"","valueType":"other","valueValue":"bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjBmNTUxNTA3LTI3MzktNDA5Ni04ZWMwLTA4MmJhYzZlZDhhZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI6Imdyb3VldHNlYmFzdGllbkBnbWFpbC5jb20iLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiPyIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL3N1cm5hbWUiOiI_PyIsImh0dHA6Ly9zY2h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c328094f","type":"debug","z":"4c839c6278082f14","name":"debug 1","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":450,"y":180,"wires":[]},{"id":"1ff8a105bb74d7e5","type":"server-state-changed","z":"4c839c6278082f14","name":"","server":"7ef5a641.f52e58","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.chevet_chambre","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":190,"y":20,"wires":[["13d5eeb2a7b091c3","b11cc9687a4208cd"],[]]},{"id":"13d5eeb2a7b091c3","type":"http request","z":"4c839c6278082f14","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://hub.myfood.eu/api/v1/Measures/GetWaterTemperatureForUser?id=702","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Authorization","keyValue":"","valueType":"other","valueValue":"bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjBmNTUxNTA3LTI3MzktNDA5Ni04ZWMwLTA4MmJhYzZlZDhhZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI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9kdWN0aW9uVW5pdFN0YXR1cy5WaWV3IiwiUGVybWlzc2lvbnMuUHJvZHVjdGlvblVuaXRUeXBlLlZpZXciLCJQZXJtaXNzaW9ucy5DYWxlbmRhci5WaWV3Il0sImV4cCI6MTY5MDg5OTExM30.gnfSYnzx3hy36FGRJn3k1Mnjn5qZYqkpHT46PteHNzY"}],"x":170,"y":280,"wires":[[]]},{"id":"7ef5a641.f52e58","type":"server","name":"Home Assistant","addon":true}]

C’est quelle valeur que tu veux récupérer ?

Si j’arrive à comprendre pour currentPhValue, je devrais être capable par analogie d’extraire le reste ,je suis pas doué pas mais j’apprends vite :sweat_smile:

Voilà un truc qui peut t’inspirer pour faire ce que tu veux.

[{"id":"4c839c6278082f14","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"feb9aedbe466c818","type":"json","z":"4c839c6278082f14","name":"","property":"payload","action":"obj","pretty":true,"x":410,"y":180,"wires":[["90ce1d7a1f3d7b72","4dd85887f4253cec"]]},{"id":"b11cc9687a4208cd","type":"http request","z":"4c839c6278082f14","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://hub.myfood.eu/api/v1/ProductionUnit/GetProductionUnitDetailForUser?id=702","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Authorization","keyValue":"","valueType":"other","valueValue":"bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6IjBmNTUxNTA3LTI3MzktNDA5Ni04ZWMwLTA4MmJhYzZlZDhhZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI6Imdyb3VldHNlYmFzdGllbkBnbWFpbC5jb20iLCJodHRwOi8vc2NoZW1hcy54b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dGlvblVuaXRUeXBlLlZpZXciLCJQZXJtaXNzaW9ucy5DYWxlbmRhci5WaWV3Il0sImV4cCI6MTY5MDg5OTExM30.gnfSYnzx3hy36FGRJn3k1Mnjn5qZYqkpHT46PteHNzY"}],"x":510,"y":80,"wires":[["feb9aedbe466c818"]]},{"id":"1ff8a105bb74d7e5","type":"server-state-changed","z":"4c839c6278082f14","name":"","server":"7ef5a641.f52e58","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.chevet_chambre","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":210,"y":60,"wires":[["b11cc9687a4208cd"],[]]},{"id":"2864c6934670a554","type":"inject","z":"4c839c6278082f14","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":100,"wires":[["b11cc9687a4208cd"]]},{"id":"90ce1d7a1f3d7b72","type":"debug","z":"4c839c6278082f14","name":"debug 21","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":260,"wires":[]},{"id":"4dd85887f4253cec","type":"ha-sensor","z":"4c839c6278082f14","name":"","entityConfig":"ac792192f3222aa7","version":0,"state":"payload.data.currentWaterTempValue","stateType":"msg","attributes":[{"property":"averageMonthlyProduction","value":"payload.data.averageMonthlyProduction","valueType":"msg"},{"property":"currentPhValue","value":"payload.data.currentPhValue","valueType":"msg"},{"property":"currentWaterTempValue","value":"payload.data.currentWaterTempValue","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":590,"y":180,"wires":[[]]},{"id":"7ef5a641.f52e58","type":"server","name":"Home Assistant","addon":true},{"id":"ac792192f3222aa7","type":"ha-entity-config","server":"4ea31fbab0fab66e","deviceConfig":"dd382125d8e499b2","name":"valeurX","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"tonsensor"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"entity_picture","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"4ea31fbab0fab66e","type":"server","name":"Home Assistant","version":5,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"dd382125d8e499b2","type":"ha-device-config","name":"tonsensor","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""}]
1 « J'aime »

Top merci bcp,
Il y a tellement de chose a apprendre avec HA et node red

Bonjour,

Je déterre le sujet car j’ai un problème similaire.

D’habitude je m’en sors assez bien mais là je bloque sur un truc :frowning:

Voici le JSON:

Je voudrais récupérer la valeur: prix_valeur

J’ai tenté une fonction avec:

msg.payload = msg.payload.records.0.fields.prix_valeur

mais ça ne passe pas.

Une idée ?

Merci.

Un change node suffit. Pas besoin de fonction. Là, le problème est l’utilisation de 0 comme clé de json. C’est interdit.
Un truc comme ça msg.payload.records[0].fields.prix_valeur doit marcher.

Il y a une manière simple de connaitre le chemin pour accéder à la valeur désirée.
Dans la partie debug, à droite de la variable, il y a des icones qui s’affichent. Il suffit de cliquer sur la 1ère (copy path) pour avoir le chemin complet.
Regarde juste la démo ci-dessous pour comprendre. C’est plus efficace qu’un texte

démo1

1 « J'aime »

@golfvert : merci ça fonctionne, j’ai eu l’illumination de mettre le 0 entre [ ] pendant que je faisais la vaisselle.

@jean-luc1203 : merci pour l’astuce, je ne connaissais pas.