How do I filter node-red output before writing it to a file?

I have this log entry created by a write-file-node, but I only need some parts of it. How do I filter them before they are written to a file? The parts I need are:

  1. payload[0].DateTime which I think is gonna output the date like "2024-06-26T22:00:00+02:00" so I’d also need something like “Date & Time:” written before it for more coherency in the log file.
    And I’d like to know how to do a new line before writing another entry such as:
  2. payload[1].DateTime

You’d stick a change node before it and change the payload to something else using JSONata. A new line can be inserted with “\n”.

How do I insert words like “Date & Time:” that are not in the data?
Why is there no output in my log file? I’m not finding good documentation for this.
chrome_2024-07-05_22-46-51

[{"DateTime":"2024-07-05T23:00:00+02:00","EpochDateTime":1720213200,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":18,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":18,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"RealFeelTemperatureShade":{"Value":18,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"WetBulbTemperature":{"Value":15.4,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":16.6,"Unit":"C","UnitType":17},"DewPoint":{"Value":13.4,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":7.4,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":204,"Localized":"SSW","English":"SSW"}},"WindGust":{"Speed":{"Value":16.7,"Unit":"km/h","UnitType":7}},"RelativeHumidity":74,"IndoorRelativeHumidity":66,"Visibility":{"Value":16.1,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":5,"ThunderstormProbability":0,"RainProbability":5,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":98,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=1&hbhhour=23&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=1&hbhhour=23&unit=c&lang=en-us"},{"DateTime":"2024-07-06T00:00:00+02:00","EpochDateTime":1720216800,"WeatherIcon":38,"IconPhrase":"Mostly cloudy","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":17.1,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":17,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"RealFeelTemperatureShade":{"Value":17,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"WetBulbTemperature":{"Value":15,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":17.3,"Unit":"C","UnitType":17},"DewPoint":{"Value":13.3,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":7.4,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":195,"Localized":"SSW","English":"SSW"}},"WindGust":{"Speed":{"Value":14.8,"Unit":"km/h","UnitType":7}},"RelativeHumidity":78,"IndoorRelativeHumidity":65,"Visibility":{"Value":16.1,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":5,"ThunderstormProbability":0,"RainProbability":5,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":77,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=0&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=0&unit=c&lang=en-us"},{"DateTime":"2024-07-06T01:00:00+02:00","EpochDateTime":1720220400,"WeatherIcon":36,"IconPhrase":"Intermittent clouds","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":16.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":16,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":16,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":14.6,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":17.2,"Unit":"C","UnitType":17},"DewPoint":{"Value":13.2,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":7.4,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":171,"Localized":"S","English":"S"}},"WindGust":{"Speed":{"Value":14.8,"Unit":"km/h","UnitType":7}},"RelativeHumidity":83,"IndoorRelativeHumidity":65,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":3,"ThunderstormProbability":0,"RainProbability":3,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":56,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=1&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=1&unit=c&lang=en-us"},{"DateTime":"2024-07-06T02:00:00+02:00","EpochDateTime":1720224000,"WeatherIcon":35,"IconPhrase":"Partly cloudy","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":15.3,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":15.2,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":15.2,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":14.1,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":16.5,"Unit":"C","UnitType":17},"DewPoint":{"Value":13.1,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":7.4,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":143,"Localized":"SE","English":"SE"}},"WindGust":{"Speed":{"Value":14.8,"Unit":"km/h","UnitType":7}},"RelativeHumidity":86,"IndoorRelativeHumidity":64,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":0,"ThunderstormProbability":0,"RainProbability":0,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":34,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=2&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=2&unit=c&lang=en-us"},{"DateTime":"2024-07-06T03:00:00+02:00","EpochDateTime":1720227600,"WeatherIcon":36,"IconPhrase":"Intermittent clouds","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":14.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":14.3,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":14.3,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":13.6,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":15.9,"Unit":"C","UnitType":17},"DewPoint":{"Value":13,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":5.6,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":129,"Localized":"SE","English":"SE"}},"WindGust":{"Speed":{"Value":13,"Unit":"km/h","UnitType":7}},"RelativeHumidity":92,"IndoorRelativeHumidity":64,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":0,"ThunderstormProbability":0,"RainProbability":0,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":54,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=3&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=3&unit=c&lang=en-us"},{"DateTime":"2024-07-06T04:00:00+02:00","EpochDateTime":1720231200,"WeatherIcon":36,"IconPhrase":"Intermittent clouds","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":14.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":14.4,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":14.4,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":13.5,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":15.5,"Unit":"C","UnitType":17},"DewPoint":{"Value":12.8,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":5.6,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":131,"Localized":"SE","English":"SE"}},"WindGust":{"Speed":{"Value":11.1,"Unit":"km/h","UnitType":7}},"RelativeHumidity":91,"IndoorRelativeHumidity":63,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":0,"ThunderstormProbability":0,"RainProbability":0,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":74,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=4&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=4&unit=c&lang=en-us"},{"DateTime":"2024-07-06T05:00:00+02:00","EpochDateTime":1720234800,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":false,"Temperature":{"Value":14.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":14.4,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":14.4,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":13.3,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":14.2,"Unit":"C","UnitType":17},"DewPoint":{"Value":12.5,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":5.6,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":134,"Localized":"SE","English":"SE"}},"WindGust":{"Speed":{"Value":11.1,"Unit":"km/h","UnitType":7}},"RelativeHumidity":90,"IndoorRelativeHumidity":62,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":1,"ThunderstormProbability":0,"RainProbability":1,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":94,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":0,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=5&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=5&unit=c&lang=en-us"},{"DateTime":"2024-07-06T06:00:00+02:00","EpochDateTime":1720238400,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":true,"Temperature":{"Value":14.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":14.7,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":14.7,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":13.5,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":14.4,"Unit":"C","UnitType":17},"DewPoint":{"Value":12.8,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":5.6,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":144,"Localized":"SE","English":"SE"}},"WindGust":{"Speed":{"Value":11.1,"Unit":"km/h","UnitType":7}},"RelativeHumidity":91,"IndoorRelativeHumidity":63,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":0,"UVIndexText":"Low","PrecipitationProbability":1,"ThunderstormProbability":0,"RainProbability":1,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":93,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":40.3,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=6&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=6&unit=c&lang=en-us"},{"DateTime":"2024-07-06T07:00:00+02:00","EpochDateTime":1720242000,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":true,"Temperature":{"Value":15.2,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":15.9,"Unit":"C","UnitType":17,"Phrase":"Cool"},"RealFeelTemperatureShade":{"Value":15.9,"Unit":"C","UnitType":17,"Phrase":"Cool"},"WetBulbTemperature":{"Value":14.3,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":15.3,"Unit":"C","UnitType":17},"DewPoint":{"Value":13.5,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":7.4,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":154,"Localized":"SSE","English":"SSE"}},"WindGust":{"Speed":{"Value":13,"Unit":"km/h","UnitType":7}},"RelativeHumidity":90,"IndoorRelativeHumidity":66,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":1,"UVIndexText":"Low","PrecipitationProbability":4,"ThunderstormProbability":0,"RainProbability":4,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":93,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":83.4,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=7&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=7&unit=c&lang=en-us"},{"DateTime":"2024-07-06T08:00:00+02:00","EpochDateTime":1720245600,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":true,"Temperature":{"Value":17.5,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":18.1,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"RealFeelTemperatureShade":{"Value":17,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"WetBulbTemperature":{"Value":15.5,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":16.9,"Unit":"C","UnitType":17},"DewPoint":{"Value":14.1,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":9.3,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":168,"Localized":"SSE","English":"SSE"}},"WindGust":{"Speed":{"Value":13,"Unit":"km/h","UnitType":7}},"RelativeHumidity":80,"IndoorRelativeHumidity":68,"Visibility":{"Value":11.3,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":1,"UVIndexText":"Low","PrecipitationProbability":15,"ThunderstormProbability":3,"RainProbability":15,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":92,"Evapotranspiration":{"Value":0,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":139.6,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=8&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=8&unit=c&lang=en-us"},{"DateTime":"2024-07-06T09:00:00+02:00","EpochDateTime":1720249200,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":true,"Temperature":{"Value":19.1,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":19,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"RealFeelTemperatureShade":{"Value":17.7,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"WetBulbTemperature":{"Value":16.4,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":17.8,"Unit":"C","UnitType":17},"DewPoint":{"Value":14.4,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":11.1,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":195,"Localized":"SSW","English":"SSW"}},"WindGust":{"Speed":{"Value":18.5,"Unit":"km/h","UnitType":7}},"RelativeHumidity":74,"IndoorRelativeHumidity":70,"Visibility":{"Value":16.1,"Unit":"km","UnitType":6},"Ceiling":{"Value":5700,"Unit":"m","UnitType":5},"UVIndex":1,"UVIndexText":"Low","PrecipitationProbability":15,"ThunderstormProbability":3,"RainProbability":15,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":94,"Evapotranspiration":{"Value":0.3,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":148.8,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=9&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=9&unit=c&lang=en-us"},{"DateTime":"2024-07-06T10:00:00+02:00","EpochDateTime":1720252800,"WeatherIcon":7,"IconPhrase":"Cloudy","HasPrecipitation":false,"IsDaylight":true,"Temperature":{"Value":20.8,"Unit":"C","UnitType":17},"RealFeelTemperature":{"Value":20.9,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"RealFeelTemperatureShade":{"Value":19.1,"Unit":"C","UnitType":17,"Phrase":"Pleasant"},"WetBulbTemperature":{"Value":17.3,"Unit":"C","UnitType":17},"WetBulbGlobeTemperature":{"Value":18.8,"Unit":"C","UnitType":17},"DewPoint":{"Value":14.9,"Unit":"C","UnitType":17},"Wind":{"Speed":{"Value":14.8,"Unit":"km/h","UnitType":7},"Direction":{"Degrees":209,"Localized":"SSW","English":"SSW"}},"WindGust":{"Speed":{"Value":24.1,"Unit":"km/h","UnitType":7}},"RelativeHumidity":69,"IndoorRelativeHumidity":69,"Visibility":{"Value":16.1,"Unit":"km","UnitType":6},"Ceiling":{"Value":9144,"Unit":"m","UnitType":5},"UVIndex":2,"UVIndexText":"Low","PrecipitationProbability":19,"ThunderstormProbability":3,"RainProbability":19,"SnowProbability":0,"IceProbability":0,"TotalLiquid":{"Value":0,"Unit":"mm","UnitType":3},"Rain":{"Value":0,"Unit":"mm","UnitType":3},"Snow":{"Value":0,"Unit":"cm","UnitType":4},"Ice":{"Value":0,"Unit":"mm","UnitType":3},"CloudCover":96,"Evapotranspiration":{"Value":0.3,"Unit":"mm","UnitType":3},"SolarIrradiance":{"Value":135.1,"Unit":"W/m²","UnitType":33},"MobileLink":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=10&unit=c&lang=en-us","Link":"http://www.accuweather.com/en/de/oberursel/61440/hourly-weather-forecast/173609?day=2&hbhhour=10&unit=c&lang=en-us"}]

