Skip to content

Commit

Permalink
- Splitted Javascript into multiple files
Browse files Browse the repository at this point in the history
- added ghostmap with history of set sensors
- fixed some minor tooltip bugs
- fixed some performance issues
  • Loading branch information
mentalilll committed Feb 27, 2024
1 parent 5d81efc commit d0528dd
Show file tree
Hide file tree
Showing 7 changed files with 433 additions and 440 deletions.
116 changes: 2 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ steps_temperature: 0.5
is_bar_view: true
enable_tooltip: true
enable_axes: true
enable_ghostmap: true
sensors:
- temperature: sensor.temperature_2
humidity: sensor.humidity_2
Expand Down Expand Up @@ -102,124 +103,11 @@ vpd_phases:
| enable_tooltip | boolean | optional | `true` | Tooltip enabled by default. |
| is_bar_view | boolean | optional | `false` | Second view of this chart for fast information of sensors |
| enable_axes | boolean | optional | `true` | Enable Axes on the Chart |
| enable_ghostmap | boolean | optional | `true` | Enable Ghostmap on the Chart |

**Default `vpd_phases` Configuration:**
- `under-transpiration`: VPD < 0.4
- `early-veg`: 0.4 ≤ VPD < 0.8
- `late-veg`: 0.8 ≤ VPD < 1.2
- `mid-late-flower`: 1.2 ≤ VPD < 1.6
- `danger-zone`: VPD ≥ 1.6

Diese Tabelle bietet eine detaillierte Übersicht über die verfügbaren Konfigurationsoptionen und deren Standardwerte für das `custom:ha-vpd-chart` Element.




###################################################################################


# HaVpdChart für Home Assistant

`HaVpdChart` ist eine benutzerdefinierte Kartenkomponente für Home Assistant, die es ermöglicht, visuelle Darstellungen von VPD (Vapour Pressure Deficit) basierend auf Temperatur- und Feuchtigkeitssensoren zu erstellen. Ideal für die Überwachung von Umgebungsbedingungen in Zelten oder Räumen.

## Voraussetzungen

- Home Assistant Installation
- Grundkenntnisse in YAML und Home Assistant Konfiguration

## Installation

### Von GitHub

1. **Repository klonen oder JS-Datei herunterladen**

Zuerst müssen Sie das JavaScript-File `ha-vpd-chart.js` von GitHub herunterladen oder das gesamte Repository klonen.

2. **Datei in Home Assistant einbinden**

Kopieren Sie `ha-vpd-chart.js` in Ihr `www` Verzeichnis von Home Assistant, typischerweise unter `<config>/www/`.

3. **Resource in Home Assistant hinzufügen**

Fügen Sie die Resource in Ihre `configuration.yaml` oder über die Home Assistant UI unter `Konfiguration` -> `Lovelace-Dashboards` -> `Ressourcen` hinzu:

```yaml
lovelace:
resources:
- url: /local/ha-vpd-chart.js
type: module
```

**Hinweis:** Nachdem Sie die Resource hinzugefügt haben, müssen Sie möglicherweise Home Assistant neustarten.

### Lokale Installation

Folgen Sie den oben genannten Schritten, um die Datei lokal zu speichern und als Resource einzubinden.

## Anwendung

Um die `HaVpdChart` in Ihrem Lovelace-Dashboard zu nutzen, fügen Sie die folgende Konfiguration zu Ihrem Dashboard hinzu. Passen Sie die Sensoren und andere Optionen entsprechend Ihrer Konfiguration an:

```yaml
type: custom:ha-vpd-chart
air_text: Temp.
rh_text: r.F.
min_temperature: 5
max_temperature: 35
min_humidity: 10
max_humidity: 100
steps_humidity: 1
steps_temperature: 0.5
is_bar_view: true
enable_tooltip: true
enable_axes: true
sensors:
- temperature: sensor.temperature_2
humidity: sensor.humidity_2
leaf_temperature: sensor.infrared_sensor
name: Tent 1
- temperature: sensor.temperature_tent_2
humidity: sensor.humidity_tent_2
vpd: sensor.vpd
leaf_temperature_offset: 3 # optional and is ignored if leaf_temperature isset
name: Tent 2
vpd_phases:
- upper: 0.4
className: under-transpiration
- lower: 0.4
upper: 0.8
className: early-veg
- lower: 0.8
upper: 1.2
className: late-veg
- lower: 1.2
upper: 1.6
className: mid-late-flower
- lower: 1.6
className: danger-zone
```
## Konfigurationsparameter

