HELP modifying array with a YAML template

Hi guys

I have this forecast data attribute whithin a sensor, it’s an array:

forecast:
  - condition: rainy
    precipitation_probability: 100
    temperature: 21
    templow: 11
    datetime: '2022-06-02T22:00:00+00:00'
    wind_speed: 5
    wind_bearing: 315
  - condition: rainy
    precipitation_probability: 100
    temperature: 20
    templow: 11
    datetime: '2022-06-03T22:00:00+00:00'
    wind_speed: 10
    wind_bearing: 315
  - condition: rainy
    precipitation_probability: 100
    temperature: 20
    templow: 11
    datetime: '2022-06-04T22:00:00+00:00'
    wind_speed: 15
    wind_bearing: 225
  - condition: rainy
    precipitation_probability: 90
    temperature: 20
    templow: 10
    datetime: '2022-06-05T22:00:00+00:00'
    wind_speed: 15
    wind_bearing: 180
  - condition: cloudy
    precipitation_probability: 30
    temperature: 22
    templow: 11
    datetime: '2022-06-06T22:00:00+00:00'
    wind_speed: 5
    wind_bearing: 270
  - condition: cloudy
    precipitation_probability: 5
    temperature: 23
    templow: 11
    datetime: '2022-06-07T22:00:00+00:00'
    wind_speed: 15
    wind_bearing: 225

I’d like get this array, replace every 22:00 with 00:00 and then select only the values whose date is the same as today or after today.

Thanks in advanced

I would think it’s easier to do this in a function node in Node red. Probably possible in yaml also.

Give this a try:

[{"id":"1e41268eef50e68b","type":"function","z":"ebaa69a9.649708","name":"","func":"var array = {};\n\nconst today = new Date();\ntoday.setHours(23, 59, 59, 998);\n\n\nfor (var index in msg.data.attributes.forecast) {\n    msg.data.attributes.forecast[index].datetime = msg.data.attributes.forecast[index].datetime.replace(\"T22\", \"T00\");\n    \n    if (new Date(msg.data.attributes.forecast[index].datetime) > today){\n        array[index] = msg.data.attributes.forecast[index];\n    }\n}\n\nmsg.arr = array;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":1880,"wires":[["051f60ed58bb9d1e"]]},{"id":"a0b23ca261fac2ad","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"weather.smhi_home","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":420,"y":1880,"wires":[["1e41268eef50e68b"]]},{"id":"051f60ed58bb9d1e","type":"debug","z":"ebaa69a9.649708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":1860,"wires":[]},{"id":"d561fc9281471daa","type":"inject","z":"ebaa69a9.649708","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1880,"wires":[["a0b23ca261fac2ad"]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Just change the entity id in the current state node.
The output is msg.arr

It’s easy peasy in NR, I have it done. I’m just curious how this would be achieved in yaml :slight_smile:. I appreciate