1

Temat: AI i satel integra powiadomienia ethm-1

Tez pobawilem sie z AI mam centrale ethm-1 i satel integra 64 i chcialem miec powiadomienia, wybralem pushbulet.
AI na bazie biblioteki openhaba (to co uzywalem) zrobilo skrypt w ksh do monitorowania alarmu i wysylania powiadomien, mozna wykorzystac modem gsm na porcie usb i wysylac sms. tu wymaga zainstalowania pushbuleta i wgrannia api keya do /etc/config/pus. calosc zajela 2h zabawy z roznymi AI, niektore niepotrafily, ale razem sobie poradzily :-)

Cala konfiguracja:


config push 'pushbullet'
    # Pushbullet notifications. Get your API key at https://www.pushbullet.com/
    option enabled '1'
    option push_api 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

#config push 'ciscospark'
    # Cisco Spark notifications. Get your auth token at https://developer.ciscospark.com/
#    option enabled '0'
#    option auth_token ''
#    option dest_uuid '

pushbulet skrypt w /usr/bin/push.sh:

#!/bin/sh

log() {
        echo "push.sh: $@"
        logger -t "push.sh" "$@"
}

SUBJECT="$1"
MSG="$2"

################
# PushBullet
################

PB_ENABLED=$(uci get push.pushbullet.enabled)
API=$(uci get push.pushbullet.push_api)

if [ $PB_ENABLED == 1 ]; then
    if [ ! -z $API ]; then
          curl -k -u $API: https://api.pushbullet.com/v2/pushes -d type=note --data-urlencode "title=$SUBJECT" --data-urlencode "body=$MSG" > /dev/null 2>&1
    else
          log "Set your PushBullet API key in /etc/config/push"
    fi
fi

################
# Cisco Spark
################

#SPARK_AUTH=$(uci get push.ciscospark.auth_token)
#SPARK_UUID=$(uci get push.ciscospark.dest_uuid)
#SPK_ENABLED=$(uci get push.ciscospark.enabled)

if [ $SPK_ENABLED == 1 ]; then
    if [ ! -z $SPARK_AUTH ]; then
            # Send a message to me via Cisco Spark
        SPARK_MSG="$SUBJECT
    
        $MSG"
            curl -k https://api.ciscospark.com/v1/messages -X POST -H "Authorization:Bearer $SPARK_AUTH" --data "toPersonId=$SPARK_UUID" --data-urlencode "text=$SPARK_MSG"  > /dev/null 2>&1
    else
        log "Set your Cisco Spark AUTH token in /etc/config/push"
    fi
fi

Czytanie centrali integra 64 z wysylaniem powiadomien:

#!/bin/sh
# SATEL INTEGRA 64 + ETHM-1 - odczyt stanu w petli co 5s + PushBullet (UCI)
# Dziala w busybox ash / ksh. Wymaga: nc, od (lub hexdump), curl (dla PushBullet).

ETHM_IP="192.168.xxx.xxx"
ETHM_PORT="7094"
USER_CODE="xxxx"
INTERVAL=5
WAIT=1
RETRIES=2
SHOW_RAW="${SHOW_RAW:-0}"

# Ile sekund uzbrojone strefy musza pozostac niezmienione, aby uznano ze zalaczanie sie zakonczylo
ARM_SETTLE_SEC="${ARM_SETTLE_SEC:-10}"

# Powiadomienia PushBullet (1 = aktywne, 0 = wylaczone)
PB_NOTIFY="${PB_NOTIFY:-1}"
# 1 = wysylaj tez przy naruszeniu wejscia; 0 = tylko zalaczenie/wylaczenie, alarm, skasowanie, bledy
NOTIFY_VIOLATIONS="${NOTIFY_VIOLATIONS:-0}"

if [ -n "${NO_COLOR:-}" ]; then
    C_RED=""
    C_GRN=""
    C_YLW=""
    C_RST=""
