{
  "code_name": "_publisher_mqtt",
  "unique_prefix": "MQTT",
  "plugin_type": "publisher",
  "enabled": true,
  "data_source": "script",
  "show_ui": true,
  "data_filters": [
    {
      "compare_column": "Watched_Value4",
      "compare_operator": "==",
      "compare_field_id": "txtMacFilter",
      "compare_js_template": "'{value}'.toString()",
      "compare_use_quotes": true
    }
  ],
  "localized": ["display_name", "description", "icon"],
  "display_name": [
    {
      "language_code": "en_us",
      "string": "MQTT publisher"
    },
    {
      "language_code": "es_es",
      "string": "Habilitar MQTT"
    }
  ],
  "icon": [
    {
      "language_code": "en_us",
      "string": "<i class=\"fa-solid fa-square-rss\"></i>"
    }
  ],
  "description": [
    {
      "language_code": "en_us",
      "string": "A plugin to publish a notification via MQTT to Home Assistant."
    }
  ],
  "params": [
    {
      "name": "devices",
      "type": "sql",
      "value": "SELECT devLastIP from DEVICES",
      "timeoutMultiplier": true
    }
  ],
  "database_column_definitions": [
    {
      "column": "Index",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "none",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Index"
        }
      ]
    },
    {
      "column": "Plugin",
      "css_classes": "col-sm-2",
      "show": false,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "N/A"
        },
        {
          "language_code": "es_es",
          "string": "N/A"
        }
      ]
    },
    {
      "column": "Object_PrimaryID",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT Device ID"
        }
      ]
    },
    {
      "column": "Object_SecondaryID",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Sensor Name"
        }
      ]
    },
    {
      "column": "DateTimeCreated",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Sent when"
        }
      ]
    },
    {
      "column": "DateTimeChanged",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Changed"
        },
        {
          "language_code": "es_es",
          "string": "Cambiado"
        }
      ]
    },
    {
      "column": "Watched_Value1",
      "css_classes": "col-sm-3",
      "show": false,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Device name"
        }
      ]
    },
    {
      "column": "Watched_Value2",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Sensor type"
        }
      ]
    },
    {
      "column": "Watched_Value3",
      "css_classes": "col-sm-2",
      "show": false,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Hash"
        }
      ]
    },
    {
      "column": "Watched_Value4",
      "css_classes": "col-sm-2",
      "show": true,
      "type": "device_name_mac",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Device"
        }
      ]
    },
    {
      "column": "UserData",
      "css_classes": "col-sm-2",
      "show": false,
      "type": "textbox_save",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Comments"
        },
        {
          "language_code": "es_es",
          "string": "Comentarios"
        }
      ]
    },
    {
      "column": "Status",
      "css_classes": "col-sm-1",
      "show": true,
      "type": "replace",
      "default_value": "",
      "options": [
        {
          "equals": "watched-not-changed",
          "replacement": "<div style='text-align:center'><i class='fa-solid fa-square-check'></i><div></div>"
        },
        {
          "equals": "watched-changed",
          "replacement": "<div style='text-align:center'><i class='fa-solid fa-triangle-exclamation'></i></div>"
        },
        {
          "equals": "new",
          "replacement": "<div style='text-align:center'><i class='fa-solid fa-circle-plus'></i></div>"
        },
        {
          "equals": "missing-in-last-scan",
          "replacement": "<div style='text-align:center'><i class='fa-solid fa-question'></i></div>"
        }
      ],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Status"
        },
        {
          "language_code": "es_es",
          "string": "Estado"
        }
      ]
    },
    {
      "column": "Extra",
      "css_classes": "col-sm-3",
      "show": false,
      "type": "label",
      "default_value": "",
      "options": [],
      "localized": ["name"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Extra"
        },
        {
          "language_code": "es_es",
          "string": "Extra"
        }
      ]
    }
  ],
  "settings": [
    {
      "function": "RUN",
      "events": ["test"],
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "select", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "disabled",
      "options": [
        "disabled",
        "on_notification",
        "once",
        "schedule",
        "always_after_scan",
        "on_new_device"
      ],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "When to run"
        },
        {
          "language_code": "es_es",
          "string": "Cuando ejecuta"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Enable sending notifications via <a target=\"_blank\" href=\"https://www.home-assistant.io/integrations/mqtt/\">MQTT</a> to your Home Assistance instance. Usually, <code>on_notification</code> is recommended. See the <a target=\"_blank\" href=\"https://github.com/jokob-sk/NetAlertX/blob/main/docs/HOME_ASSISTANT.md\">NetAlertX Home Assistant guide</a> for details."
        },
        {
          "language_code": "es_es",
          "string": "Habilitar el envío de notificaciones a través de <a target=\"_blank\" href=\"https://www.home-assistant.io/integrations/mqtt/\">MQTT</a> a su Home Assistance."
        }
      ]
    },
    {
      "function": "CMD",
      "type": {
        "dataType": "string",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "readonly": "true" }],
            "transformers": []
          }
        ]
      },
      "default_value": "python3 /app/front/plugins/_publisher_mqtt/mqtt.py",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Command"
        },
        {
          "language_code": "es_es",
          "string": "Comando"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Command to run"
        },
        {
          "language_code": "es_es",
          "string": "Comando a ejecutar"
        }
      ]
    },
    {
      "function": "RUN_SCHD",
      "type": {
        "dataType": "string",
        "elements": [
          {
            "elementType": "span",
            "elementOptions": [
              {
                "cssClasses": "input-group-addon validityCheck"
              },
              {
                "getStringKey": "Gen_ValidIcon"
              }
            ],
            "transformers": []
          },
          {
            "elementType": "input",
            "elementOptions": [
              {
                "focusout": "validateRegex(this)"
              },
              {
                "base64Regex": "Xig/OlwqfCg/OlswLTldfFsxLTVdWzAtOV18WzAtOV0rLVswLTldK3xcKi9bMC05XSspKVxzKyg/OlwqfCg/OlswLTldfDFbMC05XXwyWzAtM118WzAtOV0rLVswLTldK3xcKi9bMC05XSspKVxzKyg/OlwqfCg/OlsxLTldfFsxMl1bMC05XXwzWzAxXXxbMC05XSstWzAtOV0rfFwqL1swLTldKykpXHMrKD86XCp8KD86WzEtOV18MVswLTJdfFswLTldKy1bMC05XSt8XCovWzAtOV0rKSlccysoPzpcKnwoPzpbMC02XXxbMC02XS1bMC02XXxcKi9bMC05XSspKSQ="
              }
            ],
            "transformers": []
          }
        ]
      },
      "default_value": "0 2 * * 3",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Schedule"
        },
        {
          "language_code": "es_es",
          "string": "Schedule"
        },
        {
          "language_code": "de_de",
          "string": "Schedule"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Only enabled if you select <code>schedule</code> in the <a href=\"#MQTT_RUN\"><code>MQTT_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
        },
        {
          "language_code": "es_es",
          "string": "Solo está habilitado si selecciona <code>schedule</code> en la configuración <a href=\"#MQTT_RUN\"><code>MQTT_RUN</code></a>. Asegúrese de ingresar la programación en el formato similar a cron correcto (por ejemplo, valide en <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). Por ejemplo, ingresar <code>0 4 * * *</code> ejecutará el escaneo después de las 4 a.m. en el <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</ código> que configuró arriba</a>. Se ejecutará la PRÓXIMA vez que pase el tiempo."
        },
        {
          "language_code": "de_de",
          "string": "Nur aktiviert, wenn Sie <code>schedule</code> in der <a href=\"#MQTT_RUN\"><code>MQTT_RUN</code>-Einstellung</a> auswählen. Stellen Sie sicher, dass Sie den Zeitplan im richtigen Cron-ähnlichen Format eingeben (z. B. validieren unter <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). Wenn Sie beispielsweise <code>0 4 * * *</code> eingeben, wird der Scan nach 4 Uhr morgens in der <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</ ausgeführt. Code> den Sie oben festgelegt haben</a>. Wird das NÄCHSTE Mal ausgeführt, wenn die Zeit vergeht."
        }
      ]
    },
    {
      "function": "RUN_TIMEOUT",
      "type": {
        "dataType": "integer",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "number" }],
            "transformers": []
          }
        ]
      },
      "default_value": 20,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Run timeout"
        },
        {
          "language_code": "es_es",
          "string": "Tiempo de espera de ejecución"
        },
        {
          "language_code": "de_de",
          "string": "Wartezeit"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Maximum time in seconds to wait for the script to finish. If this time is exceeded the script is aborted."
        },
        {
          "language_code": "es_es",
          "string": "Tiempo máximo en segundos para esperar a que finalice el script. Si se supera este tiempo, el script se cancela."
        }
      ]
    },
    {
      "function": "BROKER",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT broker URL"
        },
        {
          "language_code": "es_es",
          "string": "URL del broker MQTT"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "MQTT host URL (do not include <code>http://</code> or <code>https://</code>)."
        },
        {
          "language_code": "es_es",
          "string": "URL del host MQTT (no incluya <code>http://</code> o <code>https://</code>)."
        }
      ]
    },
    {
      "function": "PORT",
      "type": {
        "dataType": "integer",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "number" }],
            "transformers": []
          }
        ]
      },
      "default_value": 1883,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT broker port"
        },
        {
          "language_code": "es_es",
          "string": "Puerto del broker MQTT"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Port number where the broker is listening. Usually <code>1883</code>."
        },
        {
          "language_code": "es_es",
          "string": "Puerto donde escucha el broker MQTT. Normalmente <code>1883</code>."
        }
      ]
    },
    {
      "function": "TLS",
      "type": {
        "dataType": "boolean",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "checkbox" }],
            "transformers": []
          }
        ]
      },
      "default_value": false,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT TLS"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Enable TLS support."
        },
        {
          "language_code": "es_es",
          "string": "Habilitar soporte TLS."
        }
      ]
    },
    {
      "function": "USER",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT user"
        },
        {
          "language_code": "es_es",
          "string": "Usuario de MQTT"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "User name used to login into your MQTT broker instance."
        },
        {
          "language_code": "es_es",
          "string": "Nombre de usuario utilizado para iniciar sesión en su instancia de agente de MQTT."
        }
      ]
    },
    {
      "function": "PASSWORD",
      "type": {
        "dataType": "string",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "password" }],
            "transformers": []
          }
        ]
      },
      "default_value": "",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT password"
        },
        {
          "language_code": "es_es",
          "string": "Contraseña de MQTT"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Password used to login into your MQTT broker instance."
        },
        {
          "language_code": "es_es",
          "string": "Contraseña utilizada para iniciar sesión en su instancia de agente de MQTT."
        }
      ]
    },
    {
      "function": "SEND_STATS",
      "type": {
        "dataType": "boolean",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "checkbox" }],
            "transformers": []
          }
        ]
      },
      "default_value": true,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Send stats"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Check to send overal device stats, such as number of Online and Offline devices."
        }
      ]
    },
    {
      "function": "DEVICE_ID",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "netalertx",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Device ID"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "The root path of the stats overview sensor. Inserted into the <code>{MQTT_topic_root}/sensor/{MQTT_DEVICE_ID}/state</code> topic."
        }
      ]
    },
    {
      "function": "DEVICE_NAME",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "NetAlertX",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Device name"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "The name used for the stats overview device."
        }
      ]
    },
    {
      "function": "SEND_DEVICES",
      "type": {
        "dataType": "boolean",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "checkbox" }],
            "transformers": []
          }
        ]
      },
      "default_value": true,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Send devices"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Check to send individual devices to the broker with details, such as <code>is_new</code>, <code>is_present</code>, or <code>mac_address</code> of the devices."
        }
      ]
    },
    {
      "function": "SEND_NOTIFICATIONS",
      "type": {
        "dataType": "boolean",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "checkbox" }],
            "transformers": []
          }
        ]
      },
      "default_value": true,
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Send notifications"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Check to send notifications to the broker with json containing events, new_devices, down_devices and more."
        }
      ]
    },
    {
      "function": "topic_root",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "system-sensors",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT topic root"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "The topic root of the devices sensors. Inserted into the <code>{MQTT_topic_root}/sensor/{MQTT_DEVICE_ID}/state</code> topic."
        }
      ]
    },
    {
      "function": "DEVICES_SQL",
      "type": {
        "dataType": "string",
        "elements": [
          { "elementType": "input", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": "select rowid, * from Devices where devName not in ({s-quote}null{s-quote}, {s-quote}(name not found){s-quote}, {s-quote}(unknown){s-quote})",
      "options": [],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Devices SQL"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "The SQL condition used to select which Devices are sent via MQTT. Please note that you need to use <code>{s-quote}</code> for single quotes replacement and double-quotes are not supported."
        }
      ]
    },
    {
      "function": "QOS",
      "type": {
        "dataType": "integer",
        "elements": [
          { "elementType": "select", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": 0,
      "options": [0, 1, 2],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT Quality of Service"
        },
        {
          "language_code": "es_es",
          "string": "Calidad de servicio MQTT"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "Quality of service setting for MQTT message sending. The higher the quality the longer the delay. <br/> <code>0</code> - Low quality to <code>2</code> - High quality."
        },
        {
          "language_code": "es_es",
          "string": "Configuración de calidad de servicio para el envío de mensajes MQTT. <code>0</code>: baja calidad a <code>2</code>: alta calidad. Cuanto mayor sea la calidad, mayor será el retraso."
        }
      ]
    },
    {
      "function": "VERSION",
      "type": {
        "dataType": "integer",
        "elements": [
          { "elementType": "select", "elementOptions": [], "transformers": [] }
        ]
      },
      "default_value": 5,
      "options": [3, 5],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "Version"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "MQTT Protocol version. Depends on the MQTT broker</a>. Usually set to <code>5</code>, or <code>3</code> for backwards compatibility."
        }
      ]
    },
    {
      "function": "DELAY_SEC",
      "type": {
        "dataType": "integer",
        "elements": [
          {
            "elementType": "input",
            "elementOptions": [{ "type": "number" }],
            "transformers": []
          }
        ]
      },
      "default_value": 2,
      "options": [2, 3, 4, 5],
      "localized": ["name", "description"],
      "name": [
        {
          "language_code": "en_us",
          "string": "MQTT delay per device"
        },
        {
          "language_code": "es_es",
          "string": "Retraso de MQTT por dispositivo"
        }
      ],
      "description": [
        {
          "language_code": "en_us",
          "string": "A little hack - delay adding to the queue in case the process is restarted and previous publish processes aborted (it takes ~<code>2</code>s to update a sensor config on the broker). Tested with <code>2</code>-<code>3</code> seconds of delay. This delay is only applied when devices are created (during the first notification loop). It doesn not affect subsequent scans or notifications."
        },
        {
          "language_code": "es_es",
          "string": "Un pequeño truco: retrase la adición a la cola en caso de que el proceso se reinicie y los procesos de publicación anteriores se anulen (se necesitan ~<code>2</code>s para actualizar la configuración de un sensor en el intermediario). Probado con <code>2</code>-<code>3</code> segundos de retraso. Este retraso solo se aplica cuando se crean dispositivos (durante el primer bucle de notificación). No afecta los escaneos o notificaciones posteriores."
        }
      ]
    }
  ]
}
