Skip to content

Commit

Permalink
Splitted Grid imp/exp (workaround Domoticz issue)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdklip committed Mar 30, 2021
1 parent a244187 commit 59ecf0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ This plugin:
- Connects to the myenergi backend and thus needs a working internet connection.
- Only takes Zappi devices into account for now; Eddi devices are ignored.

Domoticz:

- Seems to incorrectly display daily values for the computed total kWh values. This likely screws up the displayed 'Grid' values. See https://github.com/domoticz/domoticz/issues/4736

## Updating

Like other plugins, in the Domoticz-myenergi directory:
Expand Down
15 changes: 12 additions & 3 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# https://github.com/twonk/MyEnergi-App-Api

"""
<plugin key="myenergi" name="myenergi" author="mvdklip" version="1.0.0">
<plugin key="myenergi" name="myenergi" author="mvdklip" version="1.1.0">
<description>
<h2>myenergi Plugin</h2><br/>
<h3>Features</h3>
Expand Down Expand Up @@ -65,11 +65,13 @@ def onStart(self):
if len(Devices) < 1:
Domoticz.Device(Name="Generation", Unit=1, TypeName='kWh', Switchtype=4, Options={'EnergyMeterMode':'1'}).Create()
if len(Devices) < 2:
Domoticz.Device(Name="Grid", Unit=2, TypeName='kWh', Options={'EnergyMeterMode':'1'}).Create()
Domoticz.Device(Name="Grid Import", Unit=2, TypeName='kWh', Options={'EnergyMeterMode':'1'}).Create()
if len(Devices) < 3:
Domoticz.Device(Name="Car Charging", Unit=3, TypeName='kWh', Options={'EnergyMeterMode':'1'}).Create()
if len(Devices) < 4:
Domoticz.Device(Name="Home Consumption", Unit=4, TypeName='kWh', Options={'EnergyMeterMode':'1'}).Create()
if len(Devices) < 5:
Domoticz.Device(Name="Grid Export", Unit=5, TypeName='kWh', Options={'EnergyMeterMode':'1'}).Create()

DumpConfigToLog()

Expand Down Expand Up @@ -138,10 +140,17 @@ def onHeartbeat(self):
else:
# TODO - Find a way to get total counters from the API instead of letting Domoticz compute
Devices[1].Update(nValue=0, sValue=str(zappi_gen_watt)+";0")
Devices[2].Update(nValue=0, sValue=str(zappi_grd_watt)+";0")
Devices[3].Update(nValue=0, sValue=str(zappi_div_watt)+";0")
Devices[4].Update(nValue=0, sValue=str(zappi_hom_watt)+";0")

# Work around negative kWh Domoticz issue #4736 using separate import and export grid meters
if (zappi_grd_watt < 0):
Devices[5].Update(nValue=0, sValue=str(abs(zappi_grd_watt))+";0") # (-) Grid export
Devices[2].Update(nValue=0, sValue="0;0")
else:
Devices[2].Update(nValue=0, sValue=str(zappi_grd_watt)+";0") # (+) Grid import
Devices[5].Update(nValue=0, sValue="0;0")

break

self.lastPolled += 1
Expand Down

0 comments on commit 59ecf0a

Please sign in to comment.