else
    ESC=$(printf '\033')
    C_RED="${ESC}[1;31m"
    C_GRN="${ESC}[1;32m"
    C_YLW="${ESC}[1;33m"
    C_RST="${ESC}[0m"
fi

RESP=""
LAST_RAW_DEC=""
LAST_ERR_TYPE=""
CONNECTED_OK=0
LAST_BITS=""

# Poprzednie stany do wykrywania zmian
PREV_CONN=-1
PREV_ALARM_ACTIVE=""
PREV_ALARM_MEM=""
PREV_VIO_ZONE=""

# Stan stabilizacji zalaczania / wylaczania alarmu (czuwania)
ARM_CANDIDATE=""
ARM_CANDIDATE_SINCE=0
ARM_WAS_ARMED=0

pb_log() {
    printf '%s[PushBullet] %s%s\n' "$C_YLW" "$*" "$C_RST"
    logger -t "satel-pb" "$*" 2>/dev/null || true
}

now_epoch() {
    date +%s 2>/dev/null || echo 0
}

send_pushbullet() {
    pb_title="$1"
    pb_body="$2"

    [ "${PB_NOTIFY:-0}" -eq 1 ] || {
        pb_log "Pominieto (PB_NOTIFY=${PB_NOTIFY}): ${pb_title}"
        return 0
    }

    pb_enabled=$(uci get push.pushbullet.enabled 2>/dev/null | tr -d '\r\n')
    pb_api=$(uci get push.pushbullet.push_api 2>/dev/null | tr -d '\r\n')

    if [ "$pb_enabled" != "1" ]; then
        pb_log "PushBullet wylaczony w UCI (push.pushbullet.enabled='${pb_enabled}')"
        return 0
    fi

    if [ -z "$pb_api" ]; then
        pb_log "Brak klucza API w /etc/config/push (push.pushbullet.push_api)"
        return 1
    fi

    if ! command -v curl >/dev/null 2>&1; then
        pb_log "Brak polecenia curl - nie wyslano: ${pb_title}"
        return 1
    fi

    pb_resp_tmp="/tmp/satel_pb_resp.$$"
    http_code=$(curl -k -s -o "$pb_resp_tmp" -w "%{http_code}" \
        -u "${pb_api}:" https://api.pushbullet.com/v2/pushes \
        -d type=note \
        --data-urlencode "title=$pb_title" \
        --data-urlencode "body=$pb_body" 2>/dev/null)
    curl_rc=$?

    if [ "$curl_rc" -eq 0 ] && [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
        pb_log "Wyslano [HTTP ${http_code}]: '${pb_title}' -> '${pb_body}'"
    else
        err_body=$(cat "$pb_resp_tmp" 2>/dev/null | tr '\n' ' ')
        pb_log "BLAD wysylki [rc=${curl_rc}, HTTP=${http_code:-brak}]: '${pb_title}' ${err_body}"
    fi
    rm -f "$pb_resp_tmp"
}

calculate_crc() {
    crc=$((0x147A))
    for byte in "$@"; do
        crc=$(( ((crc << 1) | (crc >> 15)) & 0xFFFF ))
        crc=$(( crc ^ 0xFFFF ))
        high=$(( (crc >> 8) & 0xFF ))
        crc=$(( (crc + high + byte) & 0xFFFF ))
    done
    echo "$crc"
}

encode_code_bcd() {
    code_str=$1
    padded=$(printf '%-16s' "$code_str" | tr ' ' 'F')

    idx=1
    while [ "$idx" -le 15 ]; do
        hi_ch=$(printf '%s' "$padded" | cut -c "$idx")
        lo_ch=$(printf '%s' "$padded" | cut -c "$((idx + 1))")

        case "$hi_ch" in
            [0-9]) hi_val=$hi_ch ;;
            *) hi_val=15 ;;
        esac

        case "$lo_ch" in
            [0-9]) lo_val=$lo_ch ;;
            *) lo_val=15 ;;
        esac

        printf '%d\n' "$(( (hi_val << 4) | lo_val ))"
        idx=$((idx + 2))
    done
}

