MQTT settings to select what is send #364📩

This commit is contained in:
Jokob-sk
2024-01-06 12:09:59 +11:00
parent a6f5e6c499
commit 44f0ba0924
3 changed files with 94 additions and 55 deletions

View File

@@ -267,7 +267,7 @@
"description": [ "description": [
{ {
"language_code": "en_us", "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." "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/Pi.Alert/blob/main/docs/HOME_ASSISTANT.md\">PiAlert Home Assistant guide</a> for details."
}, },
{ {
"language_code": "es_es", "language_code": "es_es",
@@ -493,6 +493,40 @@
"language_code": "es_es", "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." "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."
}] }]
},
{
"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": "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."
}
]
} }
] ]
} }

View File

@@ -257,6 +257,8 @@ def mqtt_start(db):
# General stats # General stats
# Create a generic device for overal stats # Create a generic device for overal stats
if get_setting_value('MQTT_SEND_STATS') == True:
# Create a new device representing overall PiAlert stats
create_generic_device(client) create_generic_device(client)
# Get the data # Get the data
@@ -270,13 +272,15 @@ def mqtt_start(db):
for column in columns: for column in columns:
payload += '"'+column+'": ' + str(row[column]) +',' payload += '"'+column+'": ' + str(row[column]) +','
# Publish (warap into {} and remove last ',' from above) # Publish (wrap into {} and remove last ',' from above)
publish_mqtt(client, "system-sensors/sensor/pialert/state", publish_mqtt(client, "system-sensors/sensor/pialert/state",
'{ \ '{ \
'+ payload[:-1] +'\ '+ payload[:-1] +'\
}' }'
) )
# Generate device-specific MQTT messages if enabled
if get_setting_value('MQTT_SEND_DEVICES') == True:
# Specific devices # Specific devices

View File

@@ -248,6 +248,7 @@ def read_config_file(filename):
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# DEPERECATED soonest after 3/3/2024 # DEPERECATED soonest after 3/3/2024
# 🤔Idea/TODO: Check and compare versions/timestamps amd only perform a replacement if config/version older than...
replacements = { replacements = {
r'\bREPORT_TO\b': 'SMTP_REPORT_TO', r'\bREPORT_TO\b': 'SMTP_REPORT_TO',
r'\bREPORT_FROM\b': 'SMTP_REPORT_FROM', r'\bREPORT_FROM\b': 'SMTP_REPORT_FROM',