Comments in Rules JSON

Is there a way to add in comments into a JSON rule? I know it’s not strictly allowed by the JSON standard, but for these hand-jammed rule files, it would make updates and maintenance so much easier. Comments could be ignored on the ST parser side, but that is disabled, as is the other workaround of having “_comment”: “this is a comment” fields, where unrecognized fields are not ignored.

I just tackled my first rule to tie in my Eufy Doorbell (via Alexa) to SmartThings. Eufy sends a motion-detected event to Alexa just fine, but the “no motion detected for X minutes” option in Alexa never fires, so I created a virtual switch to pass the event to SmartThings and created a rule to add in some logic:

if(motionDetected)
    motionDetected - Off
    if(between Sunset/Sunrise)
            Outside - 100%
            Entrance - On
            Wait 5 mins
            Entrance - Off
            if(before 2200)
                Outside 30% (lights are on a simple sunset-2200 schedule)
            else
                Outside - Off

Works great, but 11 lines of pseudo-code ends up being 196 lines of ugly JSON. If I modify it in the future, not having comments and having to cross reference deviceIds against another JSON file just to figure out what’s going on is going to be quite the headache. I can just imagine what more complicated rules will look like.

3 Likes

Welcome to the SmartThings Community, @pacallen!

I asked the team about this, I’ll let you know once I get their feedback.

In case this is helpful: a little hack for “commenting” in JSON

I’m using YAML for my rules in part because I can add comments and name the devices, otherwise I’ll never remember any of it.

Hi, @pacallen
Following up, the team mentioned it’s not supported but there are other tools that can help you out to keep a local copy of the Rules where you can include comments and process them before uploading:

  • hjson allows comments and can easily be translated from hjson to standard json with command line tools
  • JSON.minify just removes comments and whitespace
  • Tools exist to translate other data formats that allow comments into JSON pretty easily. For example, you could use YAML or TOML and convert it to JSON. Just search for “yaml to json” or “toml to json”