| Name | Typ | Erforderlich | Standard | Beschreibung |
| ------------------ | ------------ | ------------ | ---------------------- | ---------------------------------------------------------------------------------------------- |
| type | string | **erforderlich** | | Muss `custom:ha-vpd-chart` sein. |
| air_text | string | optional | `Air` | Der Text für Temperaturmessungen. Standard ist "Air". |
| rh_text | string | optional | `RH` | Der Text für Feuchtigkeitsmessungen. Standard ist "RH". |
| min_temperature | number | optional | `5` | Minimale Temperatur im Diagramm. Standard ist 5. |
| min_humidity | number | optional | `10` | Minimale Feuchtigkeit im Diagramm. Standard ist 10. |
| max_temperature | number | optional | `35` | Maximale Temperatur im Diagramm. Standard ist 35. |
| max_humidity | number | optional | `90` | Maximale Feuchtigkeit im Diagramm. Standard ist 90. |
| steps_temperature | number | optional | `0.5` | Temperaturauflösung im Diagramm. Standard ist 0.5. |
| steps_humidity | number | optional | `1` | Feuchtigkeitsauflösung im Diagramm. Standard ist 1. |
| sensors | list | **erforderlich** | | Eine Liste von Sensoren mit ihren Temperatur- und Feuchtigkeits-Entity-IDs und einem optionalen Namen zur Anzeige. |
| vpd_phases | list | optional | Siehe Beschreibung | Eine Liste von VPD-Phasen und ihren Klassen zur visuellen Darstellung. Siehe unten für Standards. |
| enable_tooltip | boolean | optional | `true` | Tooltip ist standardmäßig aktiviert. |
| is_bar_view | boolean | optional | `false` | Zweite Ansicht dieses Diagramms für schnelle Informationen zu Sensoren |
| enable_axes | boolean | optional | `true` | Aktivieren Sie die Achsen im Diagramm |
**Standardkonfiguration der `vpd_phases`:**
- `under-transpiration`: VPD < 0,4
- `early-veg`: 0,4 ≤ VPD < 0,8
- `late-veg`: 0,8 ≤ VPD < 1,2
- `mid-late-flower`: 1,2 ≤ VPD < 1,6
- `danger-zone`: VPD ≥ 1,6

92 changes: 92 additions & 0 deletions dist/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
export const bar = {
buildBarChart() {
if (!this.content) {
this.innerHTML = `
<ha-card header="VPD Informations">
<style>
@import '/hacsfiles/ha-vpd-chart/bar.css'
</style>
<div class="vpd-card-container card-content"></div>
<div class="highlight mousePointer" style="opacity:0">
<div class="custom-tooltip"></div>
</div> <!-- Tooltip -->
<!-- add Legend for VPD Phases -->
<div class="legend">
<span class="vpd-state-legend">
<span class="under-transpiration"></span>
<span class="vpd-title">Under Transpiration</span>
</span>
<span class="vpd-state-legend">
<span class="early-veg"></span>
<span class="vpd-title">Early Veg</span>
</span>
<span class="vpd-state-legend">
<span class="late-veg"></span>
<span class="vpd-title">Late Veg</span>
</span>
<span class="vpd-state-legend">
<span class="mid-late-flower"></span>
<span class="vpd-title">Mid Late Flower</span>
</span>
<span class="vpd-state-legend">
<span class="danger-zone"></span>
<span class="vpd-title">Danger Zone</span>
</span>
</div>
</ha-card>
`;
this.content = this.querySelector("div.vpd-card-container");
}

let container = document.createElement('div');

this.config.sensors.forEach((sensor) => {
let humidity = this._hass.states[sensor.humidity].state;
let temperature = this._hass.states[sensor.temperature].state;
let leafTemperature = temperature - sensor.leaf_temperature_offset || 2;
if (sensor.leaf_temperature !== undefined) {
leafTemperature = this._hass.states[sensor.leaf_temperature].state;
}
let vpd;
if (sensor.vpd !== undefined) {
vpd = this._hass.states[sensor.vpd].state;
} else {
vpd = this.calculateVPD(parseFloat(leafTemperature), parseFloat(temperature), parseFloat(humidity)).toFixed(2);
}
let card = document.createElement('ha-card');
card.innerHTML += `
<div class="bar">
<span class="vpd-title">${sensor.name}</span>
<span class="vpd-value">${vpd} kPa</span>
<span class="vpd-rh">${this.rh_text}: ${humidity}%</span>
<span class="vpd-temp">${this.air_text}: ${temperature}°C</span>
<span class="vpd-state ${this.getPhaseClass(vpd)} tooltip"></span>
</div>
`;
container.appendChild(card);
if (this.enable_tooltip) {
this.content.addEventListener('mouseover', (event) => {
if (event.target.classList.contains('tooltip')) {
this.buildMouseTooltip(event.target);
}
});
this.addEventListener('mouseleave', () => {
let tooltip = this.querySelector('.mousePointer');
let fadeOut = setInterval(function () {
if (!tooltip.style.opacity) {
tooltip.style.opacity = 1;
}
if (tooltip.style.opacity > 0) {
tooltip.style.opacity -= 0.1;
} else {
clearInterval(fadeOut);
}
}, 100);
});
} else {
this.querySelector('.mousePointer').style.display = 'none';
}
});
this.content.replaceChildren(container);
}
}
13 changes: 8 additions & 5 deletions dist/chart.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,26 @@ th, td {
text-align: center;
min-width: 2px;
}

.history-circle {
display:none;
}
.highlight {
position: absolute;
z-index: 2;
background-color: white !important; /* oder eine andere Farbe Ihrer Wahl */
color: #333333 !important;
cursor:pointer;
width:10px;
height:10px;
border-radius: 50%;
transform: translate(-50%);
pointer-events: all;
}
.custom-tooltip {
pointer-events: none;
}
.highlight:hover {
z-index:9999;
}

.vertical-line {
top:0;
bottom:0;
Expand Down Expand Up @@ -171,12 +175,11 @@ th, td {
.cell {
display: table-cell;
}
#sensors {
#sensors, #ghostmap {
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
pointer-events: none;

}
Loading

0 comments on commit d0528dd

Please sign in to comment.