Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

configuration for price-based charging #71

Merged
merged 7 commits into from
Oct 7, 2024
Merged
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
13 changes: 13 additions & 0 deletions custom_components/openwbmqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def fun_enable_disable_price_based_charging(call):
payload = str(0)
hass.components.mqtt.publish(hass, topic, payload)

def fun_change_pricebased_price(call):
"""Change the price for price-based charging"""
topic = f"{call.data.get('mqtt_prefix')}/set/awattar/MaxPriceForCharging"
_LOGGER.debug("topic (change_pricebased_price): %s", topic)
_LOGGER.debug(f"set price to: {call.data.get('target_price')}")
hass.components.mqtt.publish(hass, topic, call.data.get("target_price"))

# Register our services with Home Assistant.
hass.services.async_register(DOMAIN, "enable_disable_cp", fun_enable_disable_cp)
hass.services.async_register(
Expand All @@ -111,6 +118,11 @@ def fun_enable_disable_price_based_charging(call):
"enable_disable_price_based_charging",
fun_enable_disable_price_based_charging,
)
hass.services.async_register(
DOMAIN,
"change_pricebased_price",
fun_change_pricebased_price,
)

# Return boolean to indicate that initialization was successfully.
return True
Expand All @@ -126,6 +138,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.services.async_remove(DOMAIN, "change_charge_limitation_per_cp")
hass.services.async_remove(DOMAIN, "change_charge_current_per_cp")
hass.services.async_remove(DOMAIN, "enable_disable_price_based_charging")
hass.services.async_remove(DOMAIN, "change_pricebased_price")
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

return unload_ok
24 changes: 24 additions & 0 deletions custom_components/openwbmqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntityDescription
from homeassistant.const import (
PERCENTAGE,
CURRENCY_CENT,
Platform,
UnitOfElectricCurrent,
UnitOfElectricPotential,
Expand Down Expand Up @@ -388,6 +389,15 @@ class openWBNumberEntityDescription(NumberEntityDescription):
entity_registry_enabled_default=False,
icon="mdi:battery-charging-low",
),
openwbSensorEntityDescription(
key="global/awattar/ActualPriceForCharging",
name="aktueller Strompreis",
device_class=None,
native_unit_of_measurement=CURRENCY_CENT,
state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False,
icon="mdi:currency-eur",
)
]

SENSORS_PER_LP = [
Expand Down Expand Up @@ -854,6 +864,20 @@ class openWBNumberEntityDescription(NumberEntityDescription):
mqttTopicChargeMode="pv",
icon="mdi:current-ac",
),
openWBNumberEntityDescription(
key="global/awattar/MaxPriceForCharging",
name="Maximalpreis Laden",
device_class=None,
native_unit_of_measurement=CURRENCY_CENT,
native_min_value=0.0,
native_max_value=50.0,
native_step=1.0,
entity_category=EntityCategory.CONFIG,
# icon=
mqttTopicCommand="/set/awattar/MaxPriceForCharging",
mqttTopicCurrentValue="/global/awattar/MaxPriceForCharging",
icon="mdi:currency-eur",
),
]

NUMBERS_PER_LP = [
Expand Down
8 changes: 6 additions & 2 deletions custom_components/openwbmqtt/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ async def async_setup_entry(

NUMBERS_GLOBAL_COPY = copy.deepcopy(NUMBERS_GLOBAL)
for description in NUMBERS_GLOBAL_COPY:
description.mqttTopicCommand = f"{mqttRoot}/config/set/{str(description.mqttTopicChargeMode)}/{description.mqttTopicCommand}"
description.mqttTopicCurrentValue = f"{mqttRoot}/config/get/{str(description.mqttTopicChargeMode)}/{description.mqttTopicCurrentValue}"
if description.mqttTopicCommand.startswith("/"):
description.mqttTopicCommand = f"{mqttRoot}{description.mqttTopicCommand}"
description.mqttTopicCurrentValue = f"{mqttRoot}{description.mqttTopicCurrentValue}"
else:
description.mqttTopicCommand = f"{mqttRoot}/config/set/{str(description.mqttTopicChargeMode)}/{description.mqttTopicCommand}"
description.mqttTopicCurrentValue = f"{mqttRoot}/config/get/{str(description.mqttTopicChargeMode)}/{description.mqttTopicCurrentValue}"

numberList.append(
openWBNumber(
Expand Down
23 changes: 23 additions & 0 deletions custom_components/openwbmqtt/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ change_charge_current_per_cp:
min: 6
max: 16
step: 1

enable_disable_price_based_charging:
description: Enable or disable price-based charging
fields:
Expand Down Expand Up @@ -167,3 +168,25 @@ enable_disable_price_based_charging:
number:
min: 1
max: 8

change_pricebased_price:
description: Change Price for price-based charging
fields:
mqtt_prefix:
name: Prefix for MQTT topic
description: respective Prefix on the MQTT server that addresses the respective wallbox
default: 'openWB/openWB'
example: 'openWB/openWB'
required: true
selector:
text:
target_price:
name: Charging price in cent
description: Price in cent
default: 20
example: 22
selector:
number:
min: 0
max: 50
step: 1
Loading