I’ve made some modifications to Kabongsteves code as it wasnt working with my node red flows. AC mode was missing for the set state (i.e. would only turn on to previous AC mode, not a new one) and fixed the list of fan and ac modes (dry, fan_only).
All works with the new lovelace default gui.
Thanks to bircoe and kabongsteve.