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

3.3 #49

Merged
merged 1 commit into from
Nov 26, 2024
Merged

3.3 #49

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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.0
hooks:
- id: ruff
name: ruff unused imports
Expand Down
3 changes: 3 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ ignore = [

# https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
"RUF005", # Consider {expression} instead of concatenation

# https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"PT007", # Wrong values type in @pytest.mark.parametrize expected {values} of {row}
]


Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ serial or http (e.g. for tibber) and edit the mqtt settings.
4. Run with analyze
======================================

Now run ``sml2mqtt`` with the path to the configuration file and the ``--analyze`` option.
Now run ``sml2mqtt`` with the path to the configuration file and the ``-a`` or ``--analyze`` option.
(see :ref:`command line interface <COMMAND_LINE_INTERFACE>`).
This will process one sml frame from the meter and report the output.
It's a convenient way to check what values will be reported.
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ will be reported can be processed in various ways with operations.
cli
getting_started
operations
smart_home_systems


Indices and tables
Expand Down
8 changes: 4 additions & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Packages required to build the documentation
sphinx == 7.4.7
sphinx-autodoc-typehints == 2.2.3
sphinx_rtd_theme == 2.0.0
sphinx-exec-code == 0.12
sphinx == 8.1.3
sphinx-autodoc-typehints == 2.5.0
sphinx_rtd_theme == 3.0.2
sphinx-exec-code == 0.14
autodoc_pydantic == 2.2.0
80 changes: 80 additions & 0 deletions docs/smart_home_systems.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
**************************************
Smart Home Systems
**************************************

Here are some examples to get started with various smart home systems.
They all still require some changes so make sure to modify them to fit your setup.

openHAB
======================================

Integration for `openHAB <https://www.openhab.org/>`_ requires that the
`MQTT Binding <https://www.openhab.org/addons/bindings/mqtt.generic/>`_ is used.
The example connects through the Bridge ``mqtt:broker:localhost``

| The topics you enter under ``stateTopic`` must match the topics you have configured in the sml2mqtt configuration.
| Run sml2mqtt with the ``-a`` or ``--analyze`` flag to see the topics that are being published.

.. code-block:: text
:caption: .things file

Thing mqtt:topic:stromzaehler "Stromzähler" (mqtt:broker:localhost) [
availabilityTopic="stromzaehler/status", payloadAvailable="ONLINE", payloadNotAvailable="OFFLINE"
]
{
Channels:

Type number : leistung [stateTopic="stromzaehler/leistung", unit="W"]
Type number : energie [stateTopic="stromzaehler/energie", unit="kWh"]
...


Type string : status [stateTopic="stromzaehler/status"]
}

.. code-block:: text
:caption: .items file

String Zuhause_Status "Status [%s]" {channel="mqtt:topic:stromzaehler:status"}
Number:Power Zuhause_Leistung "Leistung [%d W]" {channel="mqtt:topic:stromzaehler:leistung", unit="W", expire="5m"}
Number:Energy Zuhause_Energie "Energie [%.2f kWh]" {channel="mqtt:topic:stromzaehler:leistung", unit="kWh"}


HomeAssistant
======================================

Integration for `Home Assistant <https://www.home-assistant.io/>`_ requires that the
`mqtt integration <https://www.home-assistant.io/integrations/mqtt#configuration>`_ is used.

| The topics you enter under ``state_topic`` and ``topic`` must match the topics you have
configured in the sml2mqtt configuration.
| Run sml2mqtt with the ``-a`` or ``--analyze`` flag to see the topics that are being published.

.. code-block:: yaml

mqtt:
sensor:
- name: "sml2mqtt_energy_total"
unique_id: f955b69a-828b-4cad-bafd-7563a909153e
state_topic: "sml2mqtt/meter1/energy_total"
icon: mdi:transmission-tower
unit_of_measurement: kWh
state_class: total
device_class: energy
availability:
topic: "sml2mqtt/status"
payload_available: "ONLINE"
payload_not_available: "OFFLINE"

- name: "sml2mqtt_momentary_power"
unique_id: 6ddc1f63-bd73-4d9b-86a1-3e7dfeccee1e
state_topic: "sml2mqtt/meter1/momentary_power"
unit_of_measurement: W
state_class: measurement
device_class: power
availability:
topic: "sml2mqtt/status"
payload_available: "ONLINE"
payload_not_available: "OFFLINE"

...
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ To read from the serial port an IR to USB reader for energy meter is required.

# Changelog

#### 3.3 (2024-11-26)
- Updated dependencies and docs
- Allow rounding to the tenth

#### 3.2 (2024-11-05)
- Automatically select CRC e.g. for Holley DTZ541

Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pytest == 8.3.3
pre-commit == 4.0.1
pytest-asyncio == 0.24.0
aioresponses == 0.7.6
aioresponses == 0.7.7

# Linter
ruff == 0.7.2
ruff == 0.8.0
2 changes: 1 addition & 1 deletion requirements_setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pyserial-asyncio == 0.6
easyconfig == 0.3.2
pydantic == 2.8.2
smllib == 1.5
aiohttp == 3.10.10
aiohttp == 3.11.7
2 changes: 1 addition & 1 deletion src/sml2mqtt/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.2'
__version__ = '3.3'
3 changes: 2 additions & 1 deletion src/sml2mqtt/config/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class HeartbeatAction(BaseModel):
description='Interval'
)


# -------------------------------------------------------------------------------------------------
# Math
# -------------------------------------------------------------------------------------------------
Expand All @@ -108,7 +109,7 @@ class Offset(BaseModel):


class Round(BaseModel):
digits: int = Field(ge=0, le=6, alias='round', description='Round to the specified digits')
digits: int = Field(ge=-4, le=6, alias='round', description='Round to the specified digits, negative for tens')


# -------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/config/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_default() -> None:
- negative on energy meter status: true # Set to "true" to enable or to "false" to disable workaround. If the default obis code for the energy meter is wrong set to the appropriate meter obis code instead
- factor: 3 # Factor with which the value gets multiplied
- offset: 100 # Offset that gets added on the value
- round: 2 # Round to the specified digits
- round: 2 # Round to the specified digits, negative for tens
- type: change filter # Filter which passes only changes
- refresh action: 600 # Refresh interval
'''
2 changes: 1 addition & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def check_obj(model: BaseModel) -> None:
setup_operations(DummyOperationParent(), HasOperationsModel(operations=[model]))

for file in (pytestconfig.rootpath / 'docs').iterdir():
if file.suffix.lower() == '.rst':
if file.suffix.lower() == '.rst' and file.name.lower() != 'smart_home_systems.rst':
validate_yaml_blocks(file, func=check_obj)


Expand Down