It helps everyone when you use the </>
code tags (for YAML, Node-RED code, and data structures).
{"weather.forecast_home":{"forecast":[{"condition":"rainy","datetime":"2024-07-16T11:00:00+00:00","wind_bearing":307.9,"temperature":21,"templow":14.7,"wind_speed":19.1,"precipitation":1.8,"humidity":65},{"condition":"cloudy","datetime":"2024-07-17T11:00:00+00:00","wind_bearing":236.4,"temperature":21.1,"templow":12.1,"wind_speed":14.4,"precipitation":0.1,"humidity":68},{"condition":"cloudy","datetime":"2024-07-18T11:00:00+00:00","wind_bearing":215.1,"temperature":23.7,"templow":14,"wind_speed":14.4,"precipitation":0,"humidity":62},{"condition":"cloudy","datetime":"2024-07-19T11:00:00+00:00","wind_bearing":246.3,"temperature":21.8,"templow":13.2,"wind_speed":12.6,"precipitation":0.1,"humidity":70},{"condition":"cloudy","datetime":"2024-07-20T11:00:00+00:00","wind_bearing":197.3,"temperature":21.7,"templow":16.6,"wind_speed":18.4,"precipitation":3.7,"humidity":74},{"condition":"rainy","datetime":"2024-07-21T11:00:00+00:00","wind_bearing":319,"temperature":20.8,"templow":16.8,"wind_speed":20.9,"precipitation":4.5,"humidity":70}]}}
Note: I use a different weather provider, so my data object will not match yours, and does not have precipitation_probability.
This is a wonderful JSON data structure, and if we look at just the first part, an array of objects nested in a two-layer object:
{
"weather.forecast_home": {
"forecast": [
{
"condition": "rainy",
"datetime": "2024-07-16T11:00:00+00:00",
"wind_bearing": 307.9,
"temperature": 21,
"templow": 14.7,
"wind_speed": 19.1,
"precipitation": 1.8,
"humidity": 65
},
Your simple question has multiple facets.
First:
Since the top object key contains a special character, reference using JavaScript is certainly payload["weather.openweathermap"].forecast[0].precipitation
, however if you are using JSONata (J: expression) the reference would be
payload.'weather.openweathermap'.forecast[0].precipitation
or (payload.**.precipitation)[0]
works just as well.
Second:
Weather comes now from a service call, and we can use this service in both Node-RED and in Home Assistant. If you are looking to get the data in Node-RED and then put it back into Home Assistant (in an input_helper) why not just do this in Home Assistant, using a trigger based automation? No need to involve Node-RED at all!
Third:
Why use an input_helper to store your value? Input based sensors are special in that we (humans) can input stuff by changing their values in the dashboard, but if you are working in Node-RED you can use any of the WebSocket entity (sensor) nodes to create and maintain both the state value and attributes of a sensor of your choice.
If you are going to use the data in HA, then it would be better to do everything in HA.
If you are going to use the data in another Node-RED flow, then why not call the service, get the data, and use it immediately? Is there really a need to save the data anywhere?
If you are going to use the data in Node-RED only, then you can save this in Context, and then read it back again when you want it. Context store is a powerful way to save data without having to save to file or Home Assistant.
A solution:
Assuming that you want to read the weather forecast in Node-RED, and then save it to Home Assistant (so you can access it in HA and also in Node-RED) the following flow might provide you with some ideas.
You will have to change the service call entity_id to your weather forecast, and you can play around with the names I have used in the sensor. The flow gets the weather, uses a bit of JSONata to build a new object with just the bits we want, and then a Sensor entity node to write the precipitation to the state value, and the precipitation probability to an attribute. You can, of course, have two sensor nodes, one for the rain and another for the probability if you wish.
I have also added a save of the ‘rain object’ to flow context. If you plan to use this in Node-RED only (and don’t need the values back in Home Assistant) then you can drop the Sensor node (and the configuration node behind it) completely, and just read back the flow context variable ‘Rain’.
Here is the basic flow
[{"id":"46067599524f8de5","type":"api-call-service","z":"7021f7d89ccb8403","name":"","server":"","version":5,"debugenabled":false,"domain":"weather","service":"get_forecasts","areaId":[],"deviceId":[],"entityId":["weather.forecast_home"],"data":"{\"type\": \"daily\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":440,"y":2700,"wires":[["c14743f79f67a3de"]]},{"id":"c14743f79f67a3de","type":"change","z":"7021f7d89ccb8403","name":"Extract precipitation","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"rain_now\": (payload.**.precipitation)[0], \"rain_chance\": (payload.**.precipitation_probability)[1]}","tot":"jsonata"},{"t":"set","p":"Rain","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":2700,"wires":[["1f834b10f5498869"]]},{"id":"1f834b10f5498869","type":"ha-sensor","z":"7021f7d89ccb8403","name":"Rain","entityConfig":"1c295f2ff52050b6","version":0,"state":"payload.rain_now","stateType":"msg","attributes":[{"property":"chance","value":"payload.rain_chance","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":850,"y":2700,"wires":[["f2672103f97e8d6f"]],"server":""},{"id":"1c295f2ff52050b6","type":"ha-entity-config","server":"","deviceConfig":"","name":"SC Weather Rain","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Weather Rain"},{"property":"icon","value":""},{"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}]
I hope this resolves your impasse and gives you some ideas ! Good luck with your watering project.
(I also hope it works too as I can’t fully test it against your data)