White series Fan Canopy and 2 in 1 Switch HomeKit config

OK… Hoping y’all can help me here. I have the fan/light canopy and the switch hooked up, thanks to Bry’s help. My setup here…

Now I have questions!

  1. I have the config button turn on the fan to 25% if it is off, and turn off if it is on.
    Then I have coded the double-press to cycle the speed up to 100 in 4 steps.
Get Fan Rotation Speed
If Rotation speed less than 25
  set Fan to 25
otherwise 
if Fan Rotation speed is less than 50
 set Fan to 50
otherwise
if Fan Rotation speed is less than 75
  set Fan to 75
otherwise 
  set Fan to 100
endif endif endif 
    

It works... is there a more elegant way to do it?