logo elektroda
logo elektroda
X
logo elektroda

MQTT Discovery Error in openBEKEN v1.17.200 with Home Assistant on TUYA BK7231N Smart Plug

pedropaislopes 2235 9
ADVERTISEMENT
  • #1 20666099
    pedropaislopes
    Level 3  

    Hi!

    I'm facing a small issue with openBEKEN and Home Assistant.

    My device is a simple, generic TUYA smart plug switch with power monitoring, BK7231N based, flashed with the last version of openBEKEN. (version 1.17.200).

    openBEKEN is configured with MQTT and Flag 27 is ON (Invoke HomeAssistant discovery on change to ip address, configuration).

    MQTT server is a Mosquitto running on a virtualized HASSIO installation.

    The auto discovery is working fine: my device appears, with all sensors and switches, on MQTT integration in Home Assistant.

    But HASS log has a bunch of entries related to my smart plug. Here is an example log line:

    
    2023-07-24 10:55:02.884 ERROR (MainThread) [homeassistant.components.mqtt.mixins] Error 'required key not provided @ data['state_topic']' when processing MQTT discovery message topic: 'homeassistant/sensor/TM09_GeladeiraCozinha_sensor_6/config', message: '{'device': {'identifiers': ['TM09_GeladeiraCozinha'], 'name': 'TM09_GeladeiraCozinha', 'sw_version': '1.17.200', 'manufacturer': 'Beken Corporation', 'model': 'BK7231N', 'configuration_url': 'http://192.168.144.59/index'}, 'name': 'http://192.168.144.59/index', 'availability_topic': 'TM09/connected', 'unique_id': 'TM09_GeladeiraCozinha_sensor_6', 'qos': 1, 'platform': 'mqtt'}'
    2023-07-24 10:55:02.886 ERROR (MainThread) [homeassistant.components.mqtt.mixins] Error 'required key not provided @ data['state_topic']' when processing MQTT discovery message topic: 'homeassistant/sensor/TM09_GeladeiraCozinha_sensor_7/config', message: '{'device': {'identifiers': ['TM09_GeladeiraCozinha'], 'name': 'TM09_GeladeiraCozinha', 'sw_version': '1.17.200', 'manufacturer': 'Beken Corporation', 'model': 'BK7231N', 'configuration_url': 'http://192.168.144.59/index'}, 'name': 'http://192.168.144.59/index', 'availability_topic': 'TM09/connected', 'unique_id': 'TM09_GeladeiraCozinha_sensor_7', 'qos': 1, 'platform': 'mqtt'}'
    2023-07-24 10:55:02.887 ERROR (MainThread) [homeassistant.components.mqtt.mixins] Error 'required key not provided @ data['state_topic']' when processing MQTT discovery message topic: 'homeassistant/sensor/TM09_GeladeiraCozinha_sensor_8/config', message: '{'device': {'identifiers': ['TM09_GeladeiraCozinha'], 'name': 'TM09_GeladeiraCozinha', 'sw_version': '1.17.200', 'manufacturer': 'Beken Corporation', 'model': 'BK7231N', 'configuration_url': 'http://192.168.144.59/index'}, 'name': 'http://192.168.144.59/index', 'availability_topic': 'TM09/connected', 'unique_id': 'TM09_GeladeiraCozinha_sensor_8', 'qos': 1, 'platform': 'mqtt'}'
    


    I have a dozen of smart plugs identically flashed and configured, and all of them present the same error on HASS log.

    Am I doing something wrong? Is the required key:
    data['state_topic']

    really missing? Is this a bug in openBEKEN MQTT discovery?

    Thanks in advance!
  • ADVERTISEMENT
  • #2 20669727
    p.kaczmarek2
    Moderator Smart Home
    Hello, does the problem appears when you disable power monitoring?

    Which HA version? It was working for a long time for us, but may be the update changed something.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20690089
    pedropaislopes
    Level 3  

    Hi! Sorry for the long delay.

    My HA version is 2023.08.01.

    I've made a bunch of tests trying to isolate this issue. My steps:

    - OTA upgrade with the last openBEKEN version available (1.17.211)
    - erase flash and reset
    - reconfigure the basic things: Wifi, name, module (relay, button and led pins) and MQTT server. I didn't configure power monitoring pins on this step
    - after Home Assistant discovery, the smart plug appears as an MQTT device with a single relay on it (as it should be). No errors on HASS log.
    - I've proceeded to set BL0937 pins and started BL0937 driver ("startdriver BL0937" on the Webapp console)
    - after HA discovery, with power monitoring, six sensor entities appear on HA, but HASS logs show those errors that I've shown in my first post

    So, for me, these errors appear only with power monitoring.

    There are three error lines, one line for unique_id TM09_GeladeiraCozinha_sensor_6, one for unique_id TM09_GeladeiraCozinha_sensor_7, and one for unique_id TM09_GeladeiraCozinha_sensor_8. On the MQTT server, the topic "homeassistant/sensor/TM09_GeladeiraCozinha_sensor_6" the entry is:

    
    {"dev":{"ids":["TM09_GeladeiraCozinha"],"name":"TM09_GeladeiraCozinha","sw":"1.17.211","mf":"Beken Corporation","mdl":"BK7231N","cu":"http://192.168.xxx.yy/index"},"name":"http://192.168.xxx.yy/index","~":"TM09","avty_t":"~/connected","uniq_id":"TM09_GeladeiraCozinha_sensor_6","qos":1}
    


    Other unique_ids entries on the MQTT server change only the sensor_? number.

    What is weird for me is that 6 sensors (zero to five) are OK, and the last three (6 to 8) present errors. The first 6 are voltage, current, power, energycounter, energycounter_last_hour, and consumption_stats. The consumption_stats sensor is always unavailable/unknown.

    On the TM09 topic, there is power, voltage, current, energycounter, energycounter_last_hour, energycounter_yesterday, energycounter_today, energycounter_clear_date, and other topics (ssid, uptime, etc).

    Any clues?

    Thanks a lot!
  • #5 20700490
    p.kaczmarek2
    Moderator Smart Home
    We have applied naming patch on Aug 16, 2023, so maybe it 's working now? Can you check, @pedropaislopes ?
    https://github.com/openshwprojects/OpenBK7231...mmit/5cb73aa17e5824ce7addc842fd5466ac84e296b3
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #6 20701723
    pedropaislopes
    Level 3  

    Hi!

    Unfortunately, it didn't solve the issue. The following screenshot is from the HA log viewer.

    HA log screenshot showing MQTT errors after updating to version 1.17.224.

    As it can be seen in the image, I've updated the device to the latest version available (1.17.224).

    Thanks a lot!
  • ADVERTISEMENT
  • #7 20703113
    iprak
    Level 6  

    Do you see Voltage/Current/Power entities attached to the device in HomeAssistant? These errors are most probably for OBK_CONSUMPTION_YESTERDAY, OBK_CONSUMPTION_TODAY, and OBK_CONSUMPTION_CLEAR_DATE sensors which don't seem to be completely implemented, and now HomeAssistant is being more strict about such entities.
  • Helpful post
    #8 20749651
    p.kaczmarek2
    Moderator Smart Home
    It seems I've found a problem with a help of @DCG . I was totally not aware that HA discovery would push entities without stat_t and having old HA on my side does not help.

    It should be now fixed, can you check?
    Helpful post? Buy me a coffee.
  • #9 20750509
    pedropaislopes
    Level 3  
    Hi! Congratulations! This release solved the issue. Everything is OK now.

    Thank you!

    Cheers!
  • #10 20750617
    DCG
    Level 6  
    Thanks @p.kaczmarek2 for your support.. I can confirm this issue is now resolved for my smart plug, after updating to v260

Topic summary

The discussion revolves around an MQTT discovery error encountered with a TUYA BK7231N smart plug running openBEKEN v1.17.200 in conjunction with Home Assistant (HA) version 2023.08.01. The user reports that while the device is recognized during MQTT discovery, errors related to missing 'state_topic' keys appear in the HA logs, particularly when power monitoring is enabled. Various troubleshooting steps were taken, including firmware updates and configuration resets, but the issue persisted. Other users suggested that recent changes in Home Assistant's MQTT naming conventions might be the cause. A patch was released to address these issues, and ultimately, the user confirmed that updating to the latest version resolved the problem.
Summary generated by the language model.
ADVERTISEMENT