{
  "uid": "psut-greenhouse",
  "title": "Greenhouse",
  "description": "© 2026/2027 Dr. Mohammad Alja'afreh · PSUT IoT Engineering Learning Platform · Lab 44",
  "tags": [
    "psut",
    "iot"
  ],
  "timezone": "browser",
  "schemaVersion": 39,
  "version": 1,
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "refresh": "10s",
  "editable": true,
  "templating": {
    "list": [
      {
        "name": "node",
        "label": "Node",
        "type": "query",
        "datasource": {
          "type": "influxdb",
          "uid": "influx-greenhouse"
        },
        "refresh": 1,
        "query": "import \"influxdata/influxdb/schema\"\nschema.tagValues(bucket: \"greenhouse\", tag: \"node\")",
        "current": {
          "text": "pi-01",
          "value": "pi-01"
        },
        "sort": 1
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Temperature now",
      "description": "Newest reading; orange from 28 °C, red from 30 °C (the fan thresholds).",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 0,
        "y": 0,
        "w": 6,
        "h": 5
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"environment\" and r._field == \"temperature\" and r.node == \"${node}\")\n  |> last()"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "celsius",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "orange",
                "value": 28
              },
              {
                "color": "red",
                "value": 30
              }
            ]
          },
          "color": {
            "mode": "thresholds"
          },
          "decimals": 1
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "colorMode": "background",
        "graphMode": "none",
        "textMode": "value"
      }
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Humidity now",
      "description": "",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 6,
        "y": 0,
        "w": 6,
        "h": 5
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"environment\" and r._field == \"humidity\" and r.node == \"${node}\")\n  |> last()"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "orange",
                "value": null
              },
              {
                "color": "green",
                "value": 40
              },
              {
                "color": "orange",
                "value": 80
              }
            ]
          },
          "color": {
            "mode": "thresholds"
          },
          "decimals": 1
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "colorMode": "background",
        "graphMode": "none",
        "textMode": "value"
      }
    },
    {
      "id": 3,
      "type": "gauge",
      "title": "Soil moisture",
      "description": "Pump switches ON below 35 % and OFF above 45 %.",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 12,
        "y": 0,
        "w": 6,
        "h": 5
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"environment\" and r._field == \"soil_moisture\" and r.node == \"${node}\")\n  |> last()"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "orange",
                "value": 35
              },
              {
                "color": "green",
                "value": 45
              }
            ]
          },
          "color": {
            "mode": "thresholds"
          },
          "min": 0,
          "max": 100,
          "decimals": 1
        },
        "overrides": []
      },
      "options": {
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showThresholdMarkers": true
      }
    },
    {
      "id": 4,
      "type": "timeseries",
      "title": "Temperature (mean per interval)",
      "description": "",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 0,
        "y": 5,
        "w": 12,
        "h": 9
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"environment\" and r._field == \"temperature\" and r.node == \"${node}\")\n  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "celsius",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "orange",
                "value": 28
              },
              {
                "color": "red",
                "value": 30
              }
            ]
          },
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "drawStyle": "line",
            "lineWidth": 2,
            "pointSize": 4,
            "showPoints": "auto",
            "thresholdsStyle": {
              "mode": "line+area"
            }
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      }
    },
    {
      "id": 5,
      "type": "timeseries",
      "title": "Soil moisture (mean per interval)",
      "description": "",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 12,
        "y": 5,
        "w": 12,
        "h": 9
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"environment\" and r._field == \"soil_moisture\" and r.node == \"${node}\")\n  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "percent",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": null
              },
              {
                "color": "orange",
                "value": 35
              },
              {
                "color": "green",
                "value": 45
              }
            ]
          },
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "drawStyle": "line",
            "lineWidth": 2,
            "pointSize": 4,
            "showPoints": "auto",
            "thresholdsStyle": {
              "mode": "line+area"
            }
          }
        },
        "overrides": []
      },
      "options": {
        "legend": {
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      }
    },
    {
      "id": 6,
      "type": "state-timeline",
      "title": "Fan and pump",
      "description": "Each controller decision from Lab 42.",
      "datasource": {
        "type": "influxdb",
        "uid": "influx-greenhouse"
      },
      "gridPos": {
        "x": 18,
        "y": 0,
        "w": 6,
        "h": 5
      },
      "targets": [
        {
          "refId": "A",
          "datasource": {
            "type": "influxdb",
            "uid": "influx-greenhouse"
          },
          "query": "from(bucket: \"greenhouse\")\n  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n  |> filter(fn: (r) => r._measurement == \"actuator\" and r._field == \"state\" and r.node == \"${node}\")\n  |> keep(columns: [\"_time\", \"_value\", \"device\"])"
        }
      ],
      "fieldConfig": {
        "defaults": {
          "unit": "",
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "blue",
                "value": null
              }
            ]
          },
          "color": {
            "mode": "fixed"
          },
          "mappings": [
            {
              "type": "value",
              "options": {
                "0": {
                  "text": "OFF",
                  "color": "blue"
                },
                "1": {
                  "text": "ON",
                  "color": "red"
                }
              }
            }
          ]
        },
        "overrides": []
      },
      "options": {
        "showValue": "auto",
        "mergeValues": true,
        "rowHeight": 0.8
      }
    }
  ]
}
