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

Add mqtt delay possibility #105

Merged
merged 5 commits into from
May 23, 2023
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
8 changes: 8 additions & 0 deletions custom_components/tasmota_irhvac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
CONF_TEMP_SENSOR,
CONF_HUMIDITY_SENSOR,
CONF_POWER_SENSOR,
CONF_MQTT_DELAY,
CONF_MIN_TEMP,
CONF_MAX_TEMP,
CONF_TARGET_TEMP,
Expand Down Expand Up @@ -144,6 +145,7 @@
DEFAULT_NAME,
DEFAULT_STATE_TOPIC,
DEFAULT_COMMAND_TOPIC,
DEFAULT_MQTT_DELAY,
DEFAULT_TARGET_TEMP,
DEFAULT_MIN_TEMP,
DEFAULT_MAX_TEMP,
Expand Down Expand Up @@ -208,6 +210,7 @@
vol.Optional(
CONF_STATE_TOPIC, default=DEFAULT_STATE_TOPIC
): mqtt.valid_subscribe_topic,
vol.Optional(CONF_MQTT_DELAY, default=DEFAULT_MQTT_DELAY): vol.Coerce(float),
vol.Optional(CONF_MAX_TEMP, default=DEFAULT_MAX_TEMP): vol.Coerce(float),
vol.Optional(CONF_MIN_TEMP, default=DEFAULT_MIN_TEMP): vol.Coerce(float),
vol.Optional(CONF_TARGET_TEMP, default=DEFAULT_TARGET_TEMP): vol.Coerce(float),
Expand Down Expand Up @@ -451,6 +454,7 @@ def __init__(
self._enabled = False
self.power_mode = None
self._active = False
self._mqtt_delay = config[CONF_MQTT_DELAY]
self._cur_temp = None
self._min_temp = config[CONF_MIN_TEMP]
self._max_temp = config[CONF_MAX_TEMP]
Expand Down Expand Up @@ -1198,7 +1202,11 @@ async def send_ir(self):
setattr(self, '_' + key.lower(), 'off')

payload = (json.dumps(payload_data))

# Publish mqtt message
if float(self._mqtt_delay) != float(DEFAULT_MQTT_DELAY):
await asyncio.sleep(float(self._mqtt_delay))

await mqtt.async_publish(self.hass, self.topic, payload)

# Update HA UI and State
Expand Down
2 changes: 2 additions & 0 deletions custom_components/tasmota_irhvac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
CONF_TEMP_SENSOR = "temperature_sensor"
CONF_HUMIDITY_SENSOR = "humidity_sensor"
CONF_POWER_SENSOR = "power_sensor"
CONF_MQTT_DELAY = "mqtt_delay"
CONF_MIN_TEMP = "min_temp"
CONF_MAX_TEMP = "max_temp"
CONF_TARGET_TEMP = "target_temp"
Expand Down Expand Up @@ -96,6 +97,7 @@
DEFAULT_NAME = "IR AirConditioner"
DEFAULT_STATE_TOPIC = "state"
DEFAULT_COMMAND_TOPIC = "topic"
DEFAULT_MQTT_DELAY = 0
DEFAULT_TARGET_TEMP = 26
DEFAULT_MIN_TEMP = 16
DEFAULT_MAX_TEMP = 32
Expand Down
3 changes: 3 additions & 0 deletions examples/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ climate:
humidity_sensor: sensor.kitchen_humidity #optional - default None
power_sensor: binaly_sensor.kitchen_ac_power #optional - default None
vendor: "ELECTRA_AC"
# When operating grouped devices at the same time, MQTT commands are intentionally delayed to prevent multiple devices
# from performing the same operation at the same time. This allows the high current peaks to be shifted.
mqtt_delay: 0.0 #optional - default 0 int or 0.0 float value in [sec].
min_temp: 16 #optional - default 16 int value
max_temp: 32 #optional - default 32 int value
target_temp: 26 #optional - default 26 int value
Expand Down