diff --git a/custom_components/openwbmqtt/__init__.py b/custom_components/openwbmqtt/__init__.py index f70c6da..1490357 100644 --- a/custom_components/openwbmqtt/__init__.py +++ b/custom_components/openwbmqtt/__init__.py @@ -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( @@ -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 @@ -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 diff --git a/custom_components/openwbmqtt/const.py b/custom_components/openwbmqtt/const.py index 3881f70..2cafbb0 100644 --- a/custom_components/openwbmqtt/const.py +++ b/custom_components/openwbmqtt/const.py @@ -20,6 +20,7 @@ from homeassistant.components.switch import SwitchDeviceClass, SwitchEntityDescription from homeassistant.const import ( PERCENTAGE, + CURRENCY_CENT, Platform, UnitOfElectricCurrent, UnitOfElectricPotential, @@ -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 = [ @@ -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 = [ diff --git a/custom_components/openwbmqtt/number.py b/custom_components/openwbmqtt/number.py index 611b371..918bf8b 100644 --- a/custom_components/openwbmqtt/number.py +++ b/custom_components/openwbmqtt/number.py @@ -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( diff --git a/custom_components/openwbmqtt/services.yaml b/custom_components/openwbmqtt/services.yaml index 25b1ed6..bb49873 100644 --- a/custom_components/openwbmqtt/services.yaml +++ b/custom_components/openwbmqtt/services.yaml @@ -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: @@ -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