escaped_byte() {
    if [ "$1" -eq 254 ]; then
        printf '\\376\\360'
    else
        printf '\\%03o' "$1"
    fi
}

build_frame() {
    crc=$(calculate_crc "$@")
    crc_high=$(( (crc >> 8) & 0xFF ))
    crc_low=$(( crc & 0xFF ))

    frame='\376\376'
    for byte in "$@" "$crc_high" "$crc_low"; do
        frame="$frame$(escaped_byte "$byte")"
    done
    frame="$frame"'\376\015'
    printf '%s' "$frame"
}

dump_bytes() {
    if od -An -v -tu1 </dev/null >/dev/null 2>&1; then
        od -An -v -tu1
    else
        hexdump -v -e '1/1 "%u "'
    fi
}

nc_query() {
    tmp="/tmp/satel_rx.$$"
    : > "$tmp"
    (printf "$frame"; sleep "$WAIT") \
        | nc "$ETHM_IP" "$ETHM_PORT" > "$tmp" 2>/dev/null &
    nc_pid=$!
    sleep "$WAIT"
    kill "$nc_pid" 2>/dev/null
    wait "$nc_pid" 2>/dev/null
    dump_bytes < "$tmp"
    rm -f "$tmp"
}

dec_list_to_hex() {
    out=""
    for b in $1; do
        hex_b=$(printf '%02X' "$b")
        if [ -z "$out" ]; then
            out="$hex_b"
        else
            out="$out $hex_b"
        fi
    done
    printf '%s' "$out"
}

parse_response() {
    started=0
    escaped=0
    prev=-1
    raw=""
    RESP=""

    for b in $1; do
        if [ "$started" -eq 0 ]; then
            if [ "$prev" -eq 254 ] && [ "$b" -eq 254 ]; then
                started=1
                raw=""
            fi
            prev=$b
            continue
        fi

        if [ "$escaped" -eq 1 ]; then
            if [ "$b" -eq 240 ]; then
                raw="$raw 254"
                escaped=0
            elif [ "$b" -eq 13 ]; then
                RESP=${raw# }
                return 0
            elif [ "$b" -eq 254 ]; then
                raw=""
                escaped=0
            else
                raw=""
                escaped=0
                prev=$b
                started=0
            fi
            continue
        fi

        if [ "$b" -eq 254 ]; then
            escaped=1
        else
            raw="$raw $b"
        fi
    done
    return 1
}

verify_response_crc() {
    set -- $RESP
    count=$#
    [ "$count" -ge 3 ] || return 1

    i=0
    payload=""
    for x in "$@"; do
        i=$((i + 1))
        if [ "$i" -le $((count - 2)) ]; then
            payload="$payload $x"
        elif [ "$i" -eq $((count - 1)) ]; then
            hi=$x
        else
            lo=$x
        fi
    done

    received=$(( (hi << 8) | lo ))
    calculated=$(calculate_crc $payload)
    [ "$received" -eq "$calculated" ]
}

send_command() {
    cmd=$1
    with_code=${2:-0}
    LAST_RAW_DEC=""
    LAST_ERR_TYPE=""

    if [ "$with_code" = "WITH_CODE" ]; then
        code_bytes=$(encode_code_bcd "$USER_CODE")
        # shellcheck disable=SC2086
        frame=$(build_frame "$cmd" $code_bytes)
    else
        frame=$(build_frame "$cmd")
    fi

    try=0
    while [ "$try" -lt "$RETRIES" ]; do
        try=$((try + 1))
        bytes=$(nc_query)
        LAST_RAW_DEC="$bytes"

        if [ -z "$(printf '%s' "$bytes" | tr -d ' \t\r\n')" ]; then
            LAST_ERR_TYPE="brak odpowiedzi z ${ETHM_IP}:${ETHM_PORT} (cmd $cmd)"
        elif ! parse_response "$bytes"; then
            LAST_ERR_TYPE="niepoprawna ramka (cmd $cmd)"
        elif ! verify_response_crc; then
            LAST_ERR_TYPE="blad sumy CRC (cmd $cmd)"
        else
            set -- $RESP
            if [ "${1:-}" -eq "$cmd" ]; then
                LAST_ERR_TYPE=""
                CONNECTED_OK=1
                [ -n "${DEBUG:-}" ] && echo "RX cmd=$cmd: $RESP" >&2
                return 0
            else
                LAST_ERR_TYPE="niezgodny numer komendy (oczekiwano $cmd, otrzymano ${1:-?})"
            fi
        fi

        [ -n "${DEBUG:-}" ] && echo "RX cmd=$cmd blad ($LAST_ERR_TYPE), surowe: $bytes" >&2
        sleep 1
    done
    return 1
}

print_raw_reply() {
    [ "${SHOW_RAW:-0}" -eq 1 ] || return 0
    if [ -n "$LAST_RAW_DEC" ]; then
        hex_str=$(dec_list_to_hex "$LAST_RAW_DEC")
        printf '       HEX: %s\n' "$hex_str"
        printf '       DEC: %s\n' "$LAST_RAW_DEC"
    else
        printf '       RAW: brak bajtow\n'
    fi
}

format_csv_list() {
    printf '%s' "$1" | sed 's/^ *//; s/  */ /g; s/ /, /g'
}

merge_unique_nums() {
    all_nums="$1 $2"
    out=""
    for n in $all_nums; do
        case " $out " in
            *" $n "*) ;;
            *)
                if [ -z "$out" ]; then
                    out="$n"
                else
                    out="$out $n"
                fi
                ;;
        esac
    done
    printf '%s' "$out"
}

