Skip to content

Commit

Permalink
feat: add water warning (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Aug 11, 2024
1 parent 9fb5521 commit 4579fa0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ modules:
sensorIds:
geyserPct: sensor.geyser_hot_water
tankPct: sensor.reservoir_percentage
waterConnected: binary_sensor.water_connected
geyser:
warning: 50
low: 30
Expand All @@ -33,6 +34,10 @@ The Home Assistant geyser percentage sensor ID.
The Home Assistant water tank percentage sensor ID.
### Water Connection Sensor ID (sensorIds.waterConnected)
The Home Assistant binary sensor ID indicating if the mains water has pressure.
### Geyser Warning Percentage (geyser.warning)
The Geyser percentage for the hot water bar to display in warning style.
Expand Down
8 changes: 8 additions & 0 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
<tspan class="units" dx="-10" dy="6">%</tspan>
</text>

<g id="icons">
<path id="water-disconnect" d="M 35.5246 29.8246 L 19.8005 3.7476 c -0.3974 -0.659 -1.1109 -1.062 -1.8805 -1.062 c -0.7696 0 -1.4832 0.4029 -1.8805 1.062 L 0.3154 29.8246 c -0.4089 0.6783 -0.421 1.5242 -0.0316 2.2138 c 0.3895 0.6896 1.1201 1.1161 1.9121 1.1161 h 31.4481 c 0.792 0 1.5226 -0.4265 1.9121 -1.1161 C 35.9456 31.3488 35.9335 30.5029 35.5246 29.8246 z M 22.5178 19.5906 l -5.911 8.0822 c -0.1345 0.1839 -0.379 0.2493 -0.5873 0.1571 c -0.2083 -0.0922 -0.3244 -0.317 -0.2787 -0.5403 l 1.2289 -6.0082 H 13.9384 c -0.2927 0 -0.5605 -0.1644 -0.6929 -0.4254 c -0.1324 -0.261 -0.1071 -0.5743 0.0657 -0.8105 l 5.911 -8.0823 c 0.1345 -0.1839 0.379 -0.2493 0.5873 -0.1571 c 0.2084 0.0922 0.3244 0.317 0.2787 0.5403 l -1.2289 6.0082 h 3.0313 c 0.2927 0 0.5605 0.1644 0.6929 0.4254 C 22.716 19.041 22.6906 19.3544 22.5178 19.5906 z"
transform="translate(112,150) scale(0.8)"
fill="rgb(242, 73, 92)"
class="off"
/>
</g>

<g transform="translate(113 180)">
<path fill="#aaa"
d="M17 6H16V5C16 3.9 15.1 3 14 3H10C8.9 3 8 3.9 8 5V6H7C3.69 6 1 8.69 1 12S3.69 18 7 18V21H9V18H15V21H17V18C20.31 18 23 15.31 23 12S20.31 6 17 6M10 5H14V6H10V5Z"></path>
Expand Down
4 changes: 4 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
stroke: rgb(242, 73, 92);
}

#icons .off {
display: none;
}

.tank {
r: var(--radius);
fill: none;
Expand Down
19 changes: 15 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main
import (
_ "embed"
"fmt"
"slices"
"strconv"
"strings"
"time"
Expand All @@ -26,8 +27,9 @@ type Config struct {
URL string `yaml:"url"`
Token string `yaml:"token"`
SensorIDs struct {
GeyserPct string `yaml:"geyserPct"`
TankPct string `yaml:"tankPct"`
GeyserPct string `yaml:"geyserPct"`
TankPct string `yaml:"tankPct"`
WaterConnected string `yaml:"waterConnected"`
} `yaml:"sensorIds"`
Geyser struct {
Warning int `yaml:"warning"`
Expand Down Expand Up @@ -117,7 +119,7 @@ func (m *Module) setup() error {
}

func (m *Module) syncStates() error {
states, err := m.ha.FilterStates("sensor")
states, err := m.ha.FilterStates("sensor", "binary_sensor")
if err != nil {
return fmt.Errorf("getting states: %w", err)
}
Expand All @@ -144,7 +146,8 @@ func (m *Module) listenStates() error {
if event.EventType != "state_changed" {
continue
}
if strings.TrimSuffix(strings.SplitAfter(event.Data.EntityID, ".")[0], ".") != "sensor" {
prefix := strings.TrimSuffix(strings.SplitAfter(event.Data.EntityID, ".")[0], ".")
if !slices.Contains([]string{"sensor", "binary_sensor"}, prefix) {
continue
}

Expand Down Expand Up @@ -206,5 +209,13 @@ func (m *Module) updateState(id, state string) {
elem.Class().Add(class)
}
}
case m.cfg.SensorIDs.WaterConnected:
connected := state == "on"
if elem := m.mod.Element().QuerySelector("#water-disconnect"); elem != nil {
elem.Class().Remove("off")
if connected {
elem.Class().Add("off")
}
}
}
}

0 comments on commit 4579fa0

Please sign in to comment.