I was also looking for a similar solution, that I was able to do like so.
Can anyone help me with replacing the circled part with one Function nod?
[{"id":"ffb08fd6.0b4dc","type":"server-state-changed","z":"45465411.cc0a6c","name":"Climate is heating?","server":"72b04927.1f5688","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.thermostat","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":110,"y":340,"wires":[["2eb22370.c8995c"]]},{"id":"8f460835.65f018","type":"api-call-service","z":"45465411.cc0a6c","name":"","server":"72b04927.1f5688","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_on","entityId":"fan.second_bedroom_fan","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":280,"wires":[[]]},{"id":"7c4e3419.f4c90c","type":"api-call-service","z":"45465411.cc0a6c","name":"","server":"72b04927.1f5688","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_off","entityId":"fan.second_bedroom_fan","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":820,"y":400,"wires":[[]]},{"id":"2eb22370.c8995c","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"eq","v":"heating","vt":"str"},{"t":"eq","v":"idle","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":340,"wires":[["c9c1c605.1f3b58","229eac34.017734"],["4b4c4d59.346b24"]]},{"id":"c9c1c605.1f3b58","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"neq","v":"data.old_state.attributes.hvac_action","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":280,"wires":[["8f460835.65f018"]]},{"id":"4b4c4d59.346b24","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"neq","v":"data.old_state.attributes.hvac_action","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":400,"wires":[["a0cd550d.4744f8"]]},{"id":"a0cd550d.4744f8","type":"trigger","z":"45465411.cc0a6c","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"10","extend":false,"units":"min","reset":"stop","bytopic":"all","name":"","x":630,"y":400,"wires":[["7c4e3419.f4c90c"]],"icon":"node-red/timer.svg"},{"id":"229eac34.017734","type":"change","z":"45465411.cc0a6c","name":"stop timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":340,"wires":[["a0cd550d.4744f8"]]},{"id":"72b04927.1f5688","type":"server","z":"","name":"Home Assistant","addon":true}]