fetch_active_bits() {
    cmd=$1
    mode=${2:-0}
    LAST_BITS=""

    if ! send_command "$cmd" "$mode"; then
        return 1
    fi

    set -- $RESP
    count=$#
    active=""
    i=0
    for byte in "$@"; do
        i=$((i + 1))
        [ "$i" -eq 1 ] && continue
        [ "$i" -gt $((count - 2)) ] && break

        n=0
        while [ "$n" -lt 8 ]; do
            if [ $(( (byte >> n) & 1 )) -eq 1 ]; then
                active="$active $(( (i - 2) * 8 + n + 1 ))"
            fi
            n=$((n + 1))
        done
    done

    LAST_BITS=$(printf '%s' "$active" | sed 's/^ *//; s/  */ /g')
    return 0
}

print_state_line() {
    description=$1
    ok_flag=${2:-0}
    bits_val=$3
    empty_msg=$4
    active_prefix=$5
    alert_mode=${6:-0}

    if [ "${ok_flag:-0}" -ne 1 ]; then
        printf '  %-28s %s[BLAD ODCZYTU]%s\n' "$description" "$C_RED" "$C_RST"
        print_raw_reply
        return
    fi

    if [ -z "$bits_val" ]; then
        if [ "$alert_mode" -eq 1 ]; then
            printf '  %-28s %s%s%s\n' "$description" "$C_GRN" "$empty_msg" "$C_RST"
        else
            printf '  %-28s %s\n' "$description" "$empty_msg"
        fi
    else
        list_csv=$(format_csv_list "$bits_val")
        if [ -n "$active_prefix" ]; then
            line_val="${active_prefix}: ${list_csv}"
        else
            line_val="${list_csv}"
        fi

        if [ "$alert_mode" -eq 1 ]; then
            printf '  %-28s %s%s%s\n' "$description" "$C_RED" "$line_val" "$C_RST"
        else
            printf '  %-28s %s\n' "$description" "$line_val"
        fi
    fi
    print_raw_reply
}

