Skip to content

Commit

Permalink
add new entities for SEC module using the right columns from dataCoun…
Browse files Browse the repository at this point in the history
…tList (#97)

Include new sensor names also includes Old names which later will be deprecated
  • Loading branch information
santiagozky authored Oct 9, 2024
1 parent ee3b48a commit d471f93
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Byte-compiled / optimized / DLL files
__pycache__/
SyncToy*
SyncToy*
.idea/
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,19 @@ If you have a Saj Sec Module Add below sensor an resources:
- selfConsumedEnergy2
- plantTreeNum
- reduceCo2
- totalGridPower
- totalLoadPower
- totalPvgenPower
- totalPvEnergy
- totalLoadEnergy # Energy -> Grid consumption
- totalBuyEnergy
- totalSellEnergy # Energy -> Return to grid
#these entities are deprecated since they return incorrect values
- totalGridPower # Power being exported to the grid
- totalLoadPower # Solar power being currently self-consumed
- totalPvgenPower # Power imported from the grid
#these new entities replace them
- gridLoadPower # Power imported from the grid
- solarLoadPower # Solar power being currently self-consumed
- homeLoadPower # Total power being consumed by the plant (the home)
- exportPower # Power being exported to the grid
```
<br><br>
If you are a user of Solarprofit / Greenheiss
Expand Down
54 changes: 51 additions & 3 deletions custom_components/saj_esolar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ def add_years(d, years):
"selfConsumedEnergy2",
"plantTreeNum",
"reduceCo2",
#deprecated entities (values dont actually match what they meant to )
"totalGridPower",
"totalLoadPower",
"totalPvgenPower",
#new saj entities
"gridLoadPower",
"solarLoadPower",
"homeLoadPower",
"exportPower",
"totalPvEnergy",
"totalLoadEnergy",
"totalBuyEnergy",
Expand Down Expand Up @@ -378,6 +384,31 @@ def add_years(d, years):
icon="mdi:solar-panel",
native_unit_of_measurement=UnitOfPower.WATT,
),
SensorEntityDescription(
key="gridLoadPower",
name="gridLoadPower",
icon="mdi:transmission-tower-import",
native_unit_of_measurement=UnitOfPower.WATT,
),
SensorEntityDescription(
key="solarLoadPower",
name="solarLoadPower",
icon="mdi:solar-power",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.ENERGY,
),
SensorEntityDescription(
key="homeLoadPower",
name="homeLoadPower",
icon="mdi:home-lightning-bolt-outline",
native_unit_of_measurement=UnitOfPower.WATT,
),
SensorEntityDescription(
key="exportPower",
name="exportPower",
icon="mdi:transmission-tower-export",
native_unit_of_measurement=UnitOfPower.WATT,
),
SensorEntityDescription(
key="totalPvEnergy",
name="totalPvEnergy",
Expand Down Expand Up @@ -1199,20 +1230,37 @@ async def async_update(self):
self._state = (energy["getPlantMeterChartData"]['viewBean']["plantTreeNum"])


# dataCountList
# dataCountList, deprecated since use the wrong columns
if self._type == 'totalGridPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][4][-1] is not None:
if energy["getPlantMeterChartData"]['dataCountList'][3][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][3][-1])
if self._type == 'totalLoadPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][4][-1] is not None:
if energy["getPlantMeterChartData"]['dataCountList'][2][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][2][-1])
if self._type == 'totalPvgenPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][4][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][4][-1])

#dataCountList, new entities
if self._type == 'homeLoadPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][1][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][1][-1])
if self._type == 'solarLoadPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][2][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][2][-1])
if self._type == 'exportPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][3][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][3][-1])
if self._type == 'gridLoadPower':
if 'dataCountList' in energy:
if energy["getPlantMeterChartData"]['dataCountList'][4][-1] is not None:
self._state = float(energy["getPlantMeterChartData"]['dataCountList'][4][-1])

# getPlantMeterDetailInfo
if self._type == 'totalPvEnergy':
Expand Down

0 comments on commit d471f93

Please sign in to comment.