Skip to content

Commit

Permalink
lost signal support
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnaud committed Apr 28, 2024
1 parent 3fd90a6 commit f0d39d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ D => 1101
```

- least significant bit, indicate there is en sensors configured, somethings like that
- second bit, I don't know, but there is a low temperature detection, I should be this
- second bit, Lost of signal
- third bit, Low battery status
- fourth bit, Leak detection

Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func PublishHassConfig(config *utils.Config, cli *mqtt_client.Client, ctl *model
cli.PublishState(
sensor.GetMQTTLeakHassConfigTopic(config.HassDiscoveryTopic),
sensor.GetMQTTLeakHassConfig(config.MQTT.BaseTopic))
cli.PublishState(
sensor.GetMQTTSignalHassConfigTopic(config.HassDiscoveryTopic),
sensor.GetMQTTSignalHassConfig(config.MQTT.BaseTopic))
}
ctl.LastHassConfigPublished = time.Now()
}
42 changes: 38 additions & 4 deletions models/Leako.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ func (a *LeakoSensor) IsBatLow() bool {
return a.Value&0b0100 == 0b0100
}

func (a *LeakoSensor) IsLostSignal() bool {
return a.Value&0b0100 == 0b0010
}

func (a *LeakoSensor) IsConfigured() bool {
return a.Value&0b0001 == 0b0001
}
Expand All @@ -295,6 +299,12 @@ func (a *LeakoSensor) String() string {
}
value.Write([]byte("NotConf"))
}
if a.IsLostSignal() {
if value.Len() > 0 {
value.Write([]byte("+"))
}
value.Write([]byte("LostSignal"))
}
if value.Len() == 0 {
value.Write([]byte("ok"))
}
Expand Down Expand Up @@ -357,12 +367,36 @@ func (a *LeakoSensor) GetMQTTBatHassConfig(baseTopic string) *HassDiscoveryPaylo
}
}

func (a *LeakoSensor) GetMQTTSignalHassConfigTopic(hassPrefix string) string {
return fmt.Sprintf("%s/binary_sensor/%s/sensor-%d-lost/config", hassPrefix, a.Ctl.GetMQTTHassNodeId(), a.ID)
}

func (a *LeakoSensor) GetMQTTSignalHassConfig(baseTopic string) *HassDiscoveryPayload {
return &HassDiscoveryPayload{
Name: fmt.Sprintf("%d", a.ID),
AvailabilityTopic: a.GetMQTTAvailabilityTopic(baseTopic),
DeviceClass: "connectivity",
StateTopic: a.GetMQTTStateTopic(baseTopic),
UniqueId: fmt.Sprintf("%s_%d-signal", a.Ctl.GetMQTTHassNodeId(), a.ID),
ValueTemplate: "{{ value_json.lost_signal | abs }}",
PayloadOff: "1",
PayloadOn: "0",
Device: HassDeviceDiscoveryPayload{
Name: a.Ctl.GetMQTTHassNodeId(),
Manufacturer: MANUFACTURER,
Identifiers: []string{a.Ctl.GetMQTTHassNodeId()},
},
}
}

func (a *LeakoSensor) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
LowBat bool `json:"low_bat"`
Leak bool `json:"leak"`
LowBat bool `json:"low_bat"`
LostSignal bool `json:"lost_signal"`
Leak bool `json:"leak"`
}{
LowBat: a.IsBatLow(),
Leak: a.IsWaterDetected(),
LowBat: a.IsBatLow(),
LostSignal: a.IsLostSignal(),
Leak: a.IsWaterDetected(),
})
}

0 comments on commit f0d39d8

Please sign in to comment.