Seriennummern Systemweit ermitteln

Begonnen von Hoggle, 27 Juli 2017, 08:08:45

Vorheriges Thema - Nächstes Thema

Hoggle

Hallo.
Ich habe bei mir unter anderem einige Homematic-Geräte verbaut und in unterschiedlichen Räumen und Gruppen sortiert.
Gibt es jetzt irgend einen Befehl (List oder hminfo) wo ich alle Seriennummern der Devices auflisten kann? Habe jetzt so nix gefunden.
Habe mal die Suchfunktion hier im Forum bemüht, da kommen eigentlich nur Themen zum Firmwareupdate, aber wahrscheinlich habe ich mal wieder den falschen Suchbegriff benutzt :-[

ph1959de

Z.B. mit einer readingsGroup mit folgenden (oder ähnlichen) Parametern:

<Gerät>,<Name>,<Raum>,<Model>,<subType>,<FW>,<S/N>,<PairedTo>,<state> TYPE=CUL_HM:+NAME,?!room,?!model,?!subType,?!firmware,!D-serialNr,!R-pairCentral,!state

Wenn nötig, Filter entsprechend erweitern, um die Channels auszublenden, ...

Peter
Aktives Mitglied des FHEM e.V. | Moderator im Forenbereich "Wiki"

Otto123

#2
Hi,

konkret habe ich das so define Serial readingsGroup .*:?serialNr

geht sicher viel besser  ;) aber reichte mir so.

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

frank

oder mal zum ausdrucken
get hminfo param -dv DEF serialNr
FHEM: 6.0(SVN) => Pi3(buster)
IO: CUL433|CUL868|HMLAN|HMUSB2|HMUART
CUL_HM: CC-TC|CC-VD|SEC-SD|SEC-SC|SEC-RHS|Sw1PBU-FM|Sw1-FM|Dim1TPBU-FM|Dim1T-FM|ES-PMSw1-Pl
IT: ITZ500|ITT1500|ITR1500|GRR3500
WebUI [HMdeviceTools.js (hm.js)]: https://forum.fhem.de/index.php/topic,106959.0.html

igami

Darf ich fragen wozu man das benötigt? Ich habe selbst einige HomeMatic Geräte im Einsatz und mich noch nie für die Seriennummer interessiert.

Einmalig auflisten kann man das aber auch über list.
Pi3 mit fhem.cfg + DbLog/logProxy
Komm vorbei zum FHEM Treffen im Kreis Gütersloh! Das nächste Mal im April 2020.

MAINTAINER: archetype, LuftdatenInfo, monitoring, msgDialog, Nmap, powerMap
ToDo: AVScene, FluxLED

Otto123

Zitat von: igami am 27 Juli 2017, 12:43:31
Darf ich fragen wozu man das benötigt? Ich habe selbst einige HomeMatic Geräte im Einsatz und mich noch nie für die Seriennummer interessiert.
Für die Inventur  ;D
Wenn aus irgendeinem Grund alles weg ist (außer die Liste) hat man eine Chance ohne alle UP Dosen auf zu machen, die Aktoren über hmPairSerial neu anzulernen. Das war zumindest mein Beweggrund  am Anfang. Aber recht hast Du einmal listen und gut, ich wusste am Anfang nicht über welche Möglichkeiten das alles geht. Die RG fiel mir irgendwie direkt in die config :)

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

Christoph Morrison

Zitat von: Hoggle am 27 Juli 2017, 08:08:45
Gibt es jetzt irgend einen Befehl (List oder hminfo) wo ich alle Seriennummern der Devices auflisten kann?

Der Vollständigkeit halber:
Ich hole mir die Serials aus der Config, nicht aus dem Live-System. Denn der letzte Stand meiner Config muss nicht der des Live-Systems sein (Änderungen werden erst auf ein Testsystem gespielt und dort getestet). Die Liste mit den Serials wird dabei auch gleich auf Dubletten überprüft und es wird eine kleine Statistik ausgeworfen:


#!/usr/bin/env bash
# ****** CONFIG ******
# ********************

# path to the basic fhem config directory
fhem_config_dir="/opt/fhem-config"

# path of the source directory
fhem_source_dir="${fhem_config_dir}/source"

# path to the serials db file
serials_db_file="${fhem_config_dir}/var/homematic-serials.db"

# ****** HELPER FUNCTIONS ******
# ******************************

# prepare environment
#   See http://www.davidpashley.com/articles/writing-robust-shell-scripts/
set -o nounset
set -o errexit

# temporary file for the found serials, will be deleted at the end of this program
_tempFile="/tmp/$(basename $0).$$"

# catch exits and clean up if any is catched
trap "rm -f ${_tempFile}; exit 1" INT TERM EXIT

# check if colours are supported
#   tput colors returns the supported amount of colours by the current shell, i.e. 256 or 2
#   if 8 or more colours are supported, set a true flag
_coloursSupportedAmount=$(tput colors)

if test -n "${_coloursSupportedAmount}" && test "${_coloursSupportedAmount}" -ge 8; then
    _coloursAreSupported=true
fi

# check if we are attached to a pipe or else and then disable tput colours again
if [[ ! -t 1 || -p /dev/stdout ]]; then
    _coloursAreSupported=false
    (>&2 echo "Redirection detected, colours are disabled.")
fi

bold()          { ansi  1 "$@"; }
italic()        { ansi  3 "$@"; }
underline()     { ansi  4 "$@"; }
strike()        { ansi  9 "$@"; }
red()           { ansi 31 "$@"; }
green()         { ansi 32 "$@"; }
yellow()        { ansi 33 "$@"; }
purple()        { ansi 35 "$@"; }
cyan()          { ansi 36 "$@"; }
white()         { ansi 37 "$@"; }

ansi() {
    if [ "${_coloursAreSupported}" = true ]; then
        printf "\e[${1}m${*:2}\e[0m";
    else
        echo ${*:2}
    fi
}

# check for an array
is_array() {
    local variable_name=$1
    [[ "$(declare -p $variable_name)" =~ "declare -a" ]]
}

# ****** MAIN ******
# ******************

# check if the source directory or file exists
if [[ ! -d  "${fhem_source_dir}" && ! -f "${fhem_source_dir}" ]]; then
    (>&2 echo "$(red Source) $(cyan ${fhem_source_dir}) $(red not found. Aborting.)")
    exit 1
fi

# grep all the serial attributes to awk and filter just
#   the device name ($2) and the serial ($4) into the temporary file
#   then filter just the unique ids to the final db file
grep -hiR -e '^[^#].*serialNr.*' ${fhem_source_dir} | gawk -v OFS="," '{print $4,$2}' > "${_tempFile}"
uniq -u -w10 "${_tempFile}" > "${serials_db_file}"

# create statistics
_serial_count=$(wc -l "${serials_db_file}" | cut -f1 -d' ')

# status report the amount of found serials and the target file
echo $(green $(bold "${_serial_count}")) $(green "devices found and listed to") $(cyan "${serials_db_file}")

# get doublets
readarray _doublets < <( cut -f2 -d' ' "${_tempFile}" | uniq -d )

is_array "_doublets" && {

    _doubletsLength=${#_doublets[@]}

    if [ "${_doubletsLength}" != "0" ]; then
        echo $(red $(bold "${_doubletsLength} doublet serial(s) found:"))

        for (( i = 0; i < "${_doubletsLength}"; i++ )); do
          echo "    " $(red "${_doublets[$i]}")
        done
    fi
}