zabbix_export:
  version: '7.0'
  template_groups:
    - uuid: f06b49553b1240418914a9da29650ca8
      name: 'AI On The Edge'
  templates:
    - uuid: dc3b0164071446d4a662f323e26a12e6
      template: 'Water Meter - AI On The Edge by MQTT'
      name: 'Water Meter - AI On The Edge by MQTT'
      description: |
        The template is used to gather data from ESP32 devices running the "AI On The Edge Device" project. This project enables an ESP32CAM device to use a camera and image processing techniques to read metering devices that otherwise do not support digital means of extracting data.
        
        Reference: https://github.com/jomjol/AI-on-the-edge-device
      groups:
        - name: 'AI On The Edge'
      items:
        - uuid: abddb768f0fb4abfb1bd1ee2410f2d5a
          name: 'Meter Value'
          type: DEPENDENT
          key: meter_value
          delay: '0'
          history: 90d
          value_type: FLOAT
          units: '!Ft³'
          description: 'This is the raw consumption value read from the meter. The units will need to be adjusted to match what the meter reports.'
          preprocessing:
            - type: JSONPATH
              parameters:
                - $.value
              error_handler: DISCARD_VALUE
            - type: IN_RANGE
              parameters:
                - '0'
                - '999999.99'
              error_handler: DISCARD_VALUE
            - type: DISCARD_UNCHANGED
              parameters:
                - ''
          master_item:
            key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/main/json", "{$MQTT_USER}", "{$MQTT_PASS}"]'
        - uuid: 06e5ff27334942898c56fa2bab00e6a1
          name: 'CPU Temperature'
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/CPUtemp", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          units: °C
          description: 'The CPU temperature of the ESP32 in degrees Celsius.'
        - uuid: 6495d143e1724d528174e3f783b9bdbd
          name: 'Free Memory'
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/freeMem", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          value_type: FLOAT
          units: B
          description: 'The free memory of the ESP32 in Bytes.'
        - uuid: cad40d188bbf4458b686bbbb6dd0b613
          name: 'IP Address'
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/IP", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          value_type: TEXT
          trends: '0'
          description: 'The IP address of the ESP32.'
          preprocessing:
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - '86400'
        - uuid: 2e60fd1fb36a4a7ab277f12848a6ffb4
          name: 'Water Meter Raw Info'
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/main/json", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          value_type: TEXT
          trends: '0'
          description: 'A JSON payload containing the water consumption data read from the meter.'
        - uuid: 39f9242f75074fd3b70503d676c26e64
          name: Status
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/status", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          value_type: TEXT
          trends: '0'
          status: DISABLED
          description: 'The current status of AI on the Edge, such as "Take Image", "Aligning", "Digitalization of ROIs", etc.'
          preprocessing:
            - type: DISCARD_UNCHANGED
              parameters:
                - ''
        - uuid: b97abefe768947afa35ffb13f4fa68ae
          name: Uptime
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/uptime", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          units: s
          description: 'Uptime of the ESP32 in seconds.'
          triggers:
            - uuid: 7aac88e27d054888877216902f74b1a9
              expression: 'nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/uptime", "{$MQTT_USER}", "{$MQTT_PASS}"], 5m)=1'
              name: 'Water Meter Communication Lost'
              priority: WARNING
            - uuid: 0adc499d5d21449188a7bd8313a48151
              expression: 'last(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/uptime", "{$MQTT_USER}", "{$MQTT_PASS}"])<10m'
              name: 'Water Meter has been restarted'
              priority: INFO
        - uuid: 39c99672047e4d57be49229c052c4473
          name: 'Wireless Signal Strength'
          type: ZABBIX_ACTIVE
          key: 'mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/wifiRSSI", "{$MQTT_USER}", "{$MQTT_PASS}"]'
          delay: '0'
          history: 90d
          value_type: FLOAT
          units: dBm
          description: 'The Wi-Fi signal strength of the ESP32 in decibel-milliwatts.'
          valuemap:
            name: 'Wireless Signal Strength'
        - uuid: 921551983541492f80392e6b3f8ea908
          name: 'Water Consumption'
          type: CALCULATED
          key: total_water
          delay: 1s
          history: 90d
          value_type: FLOAT
          units: '!Ft³'
          params: last(//meter_value)
          description: |
            This is the raw consumption value read from the meter. The units will need to be adjusted to match what the meter reports.
            
            The purpose of this item is to keep the value "fresh", to prevent the Simple Change preprocessor from failing due to the item not having been measured recently.
          preprocessing:
            - type: CHECK_NOT_SUPPORTED
              parameters:
                - '-1'
            - type: DISCARD_UNCHANGED_HEARTBEAT
              parameters:
                - '60'
        - uuid: 5ec74241a340438d8b9ec62d75f80fc6
          name: 'Water Consumed'
          type: DEPENDENT
          key: water_consumed
          delay: '0'
          history: 90d
          value_type: FLOAT
          units: Gal
          description: 'The amount of water consumed between consecutive measurements. The units will need to be adjusted to match the desired output. The UNIT_CONVERSION macro can be used to convert between units of measure. (Ex: 1 Ft³ = 7.48052 Gallons).'
          preprocessing:
            - type: SIMPLE_CHANGE
              parameters:
                - ''
            - type: MULTIPLIER
              parameters:
                - '{$UNIT_CONVERSION}'
          master_item:
            key: total_water
        - uuid: f7b3f77c6f834cb3b3017a1fc55b5e59
          name: 'Water Consumed - Daily'
          type: CALCULATED
          key: water_consumed_daily
          delay: 0;h0m0s0
          history: 9125d
          value_type: FLOAT
          trends: '0'
          units: Gal
          params: 'sum(//water_consumed, 1d:now/d)'
          description: 'The amount of water consumed today. The units must be adjusted to match the water_consumed item.'
        - uuid: 74aee790c847418ea09819ecc57b02c4
          name: 'Water Consumed - Hourly'
          type: CALCULATED
          key: water_consumed_hourly
          delay: 0;m0s0
          history: 9125d
          value_type: FLOAT
          trends: '0'
          units: Gal
          params: 'sum(//water_consumed, 1h:now/h)'
          description: 'The amount of water consumed in the previous hour. The units must be adjusted to match the water_consumed item.'
        - uuid: b7b43e3574924c4cba408d303cb2ae63
          name: 'Water Consumed - Last 24 Hours'
          type: CALCULATED
          key: water_consumed_last_24_hours
          delay: '60'
          history: 90d
          value_type: FLOAT
          units: Gal
          params: 'round(sum(//water_consumed, 24h), 2)'
          description: 'The amount of water used in the previous 24 hour period. The units must be adjusted to match the water_consumed item.'
        - uuid: 598dd5ec048b485dbd63a343c7f2eb26
          name: 'Water Consumed - Today'
          type: CALCULATED
          key: water_consumed_today
          delay: 0;s0
          history: 90d
          value_type: FLOAT
          units: Gal
          params: 'round(sum(//water_consumed, 1d:now/d+1d), 2)'
          description: 'The amount of water used today. The units must be adjusted to match the water_consumed item.'
        - uuid: 4d12553d63e246bf96ca7befba8274a9
          name: 'Water Consumed - Daily Average'
          type: CALCULATED
          key: water_consumption_daily_average
          delay: 0;h0m1s0
          history: 9125d
          value_type: FLOAT
          trends: '0'
          units: Gal
          params: 'avg(//water_consumed_daily, 9125d)'
          description: 'The average daily water consumption. The units must be adjusted to match the water_consumed item.'
      macros:
        - macro: '{$MQTT_BROKER}'
          description: 'Hostname or IP address of the MQTT broker'
        - macro: '{$MQTT_PASS}'
          type: SECRET_TEXT
          description: 'MQTT password'
        - macro: '{$MQTT_PORT}'
          description: 'Port on which the MQTT broker is accessed'
        - macro: '{$MQTT_SCHEME}'
          value: tcp
          description: 'Values can be tcp (unsecure) and tls (secure)'
        - macro: '{$MQTT_USER}'
          description: 'MQTT username'
        - macro: '{$UNIT_CONVERSION}'
          value: '7.48052'
          description: 'Used to translate meter unit of measure to desired unit of measure. (Ex: 1 Ft³ = 7.48052 Gal)'
      valuemaps:
        - uuid: c567c529e18545abb2464fb5b63a5c8e
          name: 'Wireless Signal Strength'
          mappings:
            - type: GREATER_OR_EQUAL
              value: '-55'
              newvalue: Excellent
            - type: IN_RANGE
              value: '-67--54'
              newvalue: Good
            - type: IN_RANGE
              value: '-78--66'
              newvalue: Fair
            - type: IN_RANGE
              value: '-85--77'
              newvalue: Weak
            - type: LESS_OR_EQUAL
              value: '-86'
              newvalue: Unreliable
  triggers:
    - uuid: 181380a1b905430ab78253551ddaa36a
      expression: 'nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/CPUtemp", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/freeMem", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/IP", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/uptime", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/main/json", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/wifiRSSI", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1 or nodata(/Water Meter - AI On The Edge by MQTT/mqtt.get["{$MQTT_SCHEME}://{$MQTT_BROKER}:{$MQTT_PORT}", "watermeter/status", "{$MQTT_USER}", "{$MQTT_PASS}"],5m)=1'
      name: 'Water Meter MQTT Communication Problem'
      priority: WARNING
