{
  "$schema": "./.schemas/page.schema.json",
  "title": "Sprinklers",
  "icon": "sprinkler.and.droplets",
  "sources": {
    "rachio": {
      "url": "https://api.rach.io/1/public/device/YOUR_DEVICE_ID",
      "secret": "rachio",
      "every": "10m",
      "derive": [
        {
          "name": "enabled",
          "value": {
            "count": "zones",
            "where": {
              "path": "enabled",
              "equals": true
            }
          }
        },
        {
          "name": "total",
          "value": {
            "count": "zones"
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "controller",
      "type": "status",
      "label": "Controller",
      "state": "unknown",
      "source": {
        "ref": "rachio",
        "map": {
          "state": {
            "path": "status",
            "values": {
              "ONLINE": "ok",
              "OFFLINE": "critical"
            },
            "default": "warning"
          },
          "detail": {
            "path": "on",
            "values": {
              "true": {
                "template": "{status|lower|title} · schedules on · {enabled} zones enabled"
              },
              "false": {
                "template": "{status|lower|title} · standby, schedules off"
              }
            }
          }
        }
      },
      "actions": [
        {
          "label": "Water front 10m",
          "icon": "drop",
          "method": "PUT",
          "path": "/1/public/zone/start",
          "body": {
            "id": "YOUR_ZONE_ID",
            "duration": 600
          },
          "when": {
            "path": "on",
            "equals": true
          },
          "error": "error"
        },
        {
          "label": "Stop watering",
          "icon": "stop.fill",
          "method": "PUT",
          "path": "/1/public/device/stop_water",
          "body": {
            "id": "YOUR_DEVICE_ID"
          },
          "error": "error"
        }
      ]
    },
    {
      "id": "rain",
      "type": "stat",
      "label": "Rain sensor",
      "value": "—",
      "source": {
        "ref": "rachio",
        "map": {
          "value": {
            "path": "rainSensorTripped",
            "values": {
              "true": "Wet",
              "false": "Dry"
            },
            "default": "No sensor"
          },
          "delta": {
            "path": "paused",
            "values": {
              "true": "Watering paused",
              "false": "Not paused"
            }
          }
        }
      }
    },
    {
      "id": "zones-on",
      "type": "stat",
      "label": "Zones enabled",
      "value": 0,
      "source": {
        "ref": "rachio",
        "map": {
          "value": "enabled",
          "delta": {
            "template": "of {total} zones"
          }
        }
      }
    },
    {
      "id": "zones",
      "type": "list",
      "label": "Enabled zones",
      "items": [],
      "source": {
        "ref": "rachio",
        "map": {
          "items": {
            "each": "zones",
            "where": {
              "path": "enabled",
              "equals": true
            },
            "sort": "zoneNumber",
            "template": "{name} · zone {zoneNumber}",
            "limit": 8
          }
        }
      }
    },
    {
      "id": "open",
      "type": "link",
      "label": "Open Rachio",
      "url": "https://app.rach.io"
    }
  ]
}
