Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add power boost sensors #50

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions app/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func LaunchBridge(configPath string) {
}
}

if c.Settings.PowerBoostEnabled {
for k, v := range getPowerBoostEntities(w, c) {
entityConfig[k] = v
}
}

topicPrefix := "wallbox_" + serialNumber
availabilityTopic := topicPrefix + "/availability"

Expand Down Expand Up @@ -89,14 +95,20 @@ func LaunchBridge(configPath string) {

published := make(map[string]interface{})
rateLimiter := map[string]*ratelimit.DeltaRateLimit{
"charging_power": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l1": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l2": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l3": ratelimit.NewDeltaRateLimit(10, 100),
"charging_current_l1": ratelimit.NewDeltaRateLimit(10, 0.2),
"charging_current_l2": ratelimit.NewDeltaRateLimit(10, 0.2),
"charging_current_l3": ratelimit.NewDeltaRateLimit(10, 0.2),
"added_energy": ratelimit.NewDeltaRateLimit(10, 50),
"charging_power": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l1": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l2": ratelimit.NewDeltaRateLimit(10, 100),
"charging_power_l3": ratelimit.NewDeltaRateLimit(10, 100),
"charging_current_l1": ratelimit.NewDeltaRateLimit(10, 0.2),
"charging_current_l2": ratelimit.NewDeltaRateLimit(10, 0.2),
"charging_current_l3": ratelimit.NewDeltaRateLimit(10, 0.2),
"power_boost_power_l1": ratelimit.NewDeltaRateLimit(10, 100),
"power_boost_power_l2": ratelimit.NewDeltaRateLimit(10, 100),
"power_boost_power_l3": ratelimit.NewDeltaRateLimit(10, 100),
"power_boost_current_l1": ratelimit.NewDeltaRateLimit(10, 0.2),
"power_boost_current_l2": ratelimit.NewDeltaRateLimit(10, 0.2),
"power_boost_current_l3": ratelimit.NewDeltaRateLimit(10, 0.2),
"added_energy": ratelimit.NewDeltaRateLimit(10, 50),
}

for {
Expand Down
1 change: 1 addition & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type WallboxConfig struct {
PollingIntervalSeconds int `ini:"polling_interval_seconds"`
DeviceName string `ini:"device_name"`
DebugSensors bool `ini:"debug_sensors"`
PowerBoostEnabled bool `ini:"power_boost_enabled"`
} `ini:"settings"`
}

Expand Down
94 changes: 94 additions & 0 deletions app/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,100 @@ func getEntities(w *wallbox.Wallbox) map[string]Entity {
}
}

func getPowerBoostEntities(w *wallbox.Wallbox, c *WallboxConfig) map[string]Entity {
return map[string]Entity{
"power_boost_power_l1": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine1Power)
},
Config: map[string]string{
"name": "Power Boost L1",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: I'd rename Power Boost to something more generic like External Energy Meter or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the name is not ideal, but it seems like Wallbox also supports MID type energy meters, so I think anything else would be more confusing if somebody adds support for those. I don't like calling it power boost either, so I'm open to ideas though. :)

"device_class": "power",
"unit_of_measurement": "W",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_power_l2": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine2Power)
},
Config: map[string]string{
"name": "Power Boost L2",
"device_class": "power",
"unit_of_measurement": "W",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_power_l3": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine3Power)
},
Config: map[string]string{
"name": "Power Boost L3",
"device_class": "power",
"unit_of_measurement": "W",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_current_l1": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine1Current)
},
Config: map[string]string{
"name": "Power Boost current L1",
"device_class": "current",
"unit_of_measurement": "A",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_current_l2": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine2Current)
},
Config: map[string]string{
"name": "Power Boost current L2",
"device_class": "current",
"unit_of_measurement": "A",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_current_l3": {
Component: "sensor",
Getter: func() string {
return fmt.Sprint(w.Data.RedisM2W.PowerBoostLine3Current)
},
Config: map[string]string{
"name": "Power Boost current L3",
"device_class": "current",
"unit_of_measurement": "A",
"state_class": "measurement",
"suggested_display_precision": "1",
},
},
"power_boost_cumulative_added_energy": {
Component: "sensor",
Getter: func() string { return fmt.Sprint(w.Data.RedisM2W.PowerBoostCumulativeEnergy) },
Config: map[string]string{
"name": "Power Boost Cumulative added energy",
"device_class": "energy",
"unit_of_measurement": "Wh",
"state_class": "total_increasing",
"suggested_display_precision": "1",
},
},
}
}

func getDebugEntities(w *wallbox.Wallbox) map[string]Entity {
return map[string]Entity{
"control_pilot": {
Expand Down
2 changes: 2 additions & 0 deletions app/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func RunTuiSetup() {
config.Settings.PollingIntervalSeconds = 1
config.Settings.DeviceName = "Wallbox"
config.Settings.DebugSensors = false
config.Settings.PowerBoostEnabled = false

askConfirmOrNew(&config.MQTT.Host, "MQTT Host")
askConfirmOrNewInt(&config.MQTT.Port, "MQTT Port")
Expand All @@ -55,6 +56,7 @@ func RunTuiSetup() {
askConfirmOrNewInt(&config.Settings.PollingIntervalSeconds, "Polling interval")
askConfirmOrNew(&config.Settings.DeviceName, "Device name")
askConfirmOrNewBool(&config.Settings.DebugSensors, "Debug sensors")
askConfirmOrNewBool(&config.Settings.PowerBoostEnabled, "Enable Power Boost sensors")

config.SaveTo("bridge.ini")
}
21 changes: 14 additions & 7 deletions app/wallbox/wallbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ type DataCache struct {
}

RedisM2W struct {
ChargerStatus int `redis:"tms.charger_status"`
Line1Power float64 `redis:"tms.line1.power_watt.value"`
Line2Power float64 `redis:"tms.line2.power_watt.value"`
Line3Power float64 `redis:"tms.line3.power_watt.value"`
Line1Current float64 `redis:"tms.line1.current_amp.value"`
Line2Current float64 `redis:"tms.line2.current_amp.value"`
Line3Current float64 `redis:"tms.line3.current_amp.value"`
ChargerStatus int `redis:"tms.charger_status"`
Line1Power float64 `redis:"tms.line1.power_watt.value"`
Line2Power float64 `redis:"tms.line2.power_watt.value"`
Line3Power float64 `redis:"tms.line3.power_watt.value"`
Line1Current float64 `redis:"tms.line1.current_amp.value"`
Line2Current float64 `redis:"tms.line2.current_amp.value"`
Line3Current float64 `redis:"tms.line3.current_amp.value"`
PowerBoostLine1Power float64 `redis:"PBO.line1.power.value"`
PowerBoostLine2Power float64 `redis:"PBO.line2.power.value"`
PowerBoostLine3Power float64 `redis:"PBO.line3.power.value"`
PowerBoostLine1Current float64 `redis:"PBO.line1.current.value"`
PowerBoostLine2Current float64 `redis:"PBO.line2.current.value"`
PowerBoostLine3Current float64 `redis:"PBO.line3.current.value"`
PowerBoostCumulativeEnergy float64 `redis:"PBO.energy_wh.value"`
}
}

Expand Down
Loading