Im successfully using the following, to populate a list of items as switches. This works great but if you want to use a Dimmer, which also has an ON/OFF, effectively still a switch, the code fails.
Just a guess here but have you tried a value of 0 instead of OFF. If I’m right dimmer items can accept ON or Off as commands but interpret them as 100 or 0. So 0 might be the State value the RestApi gives you for a switched off dimmer and you have to use that to check.
Best regards Johannes