Switch status via JSON value

I am trying to get a switch created for displaying a module on my MagicMirror. I have the on and off working but I would like to get the status working but am struggling with the nested JSON and getting the state value template to work. Anyone have ideas on how to parse this JSON with a value template?

ON = hidden: false
OFF = hidden:true

If its easier I can reverse the switch be module_hidden to match off with false and on with true if it helps.

Switch YAML

        ##########################################################
        ## MagicMirror Weekend Chore Switch
        ##########################################################

  - platform: command_line
    switches:
      magicmirror_weekend_chores_display:
        command_on: "curl -X GET 'http://192.168.Y.XX:8080/api/module/module_5_MMM-HomeAssistantDisplay/show'"
        command_off: "curl -X GET 'http://192.168.Y.XX:8080/api/module/module_5_MMM-HomeAssistantDisplay/hide'"
#        command_state: "curl -X GET http://192.168.Y.XX:8080/api/module/module_5_MMM-HomeAssistantDisplay/"
#        value_template: "{{ value_json.data.hidden == 'false' }}"


JSON RETURNED ON STATE CALL

{
  "success": true,
  "data": [
    {
      "index": 5,
      "identifier": "module_5_MMM-HomeAssistantDisplay",
      "name": "MMM-HomeAssistantDisplay",
      "path": "modules/MMM-HomeAssistantDisplay/",
      "file": "MMM-HomeAssistantDisplay.js",
      "position": "top_left",
      "configDeepMerge": false,
      "config": {
        "title": "Weekend Chores",
        "host": "XXXXXXXXX",
        "port": 443,
        "useTLS": true,
        "ignoreCert": true,
        "token": "XXXX.XXXXXXX.XXXXX_XXXXX",
        "debuglogging": false,
        "useModuleTigger": false,
        "moduleTriggerTemplate": "",
        "moduleTriggerEntities": false,
        "animationSpeed": 3000,
        "sections": [
          {
            "triggerEntities": [
              "input_boolean.chore_xxx_bedroom_cleaned",
              "input_boolean.chore_xxx_bathroom_cleaned",
              "input_boolean.chore_yyy_bedroom_cleaned",
              "input_boolean.chore_yyy_bathroom_cleaned"
            ],
            "displayTemplate": "\n                {%- if states.input_boolean.chore_xxx_bedroom_cleaned.state == \"off\" -%}\n                <div> <i class='mdi mdi-bed'></i> xxx Bedroom </div>\n                {%- endif -%}\n                {%- if states.input_boolean.chore_xxx_bathroom_cleaned.state == \"off\" -%}\n                <div> <i class='mdi mdi-toilet'></i> xxx Bathroom </div>\n                {%- endif -%}\n                {%- if states.input_boolean.chore_yyy_bedroom_cleaned.state == \"off\" -%}\n                <div> <i class='mdi mdi-bed'></i> yyy Bedroom </div>\n                {%- endif -%}\n                {%- if states.input_boolean.chore_yyy_bathroom_cleaned.state == \"off\" -%}\n                <div> <i class='mdi mdi-toilet'></i> yyy Bathroom </div>\n                {%- endif -%}                  \n                ",
            "class": "ha-name",
            "render": "<div> <i class='mdi mdi-bed'></i> xxx Bedroom </div><div> <i class='mdi mdi-toilet'></i> xxx Bathroom </div><div> <i class='mdi mdi-bed'></i> yyy Bedroom </div><div> <i class='mdi mdi-toilet'></i> yyy Bathroom </div>"
          }
        ],
        "class": "chores",
        "identifier": "module_5_MMM-HomeAssistantDisplay"
      },
      "classes": "MMM-HomeAssistantDisplay",
      "hidden": true,
      "lockStrings": [
        "module_13_MMM-Remote-Control"
      ]
    }
  ]
}```

You can play with the json in Dev Tools/templates:

ā€¦

Oh nice, I forgot about the built in tools. I see I was close, I had a variation with [0] but not like you have it. It makes sense. I will play with that area and give that a try. Thank you.

Posting the final config in case others have a need for the plugin and use case. Thanks again, using the editor saved a lot of pushes and restarts.

        ##########################################################
        ## MagicMirror Weekend Chore Switch
        ##########################################################

  - platform: command_line
    switches:
      magicmirror_weekend_chores_display:
        command_on: "curl -X GET 'http://192.168.X.YY:8080/api/module/module_5_MMM-HomeAssistantDisplay/show'"
        command_off: "curl -X GET 'http://192.168.X.YY:8080/api/module/module_5_MMM-HomeAssistantDisplay/hide'"
        command_state: "curl -X GET http://192.168.X.YY:8080/api/module/module_5_MMM-HomeAssistantDisplay/"
        value_template: "{{ value_json.data[0].hidden == false }}"
1 Like