AM43 blinds control through MQTT

Oh! thank’s for your job!
the version for esphome reduces the battery drain or it’s identical to the other version?

is anyone else having frequent MQTT disconnects?

Hi,
Can someone help me please. How do I flash these files (am43_cover.cpp, am43_cover.h) to ESPHome? Can I ask for instructions? I’m confused. I apologize for the stupid question. :wink:
Thank you.

this was happening because one of my blinds stopped working and therefor wasn’t responding to the gateway and the watchdog service kept rebooting it.

the Arduino sketch has been working for me - follow the instructions on github

the Arduino sketch has been working for me too. I have eight engines (1 MCU / 2 blinds). But I don’t understand the interaction to ESPHome.

Hi,

It might be useful to share. I’ve configured @buxtronix ESPHome/AM43 fork (great work btw) to only connect via BLE when an action is required. I’ve used templates to simulate a fully connected device to be published to HA. It’s a work in progress but works well for me so far. Sure there is a more elegant way to achieve this.

Thanks

esphome:
  name: kitchen_ble
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "xxx"
  password: "xxx"

logger:

api:

ota:

globals:
  - id: wait_after_connect
    type: int
    restore_value: no
    initial_value: '5000' #in ms
  - id: max_battery_refresh
    type: int
    restore_value: no
    initial_value: '14400000' #in ms
  - id: min_connect
    type: int
    restore_value: no
    initial_value: '3000' #in ms
   
esp32_ble_tracker:

ble_client:
  - mac_address: AA:BB:CC:DD:EE:FF
    id: kitchen_blind
    on_connect:
      - binary_sensor.template.publish:
          id: kitchen_blind_connected
          state: ON
    on_disconnect:
      - binary_sensor.template.publish:
          id: kitchen_blind_connected
          state: OFF

cover:
  - platform: am43_cover
    id: kitchen_blind_cover_internal
    ble_client_id: kitchen_blind
    internal: true
  - platform: template
    name: "Kitchen Blind"
    id: kitchen_blind_cover
    lambda: |-
       return (id(kitchen_blind_cover_internal).position);
    open_action:
      then:
        - script.stop: disable_ble #stop to avoid imminent disconnect
        - script.stop: sleeping_ble #stop to avoid imminent disconnect
        - switch.turn_on: kitchen_blind_ble #start connect
        - wait_until:
            - binary_sensor.is_on: kitchen_blind_connected
        - delay: !lambda "return id(wait_after_connect);" #brief wait to improve reliability
        - cover.open: kitchen_blind_cover_internal
        - script.execute: disable_ble #queue disable timeout
    close_action:
      then:
        - script.stop: disable_ble
        - script.stop: sleeping_ble
        - switch.turn_on: kitchen_blind_ble
        - wait_until:
            - binary_sensor.is_on: kitchen_blind_connected
        - delay: !lambda "return id(wait_after_connect);"
        - cover.close: kitchen_blind_cover_internal
        - script.execute: disable_ble
    stop_action:
      then:
        - script.stop: disable_ble
        - script.stop: sleeping_ble
        - switch.turn_on: kitchen_blind_ble
        - wait_until:
            - binary_sensor.is_on: kitchen_blind_connected
        - delay: !lambda "return id(wait_after_connect);"
        - cover.stop: kitchen_blind_cover_internal
        - script.execute: disable_ble
    position_action:
      then:
        - script.stop: disable_ble
        - script.stop: sleeping_ble
        - switch.turn_on: kitchen_blind_ble
        - wait_until:
            - binary_sensor.is_on: kitchen_blind_connected
        - delay: !lambda "return id(wait_after_connect);"
        - lambda: |-
            auto call = id(kitchen_blind_cover_internal).make_call();
            call.set_position(pos);
            call.perform();
        - script.execute: disable_ble

binary_sensor:
  - platform: template
    name: "Kitchen Blind Connected"
    id: kitchen_blind_connected
sensor:
  - platform: ble_rssi
    mac_address: AA:BB:CC:DD:EE:FF
    name: "Kitchen Blind RSSI"
  - platform: am43
    ble_client_id: kitchen_blind
    battery_level:
      id: kitchen_blind_battery_internal
      internal: true
      on_value_range: #filter out nan
        above: 0
        below: 101
        then:
          - script.execute: battery_updated
    update_interval: 60s
