Problem mit String Vergleich: Gibts den Operator !~ überhaupt?

Begonnen von grappa24, 18 Januar 2024, 09:30:45

Vorheriges Thema - Nächstes Thema

grappa24

Was mach ich hier falsch: Die Alarmmeldung soll nicht ausgelöst werden wenn B_$DEVICE den (Teil)String "ECHO" oder "schrank" enthält. Sie wird aber ausgelöst z.B. für meine Geräte "Gefrierschrank" und "Kühlschrank", was ich ja unterbinden wollte.

hier das Ganze DOIF:
define notifier_shelly_offline DOIF ([":online: false"] and [?$SELF:B_$DEVICE] ne "false" and [?$SELF:B_$DEVICE] !~ /ECHO/ and [?$SELF:B_$DEVICE] !~ /schrank/) ({DebianMail('alarm@xxx.de', 'FHEM - warning from device: $DEVICE','Das Gerät $DEVICE ist offline')}, setreading $SELF B_$DEVICE false) DOELSEIF ([":online: true"] and [?$SELF:B_$DEVICE] ne "true") (setreading $SELF B_$DEVICE true)
attr notifier_shelly_offline do always
attr notifier_shelly_offline room Shelly,Watchdogs
#   DEF        ([":online: false"] and [?$SELF:B_$DEVICE] ne "false" and [?$SELF:B_$DEVICE] !~ /ECHO/ and [?$SELF:B_$DEVICE] !~ /schrank/) ({DebianMail('alarm@xxx.de', 'FHEM - warning from device: $DEVICE','Das Gerät $DEVICE ist offline')}, setreading $SELF B_$DEVICE false) DOELSEIF ([":online: true"] and [?$SELF:B_$DEVICE] ne "true") (setreading $SELF B_$DEVICE true)
#   FUUID      6194c760-f33f-b5ae-129c-8f4b771576da5ecb
#   MODEL      FHEM
#   NAME       notifier_shelly_offline
#   NOTIFYDEV  .*().*,global
#   NR         597
#   NTFY_ORDER 50-notifier_shelly_offline
#   STATE      cmd_2
#   TYPE       DOIF
#   VERSION    27740 2023-07-10 09:31:11
#   eventCount 1428
#   READINGS:
#     2022-03-10 11:44:33   B_AnwSim        true
#     2023-01-19 12:04:43   B_ECHO_0e79d77ada494bf88e5f195d151fdfc3 true
#     2023-01-19 12:04:42   B_ECHO_2a9067a05225433fb6867bd7dc8aacda false
#     2023-01-19 12:04:43   B_ECHO_32e355c7a449480f95eca9b4136178f8 true
#     2024-01-17 19:26:14   B_ECHO_G0014D0594531KDV true
#     2023-01-19 12:04:43   B_ECHO_G070VM2421360K8E true
#     2024-01-17 15:40:34   B_ECHO_G090L9117436078K true
#     2023-12-21 17:11:53   B_ECHO_G0913L0592730MA1 true
#     2024-01-15 16:37:22   B_ECHO_G2A0RF03745600P7 true
#     2023-01-19 12:04:43   B_ECHO_c7229b71bb5044d68288d240336865ba true
#     2023-01-19 12:04:43   B_ECHO_d4ed2843d4964db38d3596509c418f65 true
#     2023-01-19 12:04:43   B_ECHO_f18636fe03ba407683901527285d925e false
#     2024-01-18 08:33:13   B_MQTT2_gefrierschrank true
#     2024-01-18 08:33:13   B_MQTT2_kuehlschrank true
#     2023-11-08 10:09:57   B_ug_eisschrank true
#     2023-12-01 03:14:31   B_ug_garagentor_oeffner true
#     2023-11-13 10:19:40   B_ug_gefrierschrank true
#     2024-01-18 09:22:52   Device          ECHO_G070VM2421360K8E
#     2024-01-18 08:33:13   cmd             2
#     2024-01-18 08:33:13   cmd_event       MQTT2_kuehlschrank
#     2024-01-18 08:33:13   cmd_nr          2
#     2024-01-17 09:43:37   mode            enabled
#     2024-01-18 08:33:13   state           cmd_2
#   Regex:
#     accu:
#     bar:
#     barAvg:
#     collect:
#     cond:
#       :
#         0:
#           ":online: false" :online: false
#         1:
#           ":online: true" :online: true
#   attr:
#     cmdState:
#     wait:
#     waitdel:
#   condition:
#     0          ::EventDoIf('',$hash,'online: false',0) and ::ReadingValDoIf($hash,'notifier_shelly_offline','B_$DEVICE') ne "false" and ::ReadingValDoIf($hash,'notifier_shelly_offline','B_$DEVICE') !~ /ECHO/ and ::ReadingValDoIf($hash,'notifier_shelly_offline','B_$DEVICE') !~ /schrank/
#     1          ::EventDoIf('',$hash,'online: true',0) and ::ReadingValDoIf($hash,'notifier_shelly_offline','B_$DEVICE') ne "true"
#   do:
#     0:
#       0          {DebianMail('alarm@hehlgans.de', 'FHEM - warning from device: $DEVICE','Das Gerät $DEVICE ist offline')}, setreading notifier_shelly_offline B_$DEVICE false
#     1:
#       0          setreading notifier_shelly_offline B_$DEVICE true
#     2:
#   helper:
#     NOTIFYDEV  .*().*,global
#     event      online: true
#     globalinit 1
#     last_timer 0
#     sleeptimer -1
#     timerdev   MQTT2_kuehlschrank
#     timerevent online: true
#     triggerDev ECHO_G070VM2421360K8E
#     timerevents:
#       online: true
#       params_switch_0_aenergy_total_kW: 4.078749
#       params_switch_0_aenergy_total_cost: 1.38677466
#       has_update: false
#     timereventsState:
#       online: true
#       params_switch_0_aenergy_total_kW: 4.078749
#       params_switch_0_aenergy_total_cost: 1.38677466
#       has_update: false
#     triggerEvents:
#       online: true
#     triggerEventsState:
#       online: true
#   internals:
#   readings:
#   trigger:
#   uiState:
#   uiTable:
#
setstate notifier_shelly_offline cmd_2
setstate notifier_shelly_offline 2022-03-10 11:44:33 B_AnwSim true
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_0e79d77ada494bf88e5f195d151fdfc3 true
setstate notifier_shelly_offline 2023-01-19 12:04:42 B_ECHO_2a9067a05225433fb6867bd7dc8aacda false
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_32e355c7a449480f95eca9b4136178f8 true
setstate notifier_shelly_offline 2024-01-17 19:26:14 B_ECHO_G0014D0594531KDV true
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_G070VM2421360K8E true
setstate notifier_shelly_offline 2024-01-17 15:40:34 B_ECHO_G090L9117436078K true
setstate notifier_shelly_offline 2023-12-21 17:11:53 B_ECHO_G0913L0592730MA1 true
setstate notifier_shelly_offline 2024-01-15 16:37:22 B_ECHO_G2A0RF03745600P7 true
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_c7229b71bb5044d68288d240336865ba true
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_d4ed2843d4964db38d3596509c418f65 true
setstate notifier_shelly_offline 2023-01-19 12:04:43 B_ECHO_f18636fe03ba407683901527285d925e false
setstate notifier_shelly_offline 2022-04-26 19:16:11 B_HeikeDECT false
setstate notifier_shelly_offline 2024-01-18 08:33:13 B_MQTT2_gefrierschrank true
setstate notifier_shelly_offline 2024-01-18 08:33:13 B_MQTT2_kuehlschrank true
setstate notifier_shelly_offline 2023-12-22 08:29:22 B_MQTT2_shellyplug_s_977FC2 true
setstate notifier_shelly_offline 2023-11-12 23:53:23 B_MQTT2_shellyplusplugs_hwr_trockner true
setstate notifier_shelly_offline 2023-11-13 00:10:58 B_MQTT2_shellyplusplugs_hwr_waschmaschine false
setstate notifier_shelly_offline 2023-11-24 12:50:35 B_MQTT2_shellyplusplugs_spuelmaschine true
setstate notifier_shelly_offline 2023-12-03 23:12:18 B_MQTT2_spuelmaschine true
setstate notifier_shelly_offline 2024-01-18 06:00:20 B_MQTT2_trockner true
setstate notifier_shelly_offline 2023-12-19 13:36:37 B_MQTT2_waschmaschine false
setstate notifier_shelly_offline 2022-04-26 17:29:58 B_MiniLED true
setstate notifier_shelly_offline 2023-04-29 08:59:03 B_PlugS_Unbenutzt true
setstate notifier_shelly_offline 2023-11-03 22:14:36 B_eBike_charger true
setstate notifier_shelly_offline 2022-02-23 05:30:20 B_gaeste_wc true
setstate notifier_shelly_offline 2023-11-18 21:16:45 B_hwr_trockner true
setstate notifier_shelly_offline 2023-11-12 23:53:59 B_hwr_waschmaschine true
setstate notifier_shelly_offline 2023-12-01 09:13:27 B_ku_deckenlampe true
setstate notifier_shelly_offline 2023-12-01 03:14:29 B_rauchmelder_alarm true
setstate notifier_shelly_offline 2023-11-08 10:09:57 B_ug_eisschrank true
setstate notifier_shelly_offline 2023-12-01 03:14:31 B_ug_garagentor_oeffner true
setstate notifier_shelly_offline 2023-11-13 10:19:40 B_ug_gefrierschrank true
setstate notifier_shelly_offline 2022-03-16 08:32:28 B_ventilator false
setstate notifier_shelly_offline 2023-05-30 12:12:48 B_webcam_garage true
setstate notifier_shelly_offline 2023-11-04 21:37:37 B_webcam_lobby true
setstate notifier_shelly_offline 2023-12-01 03:14:27 B_wz_media true
setstate notifier_shelly_offline 2024-01-18 09:22:52 Device ECHO_G070VM2421360K8E
setstate notifier_shelly_offline 2024-01-18 08:33:13 cmd 2
setstate notifier_shelly_offline 2024-01-18 08:33:13 cmd_event MQTT2_kuehlschrank
setstate notifier_shelly_offline 2024-01-18 08:33:13 cmd_nr 2
setstate notifier_shelly_offline 2024-01-17 09:43:37 mode enabled
setstate notifier_shelly_offline 2024-01-18 08:33:13 state cmd_2

