diff --git a/custom_components/openwbmqtt/__init__.py b/custom_components/openwbmqtt/__init__.py index 3fbfce4..3360ed7 100644 --- a/custom_components/openwbmqtt/__init__.py +++ b/custom_components/openwbmqtt/__init__.py @@ -84,6 +84,19 @@ def fun_change_charge_current_per_cp(call): payload = str(call.data.get("target_current")) hass.components.mqtt.publish(hass, topic, payload) + + def fun_enable_disable_price_based_charging(call): + """Enable or disable price-based charging for charge point # --> set/lp#/etBasedCharging [0,1].""" + topic = f"{call.data.get('mqtt_prefix')}/set/lp{call.data.get('charge_point_id')}/etBasedCharging" + _LOGGER.debug("topic (enable_disable_price_based_charging): %s", topic) + + if call.data.get("selected_status") == "On": + payload = str(1) + hass.components.mqtt.publish(hass, topic, payload) + + else: + payload = str(0) + hass.components.mqtt.publish(hass, topic, payload) # Register our services with Home Assistant. hass.services.async_register(DOMAIN, "enable_disable_cp", fun_enable_disable_cp) @@ -96,6 +109,7 @@ def fun_change_charge_current_per_cp(call): hass.services.async_register( DOMAIN, "change_charge_current_per_cp", fun_change_charge_current_per_cp ) + hass.services.async_register(DOMAIN, "enable_disable_price_based_charging", fun_enable_disable_price_based_charging) # Return boolean to indicate that initialization was successfully. return True @@ -108,6 +122,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.services.async_remove(DOMAIN, "change_global_charge_mode") 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") 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 7743697..bb67d16 100644 --- a/custom_components/openwbmqtt/const.py +++ b/custom_components/openwbmqtt/const.py @@ -90,6 +90,7 @@ class openwbSwitchEntityDescription(SwitchEntityDescription): mqttTopicCommand: str | None = None mqttTopicCurrentValue: str | None = None + mqttTopicChargeMode: str | None = None @dataclass @@ -714,6 +715,15 @@ class openWBNumberEntityDescription(NumberEntityDescription): mqttTopicCurrentValue="ChargePointEnabled", device_class=SwitchDeviceClass.SWITCH, ), + openwbSwitchEntityDescription( + key="PriceBasedCharging", + entity_category=EntityCategory.CONFIG, + name="Preisbasiertes Laden (Modus Sofortladen)", + device_class=SwitchDeviceClass.SWITCH, + mqttTopicCommand="etBasedCharging", + mqttTopicCurrentValue="etBasedCharging", + mqttTopicChargeMode="sofort", + ), ] NUMBERS_GLOBAL = [ diff --git a/custom_components/openwbmqtt/services.yaml b/custom_components/openwbmqtt/services.yaml index 505b3a4..25b1ed6 100644 --- a/custom_components/openwbmqtt/services.yaml +++ b/custom_components/openwbmqtt/services.yaml @@ -137,3 +137,33 @@ change_charge_current_per_cp: min: 6 max: 16 step: 1 +enable_disable_price_based_charging: + description: Enable or disable price-based charging + fields: + mqtt_prefix: + name: Prefix for MQTT topic + description: Prefix on the MQTT server that addresses the respective wallbox + default: 'openWB/openWB' + example: 'openWB/openWB' + required: true + selector: + text: + selected_status: + name: Price-based Charging + description: Desired price-based charging status + default: 'Off' + required: true + selector: + select: + options: + - 'On' + - 'Off' + charge_point_id: + name: Charge point ID + description: ID of the charge point which shall be enabled / disabled + default: 1 + required: true + selector: + number: + min: 1 + max: 8 diff --git a/custom_components/openwbmqtt/switch.py b/custom_components/openwbmqtt/switch.py index 460e99f..6bc46fd 100644 --- a/custom_components/openwbmqtt/switch.py +++ b/custom_components/openwbmqtt/switch.py @@ -38,12 +38,12 @@ async def async_setup_entry( for chargePoint in range(1, nChargePoints + 1): localSwitchesPerLP = copy.deepcopy(SWITCHES_PER_LP) for description in localSwitchesPerLP: - description.mqttTopicCommand = ( - f"{mqttRoot}/set/lp{str(chargePoint)}/{description.mqttTopicCommand}" - ) - description.mqttTopicCurrentValue = ( - f"{mqttRoot}/lp/{str(chargePoint)}/{description.mqttTopicCurrentValue}" - ) + if description.mqttTopicChargeMode: + description.mqttTopicCommand = f"{mqttRoot}/config/set/{str(description.mqttTopicChargeMode)}/lp/{str(chargePoint)}/{description.mqttTopicCommand}" + description.mqttTopicCurrentValue = f"{mqttRoot}/config/get/{str(description.mqttTopicChargeMode)}/lp/{str(chargePoint)}/{description.mqttTopicCurrentValue}" + else: # for manual SoC module + description.mqttTopicCommand = f"{mqttRoot}/set/lp/{str(chargePoint)}/{description.mqttTopicCommand}" + description.mqttTopicCurrentValue = f"{mqttRoot}/lp/{str(chargePoint)}/{description.mqttTopicCurrentValue}" switchList.append( openwbSwitch( unique_id=integrationUniqueID,