# use template battery sensor to avoid NAN level reporting on low refreshes
  - platform: template
    name: "Kitchen Blind Battery"
    id: kitchen_blind_battery
    unit_of_measurement: '%'

script:
  - id: disable_ble
    mode: restart
    then:
      - script.stop: sleeping_ble
      - delay: !lambda "return id(min_connect);"
      - switch.turn_off: kitchen_blind_ble
      - script.execute: sleeping_ble
  - id: sleeping_ble
    mode: restart
    then:
      - delay: !lambda "return id(max_battery_refresh);"
      - script.stop: disable_ble
      - switch.turn_on: kitchen_blind_ble
      - script.execute: disable_ble
  - id: battery_updated
    mode: restart
    then:
      - lambda: |-
          id(kitchen_blind_battery).publish_state((id(kitchen_blind_battery_internal).state));
      - delay: !lambda "return id(max_battery_refresh)*2.5;" #missed 2.5 max refreshes
      - lambda: |-
          id(kitchen_blind_battery).publish_state(NAN);

switch:
  - platform: restart
    name: "Kitchen Blind ESP Reboot"
  - platform: ble_client
    name: "Kitchen Blind BLE"
    id: kitchen_blind_ble
    internal: true
    ble_client_id: kitchen_blind
1 Like

Nice share! Just on thing I noticed: after the ESP boots, it automatically connects to the ble device. I just added an auto-disconnect a few seconds later, but it would probably be nice to have a connect_on_boot parameter on the ble_client.

I have a working config except for the sensors. I get an error “platform not found”
2021-04-26 16_45_22-Window

I am using the fork of buxtronix configured in the Home Assistant addon:
2021-04-26 16_47_31-Window

What do I do wrong?

I have a strange problem, with the system up to date, when selecting the buxtronix:am43 version I get the following error:
esphome requires Python '>=3.7,<4.0' but the running Python is 3.6.9
Any guidance? From browsing other threads I can’t see anything very clear

Update:
I actually have 3.8.7

System Health

version: core-2021.4.6
installation_type: Home Assistant OS
dev: false
hassio: true
docker: true
virtualenv: false
python_version: 3.8.7
os_name: Linux
os_version: 5.4.83-v7
arch: armv7l

GitHub API: ok
Github API Calls Remaining: 4994
Installed Version: 1.12.1
Stage: waiting
Available Repositories: 782
Installed Repositories: 23

error: failed to load: unknown

logged_in: true
subscription_expiration: April 30, 2021, 2:00 AM
relayer_connected: true
remote_enabled: true
remote_connected: true
alexa_enabled: true
google_enabled: true
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok


host_os: Home Assistant OS 5.13
update_channel: stable
supervisor_version: supervisor-2021.04.0
docker_version: 19.03.15
disk_total: 27.7 GB
disk_used: 12.7 GB
healthy: true
supported: true
board: rpi3
supervisor_api: ok
version_api: ok
installed_addons: File editor (5.3.0), Samba share (9.3.0), Home Assistant Google Drive Backup (0.103.1), Check Home Assistant configuration (3.6.0), InfluxDB (4.0.3), Grafana (6.1.0), ESPHome (1.16.0), SSH & Web Terminal (8.0.1), Ring Devices (4.3.0), SQLite Web (3.0.0)


dashboards: 3
resources: 8
views: 6
mode: storage


api_endpoint_reachable: ok

I’m running an older commit of the repo which works fine for me. We will either need to raise an issue with buxtronix or fork it. I’m happy to have a look at the latest commit if need be.

I’m checking regularely here to see how the progress is to merge it into the Esphome repo. Glad to see you put a new PR. Lets hope it will get merged soon :slight_smile:

Hi
I use AM43 in my project ESPHOM and i have problem with compilation

Compiling /data/blinds/.pioenvs/blinds/src/esphome/components/api/api_connection.cpp.o
In file included from src/esphome/components/am43_cover/am43_base.h:3:0,
                 from src/esphome/components/am43/am43.h:7,
                 from src/esphome/components/am43/am43.cpp:1:
