I assume that you wish to apply the map() function to
msg.weather_entity.attributes.forecast
However, msg.weather_entity.attributes does not have a ‘forecast’ key/value in it, and therefore, msg.weather_entity.attributes.forecast will be undefined resulting in your error
The root issue here is that you are attempting to look at the weather_entity (entity) when this is just a target entity and does not carry the actual weather forecast anymore. You need to call the ‘get forecasts’ service against this entity in order to retrieve the current forecast from the returned service call results.
After that, you need to access the returned “weather.forecast_home” object which has a special character in it, so you need the appropriate referencing syntax for this.
After that, you appear to be taking an average (sum / count) of the precipitation_probability. I am not going to question the logic of averaging a probability like this, but there may be easier ways to do this.
I don’t have ‘precipitation_probability’ in my returned weather forecast, but based on ‘precipitation’ which is mm of rain per period, for an hourly weather forecast, the following will return an object with the count of the hours, the total rain over the next 24 hours, the average rain per hour, and the hour periods that it will be raining.
[{"id":"2ade2067a423465b","type":"api-call-service","z":"7021f7d89ccb8403","name":"","server":"ae8c890fd1f09885","version":5,"debugenabled":false,"domain":"weather","service":"get_forecasts","areaId":[],"deviceId":[],"entityId":["weather.forecast_home"],"data":"{\"type\": \"hourly\"}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"queue":"none","x":500,"y":4540,"wires":[["f7c775403e8fd895"]]},{"id":"f7c775403e8fd895","type":"change","z":"7021f7d89ccb8403","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t $rain:=payload.*.forecast.precipitation;\t {\"periods\": $count($rain),\t \"total\": $sum($rain),\t \"average\": $average($rain)~>$round(3),\t \"wet_periods\": $count($rain[$>0])}\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":4540,"wires":[["d1e60d5ca2e90174"]]}]
Please change the service call target weather entity for your own!
Hope that helps.