[gelöst] NetAlertX - MQTT Readingslist TOPIC verwenden

Begonnen von GunterB, 19 November 2025, 13:08:22

Vorheriges Thema - Nächstes Thema

GunterB

Hallo zusammen,

ich überwache in menem Netztwerk sämtliche Geräte mit NetAlertX (https://jokob-sk.github.io/NetAlertX/).
Die MQTT Ausgabe ist für mich jetzt erst mal ein Problem.

Meine Readingslist sieht erst mal so aus:
netalertx:system-sensors/sensor/netalertx/state:.* { $EVENT }
netalertx:system-sensors/.* { $EVENT }

Jedoch hätte ich gerne eine ordentliche Auflistung der Devices als Reading und nicht nur durchlaufende Werte.

Gibt es eine Möglichkeit, diese JSON Werte sinnvoll auszuwerten?

Code (Mitschnitt) Auswählen
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/last_ip/config', ... (333 bytes))
{"name": "last_ip", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.last_ip}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_last_ip", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:ip-network"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/mac_address/config', ... (353 bytes))
{"name": "mac_address", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.mac_address}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_mac_address", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:folder-key-network"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/is_new/config', ... (338 bytes))
{"name": "is_new", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.is_new}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_is_new", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:bell-alert-outline"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/vendor/config', ... (323 bytes))
{"name": "vendor", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.vendor}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_vendor", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:cog"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/first_connection/config', ... (393 bytes))
{"device_class": "timestamp", "name": "first_connection", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.first_connection}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_first_connection", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:calendar-start"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/sensor/mac_9c_83_AA_BB_CC_DD/last_connection/config', ... (388 bytes))
{"device_class": "timestamp", "name": "last_connection", "state_topic": "system-sensors/sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.last_connection}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_last_connection", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:calendar-end"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/binary_sensor/mac_9c_83_AA_BB_CC_DD/is_present/config', ... (343 bytes))
{"name": "is_present", "state_topic": "system-sensors/binary_sensor/mac_9c_83_AA_BB_CC_DD/state", "value_template": "{{value_json.is_present}}", "unique_id": "mac_9c_83_AA_BB_CC_DD_sensor_is_present", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor"], "manufacturer": "NetAlertX", "name": "Android_AABBCCDD"}, "icon": "mdi:wifi"}
Client mosqsub|28500-raspberry received PUBLISH (d0, q0, r0, m0, 'homeassistant/device_tracker/mac_9c_83_AA_BB_CC_DD/config', ... (524 bytes))
{"state_topic": "system-sensors/device_tracker/mac_9c_83_AA_BB_CC_DD/state", "json_attributes_topic": "system-sensors/device_tracker/mac_9c_83_AA_BB_CC_DD/attributes", "name": "is_home", "payload_home": "home", "payload_not_home": "away", "unique_id": "mac_9c_83_AA_BB_CC_DD_device_tracker_is_home", "icon": "mdi:home", "device": {"identifiers": ["mac_9c_83_AA_BB_CC_DD_sensor", "mac_9c_83_AA_BB_CC_DD_device_tracker_is_home"], "manufacturer": "NetAlertX", "model": "Android_AABBCCDD", "name": "Android_AABBCCDD"}}

Beta-User

Schritt für Schritt zu MQTT2_DEVICE im FHEM-Wiki ist bekannt?

Und im "Workshop" im korrekten Forenbereich für die Anfrage findet sich Baumaterial...
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

GunterB

Hallo,

ich finde keine Hilfe dazu, wie ich Teile, bzw das ganze Topic mit als Information verarbeiten kann.

Mit netalertx:system-sensors/binary_sensor/.*/state:.* BINARY_SENSOR bekomme ich das Reading BINARY_SENSOR    {"is_present": "OFF"}
Mit fehlt jetzt jedoch die Identifikation des Gerätes über das Topic.

Wie bekomme ich das ins Reading mit rein?

Beta-User

Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: ZigBee2mqtt, MiLight@ESP-GW, BT@OpenMQTTGw | ZWave | SIGNALduino | MapleCUN | RHASSPY
svn: u.a Weekday-&RandomTimer, Twilight,  div. attrTemplate-files, MySensors

GunterB

#4
Danke Beta-User,

du hast mich in die richtige Richtung gebracht!!!

netalertx:system-sensors/binary_sensor/.*/state:.* { my ($mac) = ($TOPIC =~ m/mac_((?:[a-fA-F0-9_]+))/g);; ($mac =~ s/_//g);; json2nameValue($EVENT, $mac) }

Ich mache daran dann noch weiter...
Rückmeldung folgt.

GunterB

#5
Device für NetAlertX:

define netalertx MQTT2_DEVICE netalertx
attr netalertx autocreate 0
attr netalertx readingList netalertx:system-sensors/.* { my ($type, $sensor, $val) = ($TOPIC =~ m/\/(.*)\/(.*)\/(.*)/);;;; fhem("setreading $NAME ${sensor}_${type}_${val} $EVENT") }

Erzeugte Readings:
Code ("MAC Sensor") Auswählen
mac_aa_bb_cc_dd_ee_ff_binary_sensor_state {"is_present": "OFF"}
mac_aa_bb_cc_dd_ee_ff_device_tracker_attributes {"last_ip": "192.168.111.103", "is_new": "0", "alert_down": "0", "vendor": "Unknown locally administered", "mac_address": "aa:bb:cc:dd:ee:ff", "model": "proxy020local", "last_connection": "2025-11-26T00:00:00+01:00", "first_connection": "2025-11-26T00:00:00+01:00", "sync_node": "", "group": "", "location": "", "network_parent_mac": "aa:bb:cc:dd:ee:00", "network_parent_name": "EAP225"}
mac_aa_bb_cc_dd_ee_ff_device_tracker_state away
mac_aa_bb_cc_dd_ee_ff_sensor_state {"last_ip": "192.168.111.103", "is_new": "0", "alert_down": "0", "vendor": "Unknown locally administered", "mac_address": "aa:bb:cc:dd:ee:ff", "model": "proxy020local", "last_connection": "2025-11-26T00:00:00+01:00", "first_connection": "2025-11-26T00:00:00+01:00", "sync_node": "", "group": "", "location": "", "network_parent_mac": "aa:bb:cc:dd:ee:00", "network_parent_name": "EAP225}

Code ("Internet Sensor") Auswählen
mac_internet_binary_sensor_state {"is_present": "ON"}
mac_internet_device_tracker_attributes {"last_ip": "99.9.1.240", "is_new": "0", "alert_down": "0", "vendor": "None", "mac_address": "Internet", "model": "flood", "last_connection": "2025-11-26T00:00:00+01:00", "first_connection": "2025-11-26T00:00:00+02:00", "sync_node": "", "group": "", "location": "", "network_parent_mac": "null", "network_parent_name": ""}
mac_internet_device_tracker_state home
mac_internet_sensor_state {"last_ip": "99.9.1.240", "is_new": "0", "alert_down": "0", "vendor": "None", "mac_address": "Internet", "model": "flood", "last_connection": "2025-11-26T00:00:00+01:00", "first_connection": "2025-11-26T00:00:00+02:00", "sync_node": "", "group": "", "location": "", "network_parent_mac": "null", "network_parent_name": ""}

Code ("NetAlertX Sensor") Auswählen
netalertx_sensor_state {"online": 87, "down": 2, "all": 139, "archived": 0, "new": 2, "unknown": 7}
JSON für jedes Gerät entpacken:
attr netalertx readingList netalertx:system-sensors/.* { my ($type, $sensor, $val) = ($TOPIC =~ m/\/(.*)\/(.*)\/(.*)/);;;; fhem("setreading $NAME ${sensor}_${type}_${val} $EVENT");;;; $sensor =~ s/mac_//g;;;; $sensor =~ s/_//g;;;; json2nameValue($EVENT, "${sensor}_") }Du darfst diesen Dateianhang nicht ansehen.