FHEM 6.1, 2 x RasPi 3B+, Debian Buster; KNX, FS20, HM, HUE, Tradfri, Shellies, KLF200
Rollo-/Lichtsteuerung/-szenarien, T-Sensoren, Fensterkontakte, Heizungssteuerung, HEOS, Sprachsteuerung mit Alexa-FHEM, Netatmo, Nuki, ...

JoWiemann

Hallo,

bitte verschiebe den Post doch in das richtig Board: Automatisierung / DOIF.

Grüße Jörg
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

grappa24

FHEM 6.1, 2 x RasPi 3B+, Debian Buster; KNX, FS20, HM, HUE, Tradfri, Shellies, KLF200
Rollo-/Lichtsteuerung/-szenarien, T-Sensoren, Fensterkontakte, Heizungssteuerung, HEOS, Sprachsteuerung mit Alexa-FHEM, Netatmo, Nuki, ...

betateilchen

Zitat von: grappa24 am 18 Januar 2024, 09:30:45Die Alarmmeldung soll nicht ausgelöst werden wenn B_$DEVICE den (Teil)String "ECHO" oder "schrank" enthält.

Grundproblem: Formuliere die Aufgabe so einfach wie möglich.

Wenn B_$DEVICE den Teilstring enthält, dann enthält auch $DEVICE bereits den Teilstring.
Deshalb würde ich lieber direkt auf $DEVICE arbeiten, anstatt da noch was unnützes wie beispielsweise "B_" drumrum zu bauen.

