-
Notifications
You must be signed in to change notification settings - Fork 107
Tasmota inverter and battery #2519
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
04bd314
move tasmota to devices; add inverter nd battery
ndrsnhs fb2a6df
add component currents
ndrsnhs 5459e5c
update config
ndrsnhs 2a15de8
add phase selection to all tasmota components
ndrsnhs bb38c9d
remove unnecessary log messages
ndrsnhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/usr/bin/env python3 | ||
| from typing import Any, TypedDict | ||
| import logging | ||
|
|
||
| from modules.devices.tasmota.tasmota.config import TasmotaBatSetup | ||
| from modules.common.abstract_device import AbstractBat | ||
| from modules.common.component_type import ComponentDescriptor | ||
| from modules.common.fault_state import ComponentInfo, FaultState | ||
| from modules.common.store import get_bat_value_store | ||
| from modules.common.simcount import SimCounter | ||
| from modules.common import req | ||
| from modules.common.component_state import BatState | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KwargsDict(TypedDict): | ||
| device_id: int | ||
| ip_address: str | ||
| phase: int | ||
|
|
||
|
|
||
| class TasmotaBat(AbstractBat): | ||
| def __init__(self, component_config: TasmotaBatSetup, **kwargs: Any) -> None: | ||
| self.component_config = component_config | ||
| self.kwargs: KwargsDict = kwargs | ||
|
|
||
| def initialize(self) -> None: | ||
| self.__device_id: int = self.kwargs['device_id'] | ||
| self.__ip_address: str = self.kwargs['ip_address'] | ||
| self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="speicher") | ||
| self.__phase: int = self.kwargs['phase'] | ||
| self.store = get_bat_value_store(self.component_config.id) | ||
| self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) | ||
|
|
||
| def update(self): | ||
| url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" | ||
| response = req.get_http_session().get(url, timeout=5).json() | ||
|
|
||
| if 'ENERGY' in response['StatusSNS']: | ||
| currents = [0.0, 0.0, 0.0] | ||
|
|
||
| power = float(response['StatusSNS']['ENERGY']['Power']) | ||
| currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 | ||
| imported = float(response['StatusSNS']['ENERGY']['Total']*1000) | ||
| _, exported = self.sim_counter.sim_count(power) | ||
|
|
||
| bat_state = BatState( | ||
| power=power, | ||
| currents=currents, | ||
| imported=imported, | ||
| exported=exported | ||
| ) | ||
| else: | ||
| power = float(response['StatusSNS']['Itron']['Power']) | ||
| imported = float(response['StatusSNS']['Itron']['E_in']*1000) | ||
| exported = float(response['StatusSNS']['Itron']['E_out']*1000) | ||
|
|
||
| bat_state = BatState( | ||
| power=power, | ||
| imported=imported, | ||
| exported=exported | ||
| ) | ||
|
|
||
| self.store.set(bat_state) | ||
|
|
||
|
|
||
| component_descriptor = ComponentDescriptor(configuration_factory=TasmotaBatSetup) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python3 | ||
| from typing import Any, TypedDict | ||
| import logging | ||
|
|
||
| from modules.devices.tasmota.tasmota.config import TasmotaInverterSetup | ||
| from modules.common.abstract_device import AbstractInverter | ||
| from modules.common.component_type import ComponentDescriptor | ||
| from modules.common.fault_state import ComponentInfo, FaultState | ||
| from modules.common.store import get_inverter_value_store | ||
| from modules.common.simcount import SimCounter | ||
| from modules.common import req | ||
| from modules.common.component_state import InverterState | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KwargsDict(TypedDict): | ||
| device_id: int | ||
| ip_address: str | ||
| phase: int | ||
|
|
||
|
|
||
| class TasmotaInverter(AbstractInverter): | ||
| def __init__(self, component_config: TasmotaInverterSetup, **kwargs: Any) -> None: | ||
| self.component_config = component_config | ||
| self.kwargs: KwargsDict = kwargs | ||
|
|
||
| def initialize(self) -> None: | ||
| self.__device_id: int = self.kwargs['device_id'] | ||
| self.__ip_address: str = self.kwargs['ip_address'] | ||
| self.sim_counter = SimCounter(self.__device_id, self.component_config.id, prefix="pv") | ||
| self.__phase: int = self.kwargs['phase'] | ||
| self.store = get_inverter_value_store(self.component_config.id) | ||
| self.fault_state = FaultState(ComponentInfo.from_component_config(self.component_config)) | ||
|
|
||
| def update(self): | ||
| url = "http://" + self.__ip_address + "/cm?cmnd=Status%208" | ||
| response = req.get_http_session().get(url, timeout=5).json() | ||
|
|
||
| if 'ENERGY' in response['StatusSNS']: | ||
| currents = [0.0, 0.0, 0.0] | ||
|
|
||
| power = float(response['StatusSNS']['ENERGY']['Power']) * -1 | ||
| currents[self.__phase-1] = (response['StatusSNS']['ENERGY']['Current']), 0.0, 0.0 | ||
| _, exported = self.sim_counter.sim_count(power) | ||
|
|
||
| inverter_state = InverterState( | ||
| power=power, | ||
| currents=currents, | ||
| exported=exported | ||
| ) | ||
| else: | ||
| power = float(response['StatusSNS']['Itron']['Power']) * -1 | ||
| exported = float(response['StatusSNS']['Itron']['E_out']*1000) | ||
|
|
||
| inverter_state = InverterState( | ||
| power=power, | ||
| exported=exported | ||
| ) | ||
|
|
||
| self.store.set(inverter_state) | ||
|
|
||
|
|
||
| component_descriptor = ComponentDescriptor(configuration_factory=TasmotaInverterSetup) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simcount und device_id wird nicht benötigt oder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eine der Tasmota Zählervarianten gibt nur einen Gesamtzählerstand aus. Bisher war das als Import Zählerwert implementiert. Der Simcount wird für den Export Zählerstand benötigt.
Ob ['StatusSNS']['ENERGY']['Total'] den Importwert oder eine Kombination aus Im- und Export wiedergibt ist nicht bekannt.
Möglicherweise wäre auch hier der SimCount besser...