Automating Climate (AC and heating) based on external temp sensor

Hello, I have Window AC/Heating unit that I have added to Home assistant using the Midea Integration.

I want to keep the room in a range of temperature so have tried making an automation that uses a separate external temperature sensor and turns on/off the AC and heating based on it.

It “works” but its too finicky, the unit will sometimes turn on for 5 seconds and then turn off, or vice versa. And sometimes it stays on for a long time, making the temperature go beyond what I want.

I use mainly Node-red for my automations, but im OK with using the integrated system in home assistant.

Does anyone have experience with something like this?

Have a look at the Generic Thermostat integration

There are Blueprints from the Community in the Blueprints Exchange - Home Assistant Community that adjust thermostats based on an external temp sensor. You may want to look at some of those to either use as is ot take control of and pull parts out for your Automation as well.