Skip to content

Commit

Permalink
Shelly gen1 EM: return positive power (evcc-io#7088)
Browse files Browse the repository at this point in the history
  • Loading branch information
thierolm authored Mar 28, 2023
1 parent ecec839 commit 62dcbfd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 4 additions & 2 deletions meter/shelly/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shelly
import (
"errors"
"fmt"
"math"
"strings"
)

Expand Down Expand Up @@ -56,7 +57,8 @@ func (sh *Switch) CurrentPower() (float64, error) {
}
}

return power, nil
// Assure positive power response (Gen 1 EM devices can provide negative values)
return math.Abs(power), nil
}

// Enabled implements the api.Charger interface
Expand Down Expand Up @@ -141,7 +143,7 @@ func (sh *Switch) TotalEnergy() (float64, error) {

// gen1Energy in kWh
func gen1Energy(devicetype string, energy float64) float64 {
// Gen 1 Shelly EM devices are providing Watt hours, Shelly EM devices are providing Watt minutes
// Gen 1 Shelly EM devices are providing Watt hours, Gen 1 Shelly PM devices are providing Watt minutes
if !strings.Contains(devicetype, "EM") {
energy = energy / 60
}
Expand Down
2 changes: 1 addition & 1 deletion templates/definition/meter/shelly-1pm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ products:
group: switchsockets
params:
- name: usage
choice: ["pv"]
choice: ["pv", "charge"]
- name: host
default: 192.0.2.2
- name: user
Expand Down
9 changes: 9 additions & 0 deletions templates/docs/meter/shelly-1pm_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ render:
user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.) # Optional
password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen) # Optional
channel: # Optional
- usage: charge
default: |
type: template
template: shelly-1pm
usage: charge
host: 192.0.2.2 # IP-Adresse oder Hostname
user: # Benutzerkonto (bspw. E-Mail Adresse, User Id, etc.) # Optional
password: # Passwort des Benutzerkontos (bei führenden Nullen bitte in einfache Hochkommata setzen) # Optional
channel: # Optional

0 comments on commit 62dcbfd

Please sign in to comment.