read_module_version_line() {
    CONNECTED_OK=0
    if ! send_command 124; then
        printf '  %-28s %s[BLAD ODCZYTU]%s\n' "Modul ETHM-1" "$C_RED" "$C_RST"
        print_raw_reply
        return 1
    fi

    set -- $RESP
    count=$#
    raw_ascii=""
    i=0
    for byte in "$@"; do
        i=$((i + 1))
        [ "$i" -eq 1 ] && continue
        [ "$i" -gt 12 ] && break
        [ "$i" -gt $((count - 2)) ] && break
        if [ "$byte" -ge 32 ] && [ "$byte" -le 126 ]; then
            ch=$(printf '%b' "$(printf '\\0%03o' "$byte")")
            raw_ascii="${raw_ascii}${ch}"
        fi
    done

    if [ "${#raw_ascii}" -eq 11 ]; then
        maj=$(printf '%s' "$raw_ascii" | cut -c 1)
        min=$(printf '%s' "$raw_ascii" | cut -c 2-3)
        yr=$(printf '%s' "$raw_ascii" | cut -c 4-7)
        mo=$(printf '%s' "$raw_ascii" | cut -c 8-9)
        dy=$(printf '%s' "$raw_ascii" | cut -c 10-11)
        printf '  %-28s fw %s.%s (%s-%s-%s)\n' "Modul ETHM-1" "$maj" "$min" "$yr" "$mo" "$dy"
    else
        printf '  %-28s %s\n' "Modul ETHM-1" "$raw_ascii"
    fi
    print_raw_reply
    return 0
}

handle_notifications() {
    ts="$1"
    curr_conn="${2:-0}"
    err_reason="$3"
    armed_now="$4"
    alarm_now="$5"
    alarm_mem_now="$6"
    vio_zone="$7"
    now_s=$(now_epoch)

    if [ "$curr_conn" -eq 0 ]; then
        if [ "${PREV_CONN:- -1}" -ne 0 ] || [ -n "$err_reason" ]; then
            reason_txt="${err_reason:-brak odpowiedzi z centrali}"
            send_pushbullet "Blad" "SATEL: ${reason_txt} [${ts}]"
        fi
    fi

    if [ "$curr_conn" -eq 1 ]; then
        if [ -n "$armed_now" ]; then
            if [ "$armed_now" != "$ARM_CANDIDATE" ]; then
                ARM_CANDIDATE="$armed_now"
                ARM_CANDIDATE_SINCE="$now_s"
            else
                elapsed=$((now_s - ARM_CANDIDATE_SINCE))
                if [ "$elapsed" -ge "${ARM_SETTLE_SEC:-10}" ] && [ "${ARM_WAS_ARMED:-0}" -eq 0 ]; then
                    send_pushbullet "Zalaczono alarm" "Alarm zalaczony [${ts}]"
                    ARM_WAS_ARMED=1
                fi
            fi
        else
            if [ "${ARM_WAS_ARMED:-0}" -eq 1 ]; then
                send_pushbullet "Wylaczono alarm" "Wszystkie strefy rozbrojone [${ts}]"
                ARM_WAS_ARMED=0
            fi
            ARM_CANDIDATE=""
            ARM_CANDIDATE_SINCE=0
        fi

        if [ -n "$alarm_now" ] && [ "$alarm_now" != "$PREV_ALARM_ACTIVE" ]; then
            send_pushbullet "ALARM! Wlamanie/Pozar" "SATEL (${ts}): $(format_csv_list "$alarm_now")"
        fi

        if [ -z "$alarm_mem_now" ] && [ -n "$PREV_ALARM_MEM" ]; then
            send_pushbullet "Skasowano alarm" "SATEL (${ts}): pamiec skasowana"
        fi

        if [ "${NOTIFY_VIOLATIONS:-0}" -eq 1 ] && [ -n "$vio_zone" ] && [ "$vio_zone" != "$PREV_VIO_ZONE" ]; then
            send_pushbullet "Naruszenie" "SATEL (${ts}): wejscia $(format_csv_list "$vio_zone")"
        fi
    fi

    PREV_CONN="$curr_conn"
    PREV_ALARM_ACTIVE="$alarm_now"
    PREV_ALARM_MEM="$alarm_mem_now"
    PREV_VIO_ZONE="$vio_zone"
}

