Since this is a tricky problem to solve, I built a quick fix solution while I work on the "real" version. The quick fix measures the average indoor temperature in the house using zigbee sensors and uses a number of weather forecast APIs to calculate the amount of heat lost from the house in a day based on the difference of outdoor / indoor temperature and the amount of solar irradiation. It runs at midnight and creates a 24h schedule based on the forecast energy price and expected COP. The heat pump is controlled with a relay from an ESP32. The algorithm/app runs on a raspberry pi and is written in Rust.
It worked surprisingly well last winter with some tweaking needed during very cold periods. And the heat pump only switches a few times per day now and makes very long efficient runs, theoretically greatly increasing its lifespan and simultaneously reducing my energy bill.
I'm still planning on building the better version I had planned based on a thermal model of my house, but that will require more studying and now that the quick&dirty version works so well the pressure is off a bit.