You can Make a custom engineering update (lets call it E ability)
put it in a disabled spell book and give that spell book to your hero
in Level 1 it turns B to A (B is the one at lower than % or whatever its)
in Level 2 it turns A to B
When Unit Learns Ability
If its C ability(the one allows you to change abilities)
Add it to YHTA group
Every Second
Pick Every Units in YHTA group
if Picked Units Health is Bellow %(35+(Level of C for Picked Unit)*10)
then
Set Level of E for Picked Unit to 2
else
Set Level of E for Picked Unit to 1
simple no jass no leaks