Automation "between time" Problem

I’m trying to make an automation to start at 5:00 am an keep running the automation till 7:00 am between that time if a temperature is below 40ºC it turns on a switch, if not, does nothing, but if it turn on the switch it should be continuously check the temperatura till it reaches 40ºC after that it turn off the switch

i had this in node red but here I’m having a trouble make it run between that time because it let’s the temperature rise above 40ºC and I had to make another automation to force it to turn off.

can anyone help me to solved this

I’ve lost count of how many times people have asked for the same thing and the answer remains the same: use the Generic Thermostat integration to control heating and create a simple automation, that uses Time Triggers, to turn the Generic Thermostat on/off at the desired times.

Let me know if you need help configuring the Generic Thermostat or composing the automation.