Hi i did not read your issue as i dont know to write rules
but first thing that came into my head when you said my first rule
was this post, i am not using code for rules , but in the post below
you will get your head around, how write very good code based on patterns already wreitten by some genuis
another thing that came to my head is node red, as you said this is your first rule, so you dont need to do any migration just startā¦
if you are Code noob like me you will find it very useful, i advise spending some time learing node red