Expression not returning expected valuebut only for ON and OFF keyword

Welcome to the forum.
Please see Wiki - how to post code on this forum.