run_poll_cycle() {
    now_ts=$(date '+%Y-%m-%d %H:%M:%S' 2>/dev/null || echo "-")
    printf '\n==================================================\n'
    printf '[%s] Laczenie z centrala %s:%s...\n' "$now_ts" "$ETHM_IP" "$ETHM_PORT"

    sys_tmp="/tmp/satel_sys.$$"
    read_module_version_line > "$sys_tmp"
    curr_conn="${CONNECTED_OK:-0}"
    err_reason="${LAST_ERR_TYPE:-}"
    sys_out=$(cat "$sys_tmp")
    rm -f "$sys_tmp"

    if [ "$curr_conn" -eq 1 ]; then
        printf '%sPolaczono z centrala SATEL INTEGRA 64 (%s:%s).%s\n' "$C_GRN" "$ETHM_IP" "$ETHM_PORT" "$C_RST"
    else
        printf '%sBrak polaczenia / blad (%s) z centrala %s:%s.%s\n' "$C_RED" "${err_reason:-brak odpowiedzi}" "$ETHM_IP" "$ETHM_PORT" "$C_RST"
    fi

    arm_sup=""; ok_arm_sup=0
    arm_full=""; ok_arm_full=0
    alm_part=""; ok_alm_part=0
    alm_fire=""; ok_alm_fire=0
    vio_zone=""; ok_vio_zone=0
    tam_zone=""; ok_tam_zone=0
    alm_zone=""; ok_alm_zone=0
    mem_zone=""; ok_mem_zone=0
    mem_part=""; ok_mem_part=0
    byp_zone=""; ok_byp_zone=0
    out_on=""; ok_out_on=0

    if [ "$curr_conn" -eq 1 ]; then
        if fetch_active_bits 9 0; then arm_sup="$LAST_BITS"; ok_arm_sup=1; fi
        if fetch_active_bits 10 0; then arm_full="$LAST_BITS"; ok_arm_full=1; fi
        if fetch_active_bits 19 0; then alm_part="$LAST_BITS"; ok_alm_part=1; fi
        if fetch_active_bits 20 0; then alm_fire="$LAST_BITS"; ok_alm_fire=1; fi
        if fetch_active_bits 0 0; then vio_zone="$LAST_BITS"; ok_vio_zone=1; fi
        if fetch_active_bits 1 0; then tam_zone="$LAST_BITS"; ok_tam_zone=1; fi
        if fetch_active_bits 2 0; then alm_zone="$LAST_BITS"; ok_alm_zone=1; fi
        if fetch_active_bits 4 0; then mem_zone="$LAST_BITS"; ok_mem_zone=1; fi
        if fetch_active_bits 21 0; then mem_part="$LAST_BITS"; ok_mem_part=1; fi
        if fetch_active_bits 6 0; then byp_zone="$LAST_BITS"; ok_byp_zone=1; fi
        if fetch_active_bits 23 0; then out_on="$LAST_BITS"; ok_out_on=1; fi
    fi

    printf '[System]\n'
    printf '%s\n' "$sys_out"

    printf '\n[Strefy]\n'
    print_state_line "Czuwanie (suppressed)" "$ok_arm_sup" "$arm_sup" "alarm rozlaczony" "alarm zalaczony (strefy)" 1
    print_state_line "Czuwanie (pelne)" "$ok_arm_full" "$arm_full" "alarm rozlaczony" "alarm zalaczony (strefy)" 1
    print_state_line "Alarm (wlamanie)" "$ok_alm_part" "$alm_part" "brak wlamania" "WYCIE ALARMU (strefy)" 1
    print_state_line "Alarm pozarowy" "$ok_alm_fire" "$alm_fire" "brak pozaru" "ALARM POZAROWY (strefy)" 1
    print_state_line "Pamiec alarmu" "$ok_mem_part" "$mem_part" "brak pamieci zdarzen" "pamiec w strefach" 0

    printf '\n[Wejscia / Zony]\n'
    print_state_line "Naruszone" "$ok_vio_zone" "$vio_zone" "wszystkie zamkniete / spoczynek" "naruszone wejscia" 1
    print_state_line "Sabotaz (tamper)" "$ok_tam_zone" "$tam_zone" "brak sabotazu / ok" "sabotaz na wejsciach" 1
    print_state_line "Alarm (wejscia)" "$ok_alm_zone" "$alm_zone" "brak alarmu" "WYCIE ALARMU (wejscia)" 1
    print_state_line "Pamiec alarmu" "$ok_mem_zone" "$mem_zone" "brak pamieci zdarzen" "pamiec na wejsciach" 0
    print_state_line "Zablokowane (bypass)" "$ok_byp_zone" "$byp_zone" "brak zablokowanych" "zablokowane wejscia" 0

    printf '\n[Wyjscia]\n'
    print_state_line "Wyjscia" "$ok_out_on" "$out_on" "wszystkie wylaczone" "wlaczone wyjscia" 0

    armed_combined=$(merge_unique_nums "$arm_sup" "$arm_full")
    alarm_active_combined=$(merge_unique_nums "$alm_part" "$alm_fire")
    alarm_active_combined=$(merge_unique_nums "$alarm_active_combined" "$alm_zone")
    alarm_mem_combined=$(merge_unique_nums "$mem_part" "$mem_zone")

    printf '\n[Status alarmu]\n'
    if [ "$curr_conn" -ne 1 ]; then
        printf '  %-28s %sbrak danych%s\n' "Stan systemu" "$C_RED" "$C_RST"
    elif [ -n "$alarm_active_combined" ]; then
        printf '  %-28s %sWYCIE ALARMU (%s)!%s\n' "Stan systemu" "$C_RED" "$(format_csv_list "$alarm_active_combined")" "$C_RST"
    elif [ -n "$armed_combined" ]; then
        printf '  %-28s %salarm zalaczony (strefy: %s)%s\n' "Stan systemu" "$C_RED" "$(format_csv_list "$armed_combined")" "$C_RST"
    else
        printf '  %-28s %salarm rozlaczony%s\n' "Stan systemu" "$C_GRN" "$C_RST"
    fi

    handle_notifications "$now_ts" "$curr_conn" "$err_reason" "$armed_combined" "$alarm_active_combined" "$alarm_mem_combined" "$vio_zone"
}