[{"id":"b20c4777490192e4","type":"change","z":"a5fc1698.8bc088","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Date & Time:","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"DateTime[0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":220,"wires":[["589772bfc9ac9001"]]}]

Using JSONata as J: expression in the Change Node

"Date & Time: " & payload[0].DateTime & "\n" & "Date & Time " & payload[1].DateTime

Please note that multiple Set operations in a Change node are cascaded and applied in order. Your first sets msg.payload to “Date & Time:”. Your second then attempts to use JSONata applied to the input JSON in msg.payload, but the input msg.payload has now been replaced by the previous expression (thus wiping the original msg.payload for good…)

JSONata is actually well documented. You can find out about it at

https://docs.jsonata.org/overview.html

which is the official, complete, and only documentation required, although I might challenge anyone to actually learn this language in less than six months.

Since JSONata is so well integrated into Node-RED, and since it is available within the Home Assistant WebSocket nodes, there is an additional ‘primer’ to the language available at

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata/jsonata-primer.html

and this focuses on how to use JSONata in the WebSocket nodes. It does include examples using the Change Node, and you will find the & JSONata string concatenator operator in both sets of documentation.

For most JSONata development, you can use the https://try.jsonata.org/ online development tool.

Here you copy-paste your entire message object (use debug and complete message) on the left as the input JSON object.
You write your code (JSONata expression) on the top right.
The result appears on the lower right.

You can copy-paste the expression back into Node-RED.
It is that easy.

Caution:
In Linux the new line character is denoted by \n as an escaped character, and this can usually be directly added to strings. In some cases you may need \r\n being return-newline as a pair, but it very much depends on the generating and consuming system. Try & "\n" and see if it works…

1 Like

This is my current JSONata code in node-red:

"Date: " & $now('[M01]/[D01]/[Y0001]') & " time: " & $toMillis(payload[0].DateTime) ~> $fromMillis('[H01]:[m01]') & " | Humidity: " & payload[0].RelativeHumidity &  " %" & "\n"

and I’m getting an error: “Invalid JSONata expression: Context value is not a compatible type with argument 1 of function “fromMillis””

$toMillis(payload[0].DateTime) ~> $fromMillis('[H01]:[m01]') works in isolation but not in conjunction with other code in the same JSONata element.

JSONata is evaluated as an expression.

All expressions in any computer language have operator precedence and an order of evaluation.

The ~> function chaining operator is low down on the precedence list, and the expression is evaluated left to right, hence the entire string on the left of the operator is built first, with the function $toMillis() returning a number, and the & string concatenator operator converting this to a string.

The next $fromMillis() function call has no first input argument, therefore requires this value to come from context, and this must be a number, but is now the string “Date: 07/06/2024 time: 1720213200000”. Hence the error - the value now in context being passed as the first argument is a string and this is not compatible with the function requiring a number.

You can easily fix this by placing the working $toMillis() ~> $fromMillis() part inside ( ) which has the highest order of precedence and will always be evaluated first.

"Date: " & $now('[M01]/[D01]/[Y0001]') & " time: " & ($toMillis(payload[0].DateTime) ~> $fromMillis('[H01]:[m01]')) & " | Humidity: " & payload[0].RelativeHumidity &  " %" & "\n"

The function chaining operator ~> is very useful for visual clarity, however nesting the functions would solve the problem directly.

"Date: " & $now('[M01]/[D01]/[Y0001]') & " time: " & $fromMillis($toMillis(payload[0].DateTime),'[H01]:[m01]') & " | Humidity: " & payload[0].RelativeHumidity &  " %" & "\n"

Functions such as $fromMillis() will be evaluated first, and in the reverse order of the depth of nesting of the ( ) pairs. This is just the basic rules of how any computer language deals with expressions.

Now I am already guessing what you are going to ask next, which is ‘why is my time wrong?

If we look at your input data we see

  "payload": [
    {
      "DateTime": "2024-07-05T23:00:00+02:00",
      "EpochDateTime": 1720213200,

Point 1. The DateTime is in ISO format, and includes the correct timezone offset. I assume that you live in Germany so currently on Central Europe Summer Time (CEST) which is two hours ahead of UTC.

The time is 23:00 local time, but actually 21:00 in UTC.

When you use $toMillis(payload[0].DateTime) you will get a correctly converted Unix time, which is 1720213200000, but this is always as UTC.

Point 2. You already have this time given in the field EpochDateTime (which is a fancy way of saying Unix millisecond time, in this case Unix seconds).

payload[0].EpochDateTime * 1000 = $toMillis(payload[0].DateTime)

so you could save yourself the effort and use that field directly.

Point 3. When you use $fromMillis() using the Unix (milliseconds) time, you will get an ISO string based on the UTC time, which here is “2024-07-05T21:00:00.000Z”

This will always be in UTC time, not local time, and I suspect that you don’t actually want your time to be 21:00 but rather 23:00.

Note that the time “2024-07-05T21:00:00.000Z” is exactly the same time as “2024-07-05T23:00:00+02:00”.

Solution:
Getting from UTC time to local time in JSONata is tricky, but you already have the local time in the string timestamp!

You can use the following expression to get the string date part

$substringBefore(payload[0].DateTime,"T")

You can use the following expression to get the time part

$substringBefore($substringAfter(payload[0].DateTime,"T"),"+")

The time part can be chopped down to get just hh:mm by using

$substring(payload[0].DateTime,11,5)

The date part, if you really want MM/DD/YYYY, is more difficult, and you cannot use the $toMillis() $fromMillis() since at 01:00:00+02:00 the UTC date you will get will be the day before and therefore wrong!

The following bit of JSONata will pick out the date substring, divide it into parts, and re-join in a different order as MM/DD/YY

($x:=$split($substringBefore(payload[0].DateTime,"T"),"-"); $join([$x[1],$x[2],$x[0]],"/"))

There are many different ways of turning “2024-07-05” into “07/05/2024”, but I have already given you three different solutions so I will leave this as an exercise for anyone to have a go at :wink:. Answers on a post card to…

As this expression is now rather large, it becomes easier to build it in a code block and to use variables, so I am going with

(
    $d:= $split($substringBefore(payload[0].DateTime,"T"),"-");
    $date:= "Date: " & $join([$d[1], $d[2], $d[0]],"/");
    $time:= " time: " & $substring(payload[0].DateTime,11,5);
    $date & $time & " | Humidity: " & payload[0].RelativeHumidity & " %\n"
)

which is giving me “Date: 07/05/2024 time: 23:00 | Humidity: 74 %\n

1 Like