{
    "code_name": "_publisher_mqtt",
    "unique_prefix": "MQTT",
    "plugin_type": "publisher",
    "enabled": true,    
    "data_source":  "script",
    "show_ui": 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 the Apprise gateway."
		}
    ],
    "params" : [
        {
            "name"              : "devices",
            "type"              : "sql",
            "value"             : "SELECT dev_LastIP from DEVICES",
            "timeoutMultiplier" : true
        }
    ],  
    "database_column_definitions":
    [          
        {
            "column": "Index",
            "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": "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": true,
            "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": true,
            "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_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": "text.select",            
            "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": "readonly",
            "default_value":"python3 /app/front/plugins/_publisher_mqtt/mqtt.py devices={devices}",
            "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": "text",
            "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": "integer",
            "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": "text",
            "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": "integer",
            "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": "USER",
            "type": "text",
            "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": "password",
            "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": "boolean",
            "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": "text",
            "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>system-sensors/sensor/{DEVICE_ID}/state</code> topic."
				}]
        },
        {
            "function": "DEVICE_NAME",
            "type": "text",
            "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": "boolean",
            "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": "PRESENCE_SENSOR_TYPE",         
            "events": [],   
            "type": "text.select",            
            "default_value":"binary_sensor",
            "options": ["binary_sensor", "device_tracker" ],
            "localized": ["name", "description"],
            "name" :[{
                "language_code": "en_us",
                "string" : "Presence Sensor Type"
				}],
            "description": [
                {
                "language_code": "en_us",
                "string" : "The type of the sensor that should be generated for the <code>is_present</code> sensor. Inserted into the <code>homeassistant/{MQTT_PRESENCE_SENSOR_TYPE}/mac_44_ef_44_ef_44_ef/is_present/</code> topic. See the <a target=\"_blank\" href=\"https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/_publisher_mqtt/README.md#usage\">Plugin readme</a> for details."
				}
            ]
        },
        {
            "function": "QOS",
            "type": "integer.select",
            "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": "integer.select",
            "default_value": 1,
            "options": [ 1, 2 ],
            "localized": ["name", "description"],
            "name" : [{
                "language_code": "en_us",
                "string" : "Version"
				}],
            "description": [{
                "language_code": "en_us",
                "string" : "Paho MQTT API version. Depends on the MQTT <a href=\"https://eclipse.dev/paho/files/paho.mqtt.python/html/index.html#callbacks\" target=\"_blank\">version supported by the MQTT broker</a>. Usually set to <code>1</code>."
				}]
        },
        {
            "function": "DELAY_SEC",
            "type": "integer",
            "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."
            }]
        }         
    ]
}
