diff --git a/core/keys/site.go b/core/keys/site.go index 601e8d345..389af6fa7 100644 --- a/core/keys/site.go +++ b/core/keys/site.go @@ -24,7 +24,7 @@ const ( Statistics = "statistics" TariffCo2 = "tariffCo2" TariffCo2Home = "tariffCo2Home" - TariffCo2Loadpoints = "tariffCo2Loadpoin" + TariffCo2Loadpoints = "tariffCo2Loadpoints" TariffFeedIn = "tariffFeedIn" TariffGrid = "tariffGrid" TariffPriceHome = "tariffPriceHome" diff --git a/core/site_vehicles.go b/core/site_vehicles.go index c9a2de49a..9fd54a64e 100644 --- a/core/site_vehicles.go +++ b/core/site_vehicles.go @@ -63,6 +63,7 @@ func (site *Site) updateVehicles(op config.Operation, dev config.Device[api.Vehi site.coordinator.Delete(vehicle) } + // TODO remove vehicle from mqtt site.publishVehicles() } diff --git a/server/mqtt.go b/server/mqtt.go index d5e38da62..544c489d6 100644 --- a/server/mqtt.go +++ b/server/mqtt.go @@ -19,7 +19,7 @@ import ( var deprecatedTopics = []string{ "activePhases", "range", "socCharge", - "vehicleSoC", "batterySoC", "bufferSoC", "minSoC", "prioritySoC", "targetSoC", "vehicleTargetSoC", + "vehicleSoC", "batterySoC", "bufferSoC", "minSoC", "prioritySoC", "targetSoC", "vehicleTargetSoC", "vehicles", "savingsAmount", "savingsEffectivePrice", "savingsGridCharged", "savingsSelfConsumptionCharged", "savingsSelfConsumptionPercent", "savingsTotalCharged", "stats/30d", "stats/365d", "stats/total", } @@ -385,10 +385,14 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) { // publish for p := range in { - topic := fmt.Sprintf("%s/site", m.root) - if p.Loadpoint != nil { + switch { + case p.Loadpoint != nil: id := *p.Loadpoint + 1 - topic = fmt.Sprintf("%s/loadpoints/%d", m.root, id) + topic = fmt.Sprintf("%s/loadpoints/%d/%s", m.root, id, p.Key) + case p.Key == "vehicles": + topic = fmt.Sprintf("%s/vehicles", m.root) + default: + topic = fmt.Sprintf("%s/site/%s", m.root, p.Key) } // alive indicator @@ -398,7 +402,6 @@ func (m *MQTT) Run(site site.API, in <-chan util.Param) { } // value - topic += "/" + p.Key m.publish(topic, true, p.Val) } }