command -v nc >/dev/null 2>&1 || { echo "Brak polecenia: nc" >&2; exit 1; }

while true; do
    run_poll_cycle
    sleep "$INTERVAL"
done

taki wynik:

=================================================
[2026-11-23 21:03:11] Laczenie z centrala 192.168.xxx.xxx:7094...
Polaczono z centrala SATEL INTEGRA 64 (192.168.xxx.xxx:7094).
[System]
  Modul ETHM-1                 fw 1.07 (2015-03-02)

[Strefy]
  Czuwanie (suppressed)        alarm rozlaczony
  Czuwanie (pelne)             alarm rozlaczony
  Alarm (wlamanie)             brak wlamania
  Alarm pozarowy               brak pozaru
  Pamiec alarmu                brak pamieci zdarzen

[Wejscia / Zony]
  Naruszone                    wszystkie zamkniete / spoczynek
  Sabotaz (tamper)             brak sabotazu / ok
  Alarm (wejscia)              brak alarmu
  Pamiec alarmu                brak pamieci zdarzen
  Zablokowane (bypass)         brak zablokowanych

[Wyjscia]
  Wyjscia                      wlaczone wyjscia: 3

[Status alarmu]
  Stan systemu                 alarm rozlaczony

#i 2 opcja:

zalaczenie

[2026-11-23 21:04:56] Laczenie z centrala 192.168.xxx.xxx:7094...
Polaczono z centrala SATEL INTEGRA 64 (192.168.xxx.xxx:7094).
[System]
  Modul ETHM-1                 fw 1.07 (2015-03-02)

