{% extends 'base.html.twig' %} {% import 'components/json_display.html.twig' as jsonDisplay %} {% import 'components/datalogger_tabs.html.twig' as tabs %} {% block title %}HAT Sensoren - Dashboard{% endblock %} {% block content %} {% if apiAvailable is defined and not apiAvailable %}
Warnung: Datalogger API ist nicht erreichbar. Die angezeigten Daten können veraltet sein.
{% endif %} {% if datalogger is defined %} {{ tabs.renderTabs(datalogger, app.request.attributes.get('_route')) }} {% endif %}
Auto-Refresh:
{% if datalogger is defined %} Alle Charts {% endif %}
{# Alte Durchschnittswerte (Fallback) #}

Durchschnittswerte

{% if avgTemperature is not null %}{{ avgTemperature|number_format(2) }}°C{% endif %} Ø Temperatur (HAT5)
{% if avgPressure is not null %}{{ avgPressure|number_format(2) }}{% endif %} Ø Druck (HAT1)
{% if hatsData.error is defined %}
Fehler: {{ hatsData.error }}
{% elseif hatsData %} {# Prüfe ob hatsData direkt die HAT-Struktur enthält oder in hat_data verschachtelt ist #} {% set hatDataToProcess = hatsData.hat_data is defined and hatsData.hat_data is iterable ? hatsData.hat_data : (hatsData is iterable ? hatsData : {}) %} {% if hatDataToProcess and hatDataToProcess is iterable %} {# Iteriere über alle HATs #} {% for hatKey, hat in hatDataToProcess %} {% if hat is iterable and hat.inputs is defined and hat.inputs is iterable %} {% set hatName = hat.name is not iterable ? hat.name : hatKey %} {% set hatStack = hat.stack is not iterable ? hat.stack : null %} {% set isHatHidden = false %} {% if not isAdmin %} {% for hidden in hiddenSensors %} {# Prüfe ob HAT komplett versteckt ist (channel ist null) #} {% if hidden.hatName == hatName and hidden.channel is null and (hidden.stack is null or hidden.stack == hatStack) %} {% set isHatHidden = true %} {% endif %} {% endfor %} {% endif %} {% if not isHatHidden %}

{% if hat.name is not iterable %}{{ hat.name }}{% else %}{{ hatKey }}{% endif %}

Stack {% if hat.stack is not iterable %}{{ hat.stack }}{% else %}N/A{% endif %}
{% if hat.address is defined and hat.address is not iterable %} Address: {{ hat.address }} {% endif %} {% if hat.version is defined and hat.version is not iterable %} v{{ hat.version }} {% endif %} {% if hat.timestamp is defined and hat.timestamp is not iterable %} {% if hat.timestamp > 1000000000 %} {{ hat.timestamp|round|date('d.m.Y H:i:s') }} {% else %} {{ hat.timestamp }} {% endif %} {% endif %}
{% for input in hat.inputs %} {% if input is iterable %} {% set inputChannel = input.channel is not iterable ? input.channel : null %} {% set isChannelHidden = false %} {% if not isAdmin %} {% for hidden in hiddenSensors %} {# Prüfe ob spezifischer Channel versteckt ist #} {% if hidden.hatName == hatName and (hidden.stack is null or hidden.stack == hatStack) and hidden.channel == inputChannel %} {% set isChannelHidden = true %} {% endif %} {% endfor %} {% endif %} {% if not isChannelHidden %} {# Initialisiere Variablen mit Standardwerten #} {% set normalizedValue = 0 %} {% set percentage = 0 %} {% set isLow = false %} {% set isHigh = false %} {% set isInRange = false %} {# Berechne normalizedValue nur wenn calibrated_value nicht vorhanden ist (altes Format) #} {% if input.calibrated_value is not defined or input.calibrated_value is iterable %} {# Altes Format #} {% set normalizedValue = (input.raw_value is defined and input.raw_value is not iterable and input.raw_min is defined and input.raw_min is not iterable and input.raw_max is defined and input.raw_max is not iterable and input.default_min is defined and input.default_min is not iterable and input.default_max is defined and input.default_max is not iterable and (input.raw_max - input.raw_min) != 0) ? ((input.raw_value - input.raw_min) / (input.raw_max - input.raw_min) * (input.default_max - input.default_min) + input.default_min) : 0 %} {% set percentage = (input.raw_value is defined and input.raw_value is not iterable and input.raw_min is defined and input.raw_min is not iterable and input.raw_max is defined and input.raw_max is not iterable and (input.raw_max - input.raw_min) != 0) ? (((input.raw_value - input.raw_min) / (input.raw_max - input.raw_min)) * 100) : 0 %} {% set isInRange = (normalizedValue is not iterable and input.default_min is not iterable and input.default_max is not iterable) ? (normalizedValue >= input.default_min and normalizedValue <= input.default_max) : false %} {% set isLow = (normalizedValue is not iterable and input.default_min is not iterable) ? (normalizedValue < input.default_min) : false %} {% set isHigh = (normalizedValue is not iterable and input.default_max is not iterable) ? (normalizedValue > input.default_max) : false %} {% else %} {# Neues Format: Verwende calibrated_value und alarm-Werte #} {% set normalizedValue = input.calibrated_value %} {% set isLow = (input.alarm_low is defined and input.alarm_low is not iterable and input.calibrated_value is not iterable) ? (input.calibrated_value < input.alarm_low) : false %} {% set isHigh = (input.alarm_high is defined and input.alarm_high is not iterable and input.calibrated_value is not iterable) ? (input.calibrated_value > input.alarm_high) : false %} {% set isInRange = not isLow and not isHigh %} {# percentage wird für neues Format nicht benötigt, aber setze es auf 0 für Kompatibilität #} {% set percentage = 0 %} {% endif %}
Channel {% if input.channel is not iterable %}{{ input.channel }}{% else %}-{% endif %}
{% if input.digital_state %} {% else %} {% endif %}
{% if input.sensor_name is defined and input.sensor_name is not iterable %}
{{ input.sensor_name }} {% if input.sensor_type is defined and input.sensor_type is not iterable %} {{ input.sensor_type }} {% endif %}
{% endif %}
{% if input.calibrated_value is defined and input.calibrated_value is not iterable %} {# Neues Format mit calibrated_value #} {{ input.calibrated_value|number_format(2) }} {% if input.unit is not iterable %}{{ input.unit }}{% else %}{% if input.mode_kind is not iterable %}{{ input.mode_kind == 'current' ? 'mA' : (input.raw_unit is not iterable ? (input.raw_unit ?? '') : '') }}{% else %}{% endif %}{% endif %} {% else %} {# Altes Format mit normalizedValue #} {% if normalizedValue is not iterable %}{{ normalizedValue|number_format(2) }}{% else %}-{% endif %} {% if input.mode_kind is not iterable %}{{ input.mode_kind == 'current' ? 'mA' : (input.raw_unit is not iterable ? (input.raw_unit ?? '') : '') }}{% else %}{% endif %} {% endif %}
{% if input.alarm_low is defined and input.alarm_high is defined and input.alarm_low is not iterable and input.alarm_high is not iterable and (input.alarm_high - input.alarm_low) != 0 %} {# Neues Format mit Alarm-Werten #} {% set alarmValue = input.calibrated_value is defined and input.calibrated_value is not iterable ? input.calibrated_value : normalizedValue %} {% set alarmPercentage = (alarmValue - input.alarm_low) / (input.alarm_high - input.alarm_low) * 100 %} {% set isAlarmLow = alarmValue < input.alarm_low %} {% set isAlarmHigh = alarmValue > input.alarm_high %} {% set isAlarmOk = not isAlarmLow and not isAlarmHigh %}
{% if isAlarmLow %} Unter Alarm {% elseif isAlarmHigh %} Über Alarm {% else %} OK {% endif %}
{{ input.alarm_low }} {{ input.alarm_high }}
{% else %} {# Altes Format mit default_min/max #}
{% if input.default_min is not iterable %}{{ input.default_min }}{% else %}-{% endif %} {% if input.mode_kind is not iterable and input.mode_kind == 'current' %}mA{% endif %} {% if input.default_max is not iterable %}{{ input.default_max }}{% else %}-{% endif %} {% if input.mode_kind is not iterable and input.mode_kind == 'current' %}mA{% endif %}
{% endif %} {% if input.counter is defined and input.counter is not iterable and input.counter > 0 %}
Counter: {{ input.counter }}
{% endif %}
{% if input.sensor_id is not iterable %}{{ input.sensor_id }}{% elseif input.id is not iterable %}{{ input.id }}{% else %}{% endif %}
{% endif %} {% endif %} {% endfor %}
{% endif %} {% endif %} {% endfor %} {% endif %} {% else %}
Keine HAT-Daten verfügbar
{% endif %}
{% if hatsStatus is defined and hatsStatus.error is not defined %}

HAT Status

{% for key, value in hatsStatus %} {% if key != 'error' %}
{{ key|replace({'_': ' '})|title }} {% set isArray = value is iterable and value is not same as('') and value is not same as([]) %} {% if isArray %}
{% for item in value %} {% if item is iterable and item is not same as('') and item is not same as([]) %} {{ item|json_encode }} {% else %} {{ item }} {% endif %} {% endfor %}
{% elseif value is same as(true) %} Ja {% elseif value is same as(false) %} Nein {% elseif value is null %} - {% elseif key|lower matches '/timestamp/' and not isArray %} {% set timestampValue = value|round %} {% if timestampValue > 1000000000 and timestampValue < 9999999999 %} {{ timestampValue|date('d.m.Y H:i:s') }} {% else %} {{ value }} {% endif %} {% else %} {# Normale Anzeige #} {% if isArray %} {{ value|json_encode }} {% else %} {{ value }} {% endif %} {% endif %}
{% endif %} {% endfor %}
{% endif %}

Legende

Normaler Bereich
Unter Minimum
Über Maximum
{% if hatsData.error is not defined and hatsData %} {% set hatDataToProcess = hatsData.hat_data is defined and hatsData.hat_data is iterable ? hatsData.hat_data : (hatsData is iterable ? hatsData : {}) %} {% if hatDataToProcess and hatDataToProcess is iterable %} {# Sammle Min/Max-Werte pro Einheit - verwende einfache Variablen für jede Einheit #} {% set tempMin = null %} {% set tempMax = null %} {% set pressureMin = null %} {% set pressureMax = null %} {% set otherRanges = {} %} {% for hatKey, hat in hatDataToProcess %} {% if hat is iterable and hat.inputs is defined and hat.inputs is iterable %} {% set hatName = hat.name is not iterable ? hat.name : hatKey %} {% set hatStack = hat.stack is not iterable ? hat.stack : null %} {% for input in hat.inputs %} {% if input is iterable %} {% set inputChannel = input.channel is not iterable ? input.channel : null %} {% set isChannelHidden = false %} {% if not isAdmin %} {% for hidden in hiddenSensors %} {% if hidden.hatName == hatName and (hidden.stack is null or hidden.stack == hatStack) and hidden.channel == inputChannel %} {% set isChannelHidden = true %} {% endif %} {% endfor %} {% endif %} {% if not isChannelHidden %} {% set unit = input.unit is defined and input.unit is not iterable ? input.unit : (input.raw_unit is defined and input.raw_unit is not iterable ? input.raw_unit : '') %} {% set isTemp = unit == '°C' or unit|lower == 'c' or (input.sensor_name is defined and input.sensor_name is not iterable and 'temp' in input.sensor_name|lower) %} {% set isPressure = unit == 'bar' or (input.sensor_name is defined and input.sensor_name is not iterable and 'druck' in input.sensor_name|lower or 'pressure' in input.sensor_name|lower) %} {# Neues Format: alarm_low/alarm_high #} {% if input.alarm_low is defined and input.alarm_low is not iterable and input.alarm_high is defined and input.alarm_high is not iterable %} {% if isTemp %} {% if tempMin is null or input.alarm_low < tempMin %} {% set tempMin = input.alarm_low %} {% endif %} {% if tempMax is null or input.alarm_high > tempMax %} {% set tempMax = input.alarm_high %} {% endif %} {% elseif isPressure %} {% if pressureMin is null or input.alarm_low < pressureMin %} {% set pressureMin = input.alarm_low %} {% endif %} {% if pressureMax is null or input.alarm_high > pressureMax %} {% set pressureMax = input.alarm_high %} {% endif %} {% endif %} {# Altes Format: default_min/default_max #} {% elseif input.default_min is defined and input.default_min is not iterable and input.default_max is defined and input.default_max is not iterable %} {% if isTemp %} {% if tempMin is null or input.default_min < tempMin %} {% set tempMin = input.default_min %} {% endif %} {% if tempMax is null or input.default_max > tempMax %} {% set tempMax = input.default_max %} {% endif %} {% elseif isPressure %} {% if pressureMin is null or input.default_min < pressureMin %} {% set pressureMin = input.default_min %} {% endif %} {% if pressureMax is null or input.default_max > pressureMax %} {% set pressureMax = input.default_max %} {% endif %} {% endif %} {% endif %} {% endif %} {% endif %} {% endfor %} {% endif %} {% endfor %} {# Zeige Min/Max-Werte an #} {% if tempMin is not null and tempMax is not null or pressureMin is not null and pressureMax is not null %}

Bereiche aus API:

{% if tempMin is not null and tempMax is not null %}
Temperatur: Min: {{ tempMin|number_format(1) }}°C, Max: {{ tempMax|number_format(1) }}°C
{% endif %} {% if pressureMin is not null and pressureMax is not null %}
Druck: Min: {{ pressureMin|number_format(1) }} bar, Max: {{ pressureMax|number_format(1) }} bar
{% endif %}
{% endif %} {% endif %} {% endif %}
{% endblock %} {% block stylesheets %}{% endblock %} {% block javascripts %} {% endblock %}