Air conditioner - AUX - mqtt configuration

There will be two parts in this post: descriptive and question.

Part I: My configuration
I have AUX ASW-H09A4 WiFi air conditioner (further AC). I chose it especially to work with home assistant (further HA). It has Broadlink WiFi module.
It worth mentioning that I installed python version of HA to have minimal footprint and be able to make rapid update (but that’s another story).

This article assumes you already have mosquitto MQTT broker configured and users added.

To control my AC unit I use this script here:
Here’s my service file (/etc/systemd/system/ac_mqtt.service) for this script:

Description=AC connection service ha.service

ExecStartPre=/bin/sleep 20
ExecStart=/opt/homeassistant/bin/python3 /opt/broadlink_ac_mqtt/ -b


This service has it’s own config file which should be located in <workdir>/settings (in my case /opt/broadlink_ac_mqtt/settings) or specified via command line.
Here’s my config file with some placeholders:

    daemon_mode: True
    update_interval: 10
    self_discovery: True
    bind_to_ip: False

    port: 1883
    client_id: ac_to_mqtt
    user: <mqtt user, added in mqtt broker>
    passwd: <your passord here>
    # Line below shows where in mqtt you will search for AC messages
    # feel free use name to your liking
    topic_prefix: /aircon
    auto_discovery_topic: homeassistant
    auto_discovery_topic_retain: False
    discovery: False

- ip: (or any other IP you/dhcp like)
  mac: <here should be mac of your AC, I looked my up in DHCP>
  name: climatic_ctrl
  port: 80

In HA I have my AC device, which can be added to lovelace UI or controlled via automations.

– Up until this line everything works -------------------
Part II: This should work…
The issue I’ve been having is that if HA service restarts (or starts) after ac_mqtt is started, then HA show it unavailable. Once again:

  1. Start HA.
  2. Start ac_mqtt
  3. everything fine.
  4. Restart HA
  5. air conditioner controls unavailable.

I’m relatively new to HA, so I have a question: What will be the best way to resolve this?
Things that crossed my mind:

  1. Make ac_mqtt service dependant on ha service in system - works so-so, doesn’t shine when HA gets restarted from UI.
  2. Track aircon entity state and on unavailable use shell_script to restart services - seems a little clumsy.

Would be glad to hear any suggestions.

1 Like

Ok, I’ll answer my own question:

  restart_ac_connector: /usr/bin/systemctl restart ac_aux.service


alias: restart ac connector on ha start
description: ''
  - platform: homeassistant
    event: start
condition: []
  - service: shell_command.restart_ac_connector
mode: single


alias: restart ac connector
description: ''
  - platform: state
    entity_id: climate.mqtt_<mac_here>
    to: unavailable
condition: []
  - service: shell_command.restart_ac_connector
mode: single

Pretty much works.

1 Like