[Strefy]
  Czuwanie (suppressed)        alarm zalaczony (strefy): 2
  Czuwanie (pelne)             alarm zalaczony (strefy): 2
  Alarm (wlamanie)             brak wlamania
  Alarm pozarowy               brak pozaru
  Pamiec alarmu                brak pamieci zdarzen

[Wejscia / Zony]
  Naruszone                    wszystkie zamkniete / spoczynek
  Sabotaz (tamper)             brak sabotazu / ok
  Alarm (wejscia)              brak alarmu
  Pamiec alarmu                brak pamieci zdarzen
  Zablokowane (bypass)         brak zablokowanych

[Wyjscia]
  Wyjscia                      wlaczone wyjscia: 3

[Status alarmu]
  Stan systemu                 alarm zalaczony (strefy: 2)
[PushBullet] Wyslano [HTTP 200]: 'Zalaczono alarm' -> 'Alarm zalaczony [2026-11-23 21:04:56]'

jeszcze init.d

#!/bin/sh /etc/rc.common
# Skrypt startowy procd dla /etc/satel.sh (SATEL INTEGRA + PushBullet)

START=99
STOP=15
USE_PROCD=1

SATEL_BIN="/etc/satel.sh"
SATEL_LOG="/var/log/satel.log"

start_service() {
    if [ ! -x "$SATEL_BIN" ]; then
        logger -t "satel-init" "Brak wykonywalnego pliku $SATEL_BIN"
        return 1
    fi

    procd_open_instance "satel"
    # Wymuszamy NO_COLOR=1 dla czystego logu bez kodow sterujacych ANSI
    procd_set_param env NO_COLOR=1
    procd_set_param command /bin/sh "$SATEL_BIN"
    # Automatyczny restart w razie awarii procesu
    procd_set_param respawn 3600 5 0
    # Logowanie stdout i stderr do logread / systemowego logu procd
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_close_instance
}

stop_service() {
    :
}

service_triggers() {
    procd_add_reload_trigger "push"
}

Odp: AI i satel integra powiadomienia ethm-1

Thanks for sharing the full setup — seeing the whole script, the Pushbullet config and the start-up script together makes it much easier to follow than just the idea on its own. The two hours of work sounds about right for getting the polling and the notifications to line up. How has it held up since you put it in place — have the notifications stayed reliable, and have you had any false alarms or missed state changes with the five-second loop? I am also curious whether the connection to the ETHM-1 has stayed stable over longer periods.

3 (edytowany przez roblad 2026-11-24 23:05:56)

Odp: AI i satel integra powiadomienia ethm-1

elizacommunities napisał/a:

Thanks for sharing the full setup — seeing the whole script, the Pushbullet config and the start-up script together makes it much easier to follow than just the idea on its own. The two hours of work sounds about right for getting the polling and the notifications to line up. How has it held up since you put it in place — have the notifications stayed reliable, and have you had any false alarms or missed state changes with the five-second loop? I am also curious whether the connection to the ETHM-1 has stayed stable over longer periods.

A fix is needed for the disconnected state because it causes false alarms, while the rest work correctly. I hadn't accounted for Satel being disconnected. Give this to the AI to fix. Also you can ask IA to translat to English if you need. That is mostly stable but experiences occasional, brief drops followed by automatic reconnection attempts.

Odp: AI i satel integra powiadomienia ethm-1

Thanks for the update — good to hear the rest is stable. Do the false alarms happen on every brief drop, or only when the disconnect lasts a bit longer? It would be interesting to know whether holding off the alarm notification until the connection is confirmed back would help.

5 (edytowany przez roblad 2026-11-26 18:02:37)

Odp: AI i satel integra powiadomienia ethm-1

elizacommunities napisał/a:

Thanks for the update — good to hear the rest is stable. Do the false alarms happen on every brief drop, or only when the disconnect lasts a bit longer? It would be interesting to know whether holding off the alarm notification until the connection is confirmed back would help.

No, only when the port and connection are busy, but that would be irritating. It's better to remove it or use a counter, e.g., after 15 unsuccessful attempts