From f6fbb0dcec2632cd527c631ae23872f6ac7a7426 Mon Sep 17 00:00:00 2001 From: timtasse Date: Sat, 22 Oct 2022 13:31:20 +0200 Subject: [PATCH 1/5] Add Sensor evu/W: Power at the electricity meter, positive means input and negative means feed in --- custom_components/openwbmqtt/const.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/custom_components/openwbmqtt/const.py b/custom_components/openwbmqtt/const.py index 8261285..9f14c93 100644 --- a/custom_components/openwbmqtt/const.py +++ b/custom_components/openwbmqtt/const.py @@ -230,6 +230,16 @@ class openWBNumberEntityDescription(NumberEntityDescription): value_fn=lambda x: round(float(x) * (-1.0)), icon="mdi:solar-power-variant-outline", ), + openwbSensorEntityDescription( + key="evu/W", + name="EVU-Leistung", + device_class=SensorDeviceClass.POWER, + native_unit_of_measurement=POWER_WATT, + state_class=SensorStateClass.MEASUREMENT, + entity_registry_enabled_default=False, + value_fn=lambda x: round(float(x)), + icon="mdi:transmission-tower", + ), openwbSensorEntityDescription( key="evu/WhImported", name="Netzbezug", From a451558e34a6e5621a40ce516231b79fbc550028 Mon Sep 17 00:00:00 2001 From: Stefan Dilk Date: Wed, 2 Oct 2024 01:42:28 +0200 Subject: [PATCH 2/5] Add sensor and service for price-based charging new sensor for the actual price new number entity for the max price for charging new service to change the max price --- custom_components/openwbmqtt/__init__.py | 13 ++++++++++++ custom_components/openwbmqtt/const.py | 24 ++++++++++++++++++++++ custom_components/openwbmqtt/number.py | 8 ++++++-- custom_components/openwbmqtt/services.yaml | 23 +++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/custom_components/openwbmqtt/__init__.py b/custom_components/openwbmqtt/__init__.py index f70c6da..4d90353 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')}/global/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..0b82178 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="/global/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..0e45144 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.mqttTopicCommand}" + 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 From 5d41527617f870383a7fa8e40eae4f070743bc70 Mon Sep 17 00:00:00 2001 From: Stefan Dilk Date: Wed, 2 Oct 2024 02:31:14 +0200 Subject: [PATCH 3/5] Add sensor and service for price-based charging new sensor for the actual price new number entity for the max price for charging new service to change the max price --- custom_components/openwbmqtt/number.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/openwbmqtt/number.py b/custom_components/openwbmqtt/number.py index 0e45144..918bf8b 100644 --- a/custom_components/openwbmqtt/number.py +++ b/custom_components/openwbmqtt/number.py @@ -40,7 +40,7 @@ async def async_setup_entry( for description in NUMBERS_GLOBAL_COPY: if description.mqttTopicCommand.startswith("/"): description.mqttTopicCommand = f"{mqttRoot}{description.mqttTopicCommand}" - description.mqttTopicCurrentValue = 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}" From 3a1ad34986d55ecfd1749a9a468521f74abbc9d2 Mon Sep 17 00:00:00 2001 From: Stefan Dilk Date: Wed, 2 Oct 2024 02:56:25 +0200 Subject: [PATCH 4/5] Add sensor and service for price-based charging new sensor for the actual price new number entity for the max price for charging new service to change the max price --- custom_components/openwbmqtt/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/openwbmqtt/const.py b/custom_components/openwbmqtt/const.py index 0b82178..2cafbb0 100644 --- a/custom_components/openwbmqtt/const.py +++ b/custom_components/openwbmqtt/const.py @@ -874,7 +874,7 @@ class openWBNumberEntityDescription(NumberEntityDescription): native_step=1.0, entity_category=EntityCategory.CONFIG, # icon= - mqttTopicCommand="/global/awattar/MaxPriceForCharging", + mqttTopicCommand="/set/awattar/MaxPriceForCharging", mqttTopicCurrentValue="/global/awattar/MaxPriceForCharging", icon="mdi:currency-eur", ), From c843a87f1a397671d912369654f76d689191db9a Mon Sep 17 00:00:00 2001 From: Stefan Dilk Date: Wed, 2 Oct 2024 02:57:37 +0200 Subject: [PATCH 5/5] Add sensor and service for price-based charging new sensor for the actual price new number entity for the max price for charging new service to change the max price --- custom_components/openwbmqtt/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/openwbmqtt/__init__.py b/custom_components/openwbmqtt/__init__.py index 4d90353..1490357 100644 --- a/custom_components/openwbmqtt/__init__.py +++ b/custom_components/openwbmqtt/__init__.py @@ -97,7 +97,7 @@ def fun_enable_disable_price_based_charging(call): def fun_change_pricebased_price(call): """Change the price for price-based charging""" - topic = f"{call.data.get('mqtt_prefix')}/global/awattar/MaxPriceForCharging" + 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"))