{
  "context": {
    "name": "InfluxDB",
    "options": {
      "tags": [
        {
          "name": "sourceIP",
          "value": "@bind=webApp.ip();"
        },
        {
          "name": "sourceApp",
          "value": "njspc"
        }
      ]
    }
  },
  "events": [
    {
      "name": "temps",
      "description": "Bind temperatures to measurements",
      "points": [
        {
          "measurement": "ambientTemps",
          "tags": [
            {
              "name": "units",
              "value": "@bind=data.units.desc;"
            }
          ],
          "fields": [
            {
              "name": "airTemp",
              "value": "@bind=data.air;",
              "type": "int"
            },
            {
              "name": "solarTemp",
              "value": "@bind=data.solar;",
              "type": "int"
            },
            {
              "name": "airTempF",
              "value": "@bind=data.air;",
              "type": "float"
            },
            {
              "name": "solarTempF",
              "value": "@bind=data.solar;",
              "type": "float"
            },
            {
              "name": "waterSensor1",
              "value": "@bind=data.waterSensor1;",
              "type": "float"
            },
            {
              "name": "waterSensor2",
              "value": "@bind=data.waterSensor2;",
              "type": "float"
            },
            {
              "name": "waterSensor3",
              "value": "@bind=data.waterSensor3;",
              "type": "float"
            },
            {
              "name": "waterSensor4",
              "value": "@bind=data.waterSensor4;",
              "type": "float"
            }
          ]
        }
      ]
    },
    {
      "name": "body",
      "description": "Bind bodies to measurements",
      "points": [
        {
          "measurement": "bodyTemps",
          "tags": [
            {
              "name": "heatMode",
              "value": "@bind=data.heatMode.desc;"
            },
            {
              "name": "heatStatus",
              "value": "@bind=data.heatStatus.desc;"
            },
            {
              "name": "body",
              "value": "@bind=data.name;"
            }
          ],
          "fields": [
            {
              "name": "@bind=data.name;",
              "value": "@bind=data.temp;",
              "type": "int"
            },
            {
              "name": "@bind=data.name+'F';",
              "value": "@bind=data.temp;",
              "type": "float"
            },
            {
              "name": "@bind=data.name+'.setPoint';",
              "value": "@bind=data.setPoint;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "chemicalDose",
      "points": [
        {
          "measurement": "chemicalDose",
          "description": "Active doses recorded by chemical dosed",
          "series": {
            "value": "@bind=data.start;"
          },
          "tags": [
            {
              "name": "chemical",
              "value": "@bind=data.chem;"
            }
          ],
          "fields": [
            {
              "name": "volumeDosed",
              "value": "@bind=data.volumeDosed;",
              "type": "float"
            },
            {
              "name": "timeDosed",
              "value": "@bind=data.timeDosed;",
              "type": "float"
            },
            {
              "name": "id",
              "value": "@bind=data.id;",
              "type": "int"
            },
            {
              "name": "demand",
              "value": "@bind=data.demand;",
              "type": "float"
            },
            {
              "name": "setpoint",
              "value": "@bind=data.setpoint;",
              "type": "float"
            },
            {
              "name": "method",
              "value": "@bind=data.method;",
              "type": "string"
            },
            {
              "name": "status",
              "value": "@bind=data.status;",
              "type": "string"
            },
            {
              "name": "end",
              "value": "@bind=data.end;",
              "type": "date"
            }
          ]
        }
      ]
    },
    {
      "name": "chemController",
      "vars": {
        "cfg": "@bind=sys.chemControllers.getItemById(data.id).get();"
      },
      "points": [
        {
          "measurement": "chemControllersPh",
          "description": "Bind chemController emit and save pH",
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "dosing status desc",
              "value": "@bind=data.ph.dosingStatus.desc;"
            },
            {
              "name": "dosing method desc",
              "value": "@bind=vars.cfg.ph.dosingMethod.desc;"
            }
          ],
          "fields": [
            {
              "name": "level",
              "value": "@bind=data.ph.level;",
              "type": "float"
            },
            {
              "name": "temperature",
              "value": "@bind=data.ph.probe.temperature;",
              "type": "float"
            },
            {
              "name": "setpoint",
              "value": "@bind=data.ph.setpoint;",
              "type": "float"
            },
            {
              "name": "dosing time",
              "value": "@bind=data.ph.doseTime;",
              "type": "float"
            },
            {
              "name": "pump is dosing",
              "value": "@bind=typeof data.ph.pump.isDosing !== 'undefined'?data.ph.pump.isDosing?1:0:0;",
              "type": "int"
            },
            {
              "name": "lockout",
              "value": "@bind=data.ph.lockout;",
              "type": "boolean"
            },
            {
              "name": "dose time remaining",
              "value": "@bind=data.ph.dosingTimeRemaining;",
              "type": "float"
            },
            {
              "name": "mix time remaining",
              "value": "@bind=data.ph.mixTimeRemaining;",
              "type": "float"
            },
            {
              "name": "delay time remaining",
              "value": "@bind=data.ph.delayTimeRemaining;",
              "type": "float"
            },
            {
              "name": "dose volume",
              "value": "@bind=data.ph.doseVolume;",
              "type": "int"
            },
            {
              "name": "dose volume remaining",
              "value": "@bind=data.ph.dosingVolumeRemaining;",
              "type": "int"
            },
            {
              "name": "tank level",
              "value": "@bind=data.ph.tank.level;",
              "type": "float"
            },
            {
              "name": "tank capacity",
              "value": "@bind=data.ph.tank.capacity;",
              "type": "float"
            },
            {
              "name": "dosing status",
              "value": "@bind=data.ph.dosingStatus.val;",
              "type": "int"
            },
            {
              "name": "dosing method",
              "value": "@bind=vars.cfg.dosingMethod;",
              "type": "int"
            },
            {
              "name": "start delay",
              "value": "@bind=vars.cfg.ph.startDelay;",
              "type": "int"
            },
            {
              "name": "max dosing time",
              "value": "@bind=data.ph.maxDosingTime;",
              "type": "int"
            },
            {
              "name": "max dosing volume",
              "value": "@bind=data.ph.maxDosingVolume;",
              "type": "int"
            },
            {
              "name": "mixing time",
              "value": "@bind=data.ph.mixingTime;",
              "type": "int"
            },
            {
              "name": "flow readings only int",
              "value": "@bind=vars.cfg.ph.flowReadingsOnly?1:0;",
              "type": "int"
            },
            {
              "name": "low tolerance",
              "value": "@bind=vars.cfg.ph.tolerance.low;",
              "type": "int"
            },
            {
              "name": "high tolerance",
              "value": "@bind=vars.cfg.ph.tolerance.high;",
              "type": "int"
            },
            {
              "name": "high threshold",
              "value": "@bind=vars.cfg.ph.tolerance.high;",
              "type": "float"
            },
            {
              "name": "low threshold",
              "value": "@bind=vars.cfg.ph.tolerance.low;",
              "type": "float"
            },
            {
              "name": "tolerance enabled int",
              "value": "@bind=vars.cfg.ph.tolerance.enabled?1:0;",
              "type": "int"
            },
            {
              "name": "dose priority int",
              "value": "@bind=vars.cfg.ph.dosePriority?1:0;",
              "type": "int"
            },
            {
              "name": "flow only mixing int",
              "value": "@bind=vars.cfg.ph.flowOnlyMixing?1:0;",
              "type": "int"
            },
            {
              "name": "max daily volume",
              "value": "@bind=vars.cfg.ph.maxDailyVolume;",
              "type": "int"
            },
            {
              "name": "daily volume dosed",
              "value": "@bind=data.ph.dailyVolumeDosed;",
              "type": "int"
            },
            {
              "name": "volume dosed",
              "value": "@bind=data.ph.volumeDosed;",
              "type": "int"
            },
            {
              "name": "acid demand",
              "value": "@bind=data.ph.demand;",
              "type": "int"
            }
          ]
        },
        {
          "measurement": "chemControllersOrp",
          "description": "Bind chemController emit and save orp",
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "dosing status desc",
              "value": "@bind=data.orp.dosingStatus.desc;"
            },
            {
              "name": "dosing method desc",
              "value": "@bind=vars.cfg.orp.dosingMethod.desc;"
            }
          ],
          "fields": [
            {
              "name": "level",
              "value": "@bind=data.orp.level;",
              "type": "float"
            },
            {
              "name": "setpoint",
              "value": "@bind=data.orp.setpoint;",
              "type": "float"
            },
            {
              "name": "dosing time",
              "value": "@bind=data.orp.doseTime;",
              "type": "float"
            },
            {
              "name": "pump is dosing",
              "value": "@bind=typeof data.orp.pump.isDosing !== 'undefined'?data.orp.pump.isDosing?1:0:0;",
              "type": "int"
            },
            {
              "name": "lockout",
              "value": "@bind=data.orp.lockout;",
              "type": "boolean"
            },
            {
              "name": "pump dose time remaining",
              "value": "@bind=data.orp.dosingTimeRemaining;",
              "type": "float"
            },
            {
              "name": "mix time remaining",
              "value": "@bind=data.orp.mixTimeRemaining;",
              "type": "float"
            },
            {
              "name": "delay time remaining",
              "value": "@bind=data.orp.delayTimeRemaining;",
              "type": "float"
            },
            {
              "name": "dose volume",
              "value": "@bind=data.orp.doseVolume;",
              "type": "int"
            },
            {
              "name": "dose volume remaining",
              "value": "@bind=data.orp.dosingVolumeRemaining;",
              "type": "int"
            },
            {
              "name": "dose volume float",
              "value": "@bind=data.orp.doseVolume;",
              "type": "float"
            },
            {
              "name": "dose volume remaining float",
              "value": "@bind=data.orp.dosingVolumeRemaining;",
              "type": "float"
            },
            {
              "name": "tank level",
              "value": "@bind=data.orp.tank.level;",
              "type": "float"
            },
            {
              "name": "tank capacity",
              "value": "@bind=data.orp.tank.capacity;",
              "type": "float"
            },
            {
              "name": "dosing status",
              "value": "@bind=data.orp.dosingStatus.val;",
              "type": "int"
            },
            {
              "name": "dosing method",
              "value": "@bind=vars.cfg.orp.dosingMethod.val;",
              "type": "int"
            },
            {
              "name": "start delay",
              "value": "@bind=vars.cfg.orp.startDelay;",
              "type": "int"
            },
            {
              "name": "max dosing time",
              "value": "@bind=vars.cfg.orp.maxDosingTime;",
              "type": "int"
            },
            {
              "name": "max dosing volume",
              "value": "@bind=vars.cfg.orp.maxDosingVolume;",
              "type": "int"
            },
            {
              "name": "max dosing volume float",
              "value": "@bind=vars.cfg.orp.maxDosingVolume;",
              "type": "float"
            },
            {
              "name": "mixing time",
              "value": "@bind=vars.cfg.orp.mixingTime;",
              "type": "int"
            },
            {
              "name": "flow readings only int",
              "value": "@bind=vars.cfg.orp.flowReadingsOnly?1:0;",
              "type": "int"
            },
            {
              "name": "low tolerance",
              "value": "@bind=vars.cfg.orp.tolerance.low;",
              "type": "int"
            },
            {
              "name": "high tolerance",
              "value": "@bind=vars.cfg.orp.tolerance.high;",
              "type": "int"
            },
            {
              "name": "tolerance enabled int",
              "value": "@bind=vars.cfg.orp.tolerance.enabled?1:0;",
              "type": "int"
            },
            {
              "name": "dose priority int",
              "value": "@bind=data.orp.dosePriority?1:0;",
              "type": "int"
            },
            {
              "name": "flow only mixing int",
              "value": "@bind=data.orp.flowOnlyMixing?1:0;",
              "type": "int"
            },
            {
              "name": "max daily volume",
              "value": "@bind=data.orp.maxDailyVolume;",
              "type": "int"
            },
            {
              "name": "daily volume dosed",
              "value": "@bind=data.ph.dailyVolumeDosed;",
              "type": "int"
            },
            {
              "name": "volume dosed",
              "value": "@bind=data.ph.volumeDosed;",
              "type": "int"
            },
            {
              "name": "max daily volume float",
              "value": "@bind=data.orp.maxDailyVolume;",
              "type": "float"
            },
            {
              "name": "daily volume dosed float",
              "value": "@bind=data.ph.dailyVolumeDosed;",
              "type": "float"
            },
            {
              "name": "volume dosed float",
              "value": "@bind=data.ph.volumeDosed;",
              "type": "float"
            },
            {
              "name": "orp demand",
              "value": "@bind=data.orp.demand;",
              "type": "int"
            }
          ]
        },
        {
          "description": "Bind chemController emit",
          "measurement": "chemControllersGen",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            },
            {
              "name": "status",
              "value": "@bind=data.status.desc;"
            },
            {
              "name": "alarm: comms desc",
              "value": "@bind=data.alarms.comms.desc;"
            },
            {
              "name": "alarm: flow desc",
              "value": "@bind=data.alarms.flow.desc;"
            },
            {
              "name": "alarm: body fault desc",
              "value": "@bind=data.alarms.bodyFault.desc;"
            },
            {
              "name": "alarm: flow sensor fault desc",
              "value": "@bind=data.alarms.flowSensorFault.desc;"
            },
            {
              "name": "warning: orp daily limit reached desc",
              "value": "@bind=data.warnings.orpDailyLimitReached.desc;"
            },
            {
              "name": "warning: water chemistry desc",
              "value": "@bind=data.warnings.waterChemistry.desc;"
            }
          ],
          "fields": [
            {
              "name": "saturation index",
              "value": "@bind=data.saturationIndex;",
              "type": "float"
            },
            {
              "name": "cyanuric acid",
              "value": "@bind=vars.cfg.cyanuricAcid;",
              "type": "int"
            },
            {
              "name": "calcium hardness",
              "value": "@bind=vars.cfg.calciumHardness;",
              "type": "int"
            },
            {
              "name": "alkalinity",
              "value": "@bind=vars.cfg.alkalinity;",
              "type": "int"
            },
            {
              "name": "borates",
              "value": "@bind=vars.cfg.borates;",
              "type": "int"
            },
            {
              "name": "flow detected",
              "value": "@bind=data.flowDetected;",
              "type": "float"
            },
            {
              "name": "flow sensor state",
              "value": "@bind=data.flowSensor.state;",
              "type": "float"
            },
            {
              "name": "alarm: comms",
              "value": "@bind=data.alarms.comms.val;",
              "type": "int"
            },
            {
              "name": "alarm: flow",
              "value": "@bind=data.alarms.flow.val;",
              "type": "int"
            },
            {
              "name": "alarm: body fault",
              "value": "@bind=data.alarms.bodyFault.val;",
              "type": "int"
            },
            {
              "name": "alarm: flow sensor fault",
              "value": "@bind=data.alarms.flowSensorFault.val;",
              "type": "int"
            },
            {
              "name": "warning: orp daily limit reached",
              "value": "@bind=data.warnings.orpDailyLimitReached.val;",
              "type": "int"
            },
            {
              "name": "warning: pH daily limit reached",
              "value": "@bind=data.warnings.pHDailyLimitReached.val;",
              "type": "int"
            },
            {
              "name": "warning: water chemistry",
              "value": "@bind=data.warnings.waterChemistry.val;",
              "type": "int"
            },
            {
              "name": "lsi range low",
              "value": "@bind=vars.cfg.lsiRange.low.val;",
              "type": "int"
            },
            {
              "name": "lsi range enabled",
              "value": "@bind=vars.cfg.lsiRange.enabled?1:0;",
              "type": "int"
            },
            {
              "name": "lsi range high",
              "value": "@bind=vars.cfg.lsiRange.high.val;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "circuit",
      "description": "Bind circuit emit",
      "points": [
        {
          "measurement": "circuits",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "integer"
            }
          ]
        }
      ]
    },
    {
      "name": "feature",
      "description": "Bind feature emit",
      "points": [
        {
          "measurement": "circuits",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "virtualCircuit",
      "description": "Bind virtualCircuit emit",
      "points": [
        {
          "measurement": "circuits",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "lightGroup",
      "description": "Bind lightGroup emit",
      "points": [
        {
          "measurement": "circuits",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "circuitGroup",
      "description": "Bind circuitGroup emit",
      "points": [
        {
          "measurement": "circuits",
          "storePrevState": true,
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "pump",
      "description": "Pump state emit",
      "points": [
        {
          "measurement": "pumps",
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "type",
              "value": "@bind=data.type.desc;"
            },
            {
              "name": "status",
              "value": "@bind=data.status.desc;"
            }
          ],
          "fields": [
            {
              "name": "rpm",
              "value": "@bind=data.rpm;",
              "type": "int"
            },
            {
              "name": "gpm",
              "value": "@bind=data.gpm;",
              "type": "int"
            },
            {
              "name": "flow",
              "value": "@bind=data.flow;",
              "type": "int"
            },
            {
              "name": "watts",
              "value": "@bind=data.watts;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "chlorinator",
      "description": "Bind circuit emit",
      "points": [
        {
          "measurement": "chlorinators",
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            },
            {
              "name": "status",
              "value": "@bind=data.status.desc;"
            },
            {
              "name": "superChlor",
              "value": "@bind=data.superChlor;"
            },
            {
              "name": "superChlorHours",
              "value": "@bind=data.superChlorHours;"
            }
          ],
          "fields": [
            {
              "name": "currentOutput",
              "value": "@bind=data.currentOutput;",
              "type": "int"
            },
            {
              "name": "poolSetpoint",
              "value": "@bind=data.poolSetpoint;",
              "type": "int"
            },
            {
              "name": "saltLevel",
              "value": "@bind=data.saltLevel;",
              "type": "int"
            },
            {
              "name": "spaSetpoint",
              "value": "@bind=data.spaSetpoint;",
              "type": "int"
            },
            {
              "name": "target output",
              "value": "@bind=data.targetOutput;",
              "type": "int"
            }
          ]
        }
      ]
    },
    {
      "name": "config",
      "description": "Not used for updates",
      "enabled": false
    },
    {
      "name": "filter",
      "description": "Bind filter to measurements",
      "points": [
        {
          "measurement": "filter",
          "tags": [
            {
              "name": "units",
              "value": "@bind=data.pressureUnits.desc;"
            },
            {
              "name": "filterType",
              "value": "@bind=data.filterType.desc;"
            },
            {
              "name": "body",
              "value": "@bind=data.body.desc;"
            },
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            }
          ],
          "fields": [
            {
              "name": "isOn",
              "value": "@bind=data.isOn;",
              "type": "boolean"
            },
            {
              "name": "isOnVal",
              "value": "@bind=data.isOn?1:0;",
              "type": "integer"
            },
            {
              "name": "pressure",
              "value": "@bind=data.pressure;",
              "type": "float"
            },
            {
              "name": "referencePressure",
              "value": "@bind=data.refPressure;",
              "type": "float"
            },
            {
              "name": "cleanPercentage",
              "value": "@bind=data.cleanPercentage;",
              "type": "float"
            }
          ]
        }
      ]
    },
    {
      "name": "cover",
      "description": "Bind cover to measurements",
      "points": [
        {
          "measurement": "cover",
          "tags": [
            {
              "name": "name",
              "value": "@bind=data.name;"
            },
            {
              "name": "id",
              "value": "@bind=data.id;"
            }
          ],
          "fields": [
            {
              "name": "isClosed",
              "value": "@bind=data.isClosed;",
              "type": "boolean"
            }
          ]
        }
      ]
    }
  ]
}