src/esphome/components/am43/am43.cpp: In member function 'virtual void esphome::am43::Am43::gattc_event_handler(esp_gattc_cb_event_t, esp_gatt_if_t, esp_ble_gattc_cb_param_t*)':
src/esphome/components/am43/am43.cpp:46:91: error: 'class esphome::am43::Am43' has no member named 'get_name'
           ESP_LOGE(TAG, "[%s] Detected a Tuya AM43 which is not supported, sorry.", this->get_name().c_str());
                                                                                           ^
src/esphome/core/log.h:119:89: note: in definition of macro 'esph_log_e'
   esp_log_printf_(ESPHOME_LOG_LEVEL_ERROR, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^
src/esphome/components/am43/am43.cpp:46:11: note: in expansion of macro 'ESP_LOGE'
           ESP_LOGE(TAG, "[%s] Detected a Tuya AM43 which is not supported, sorry.", this->get_name().c_str());
           ^
src/esphome/components/am43/am43.cpp:48:90: error: 'class esphome::am43::Am43' has no member named 'get_name'
           ESP_LOGE(TAG, "[%s] No control service found at device, not an AM43..?", this->get_name().c_str());
                                                                                          ^
src/esphome/core/log.h:119:89: note: in definition of macro 'esph_log_e'
   esp_log_printf_(ESPHOME_LOG_LEVEL_ERROR, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
                                                                                         ^
src/esphome/components/am43/am43.cpp:48:11: note: in expansion of macro 'ESP_LOGE'
           ESP_LOGE(TAG, "[%s] No control service found at device, not an AM43..?", this->get_name().c_str());
           ^
Compiling /data/blinds/.pioenvs/blinds/src/esphome/components/api/api_pb2.cpp.o
*** [/data/blinds/.pioenvs/blinds/src/esphome/components/am43/am43.cpp.o] Error 1

Hey! Please tell me how to add your repository to the home assistant? When I try to manually add a link, I get an error …

Try this:

  • Supervisor → Add On Store → ESPHome
  • “Show unused optional configuration options”
  • esphome_version → “buxtronix:am43”

Save/install that.

2 Likes

You can now use the external components feature of ESPHome to use this, no installation or downloading required, just YAML.

See the component repo for details: GitHub - buxtronix/esphome-am43: AM43 component for ESPHome

2 Likes

Your addon is working. This is great! Can be operated directly without additional equipment such as esp32. However, I found that after a while, the drive stops responding and responding to commands. Both from HA and through the native app. I was sure that the problem is in the drive itself. Maybe a marriage or a power problem. However, later, using the method of long testing, it turned out that without starting this integration, everything works fine through the native application. And ping through the phone. But when the integration is started, after a time, from several minutes to several hours, the drive loses control. Only restarting it helps. I guess this is due to multiple requests causing it to hang. But I am not an expert and I cannot find the reason myself. If you can, please see. And many will be very grateful to you)

I guess the device cannot accept 2 connections at the same time. To be honest I only used the mobile app to setup and adjust the device and from there on its only home assistant and don`t really have any issues.

I had some issues in the past where the status of the device was not synced after some hours but could still operate it and my automations worked. But with a recent rebuild it works perfectly now. I guess there where some fixes in the original nodejs app.

Try to make a complete rebuild/reinstall of the addon. Should help :slight_smile:

It works perfectly! Thank you! But the battery state is still unknown. When I have “battery_internal” internal: false, I see the value if am43 is connected, but battery state does not change.

Thanks for the tips.
batt_state

hi! Please tell me: what are the parameters MAC1 & MAC12:
" [Service]
ExecStart=/AM43DIRECTORY/node_modules/.bin/am43ctrl MAC1 MAC12 -l 3001 -d --url mqtt://BROKERIP -u BROKERUSER -p BROKERPASS -d
Restart=always
User=root
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/AM43DIRECTORY"
Hassio writes to me:
“2021-11-21T14:25:50.177Z am43 listening on port 3001
2021-11-21T14:25:50.405Z am43 Found 020062a7c79e but will not connect as it was not specified in the list of devices [ ‘0283a48e2668’ ]
2021-11-21T14:25:52.446Z am43:0283a48e2668 mqtt topic homeassistant/cover/0283a48e2668
2021-11-21T14:25:52.447Z am43:0283a48e2668 interval: 600000
2021-11-21T14:25:52.483Z am43:0283a48e2668 mqtt connected”

ADDON Hassio only sees the first device.