Das bedeutet nicht zwingend, dass es Deine Aufgabe löst, aber es ist einfach formuliert, besser lesbar und logischer nachvollziehbar.
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

Damian

Du überprüfst hier den Inhalt des Readings nach den Stichwörtern, willst aber offenbar den Namen des Readings prüfen, also

statt [?$SELF:B_$DEVICE] !~ /ECHO/  musst du "B_$DEVICE" !~ /ECHO/ prüfen
Programmierte FHEM-Module: DOIF-FHEM, DOIF-Perl, DOIF-uiTable, THRESHOLD, FHEM-Befehl: IF

grappa24

#5
hatte da gerade eine Idee:

Ich hab die Ausnahmen eh nur eingeführt, weil diese spezellen Devices ("...schrank") nur mal kurz offline gehen (=>online wird false).

(Wie) Könnte man das DOIF so modifizieren, dass es erst dann greift, wenn der Status länger als x min offline ist?
FHEM 6.1, 2 x RasPi 3B+, Debian Buster; KNX, FS20, HM, HUE, Tradfri, Shellies, KLF200
Rollo-/Lichtsteuerung/-szenarien, T-Sensoren, Fensterkontakte, Heizungssteuerung, HEOS, Sprachsteuerung mit Alexa-FHEM, Netatmo, Nuki, ...

Damian

Mit wait warten und dann mit IF die zweite Prüfung vornehmen
Programmierte FHEM-Module: DOIF-FHEM, DOIF-Perl, DOIF-uiTable, THRESHOLD, FHEM-Befehl: IF