logo elektroda
logo elektroda
X
logo elektroda

OpenBeken BK7231N + BL0942 MQTT Sensor Availability in Home Assistant, Missing avty_t

avgapon 369 5
ADVERTISEMENT
  • #1 21821590
    avgapon
    Level 2  
    Hi. I am totally new here, so maybe I am asking something obvious or silly. My apologies if that's the case.

    I've just reflashed a pretty generic Tuya smart plug based on BK7231N (T34, actually) + BL0942 to the latest OpenBeken firmware that has been downloaded by the GUI flasher (1.18.249).
    Everything went very well, everything works.
    Home Asssistant has auto-discovered the device and it was also perfect.

    Then, I pulled the plug from the wall socket and that's when I got a bit puzzled.
    Home Assistant shows the switch entity of the device as unavailable, but for all power sensors it keeps showing the last reported value.

    I checked with MQTT explorer and I think that the issue may be related to availability topic ("avty_t") in the discovery messages.
    I see relevant topics under homeassistant/switch (there's just one, homeassistant/switch/XXX_relay_1/config) and under homeassistant/sensor (there are several of them).
    The topic under "switch/" has a message with JSON payload that has
    "avty_t": "~/connected"
    field in it.
    But messages in the topics under "sensor/" do not have that field in their payloads.

    I guess that's why Home Assistant does not know / care about availability of those sensors.

    I wonder if I configured something wrong or if I haven't configured something that I should have.

    AI: Could you please share whether you customized any MQTT or discovery settings in OpenBeken, or are you using the default configuration?

    Almost default configuration.

    In Flags I have only flag 2 set.

    I also have a startup command:
    backlog startDriver NTP; ntp_setServer 192.168.0.1; ntp_timeZoneOfs +3; SetupEnergyStats 1 60 5;
    


    AI: Which versions of Home Assistant and your MQTT broker are you currently using?
    mosquitto-2.0.22
    HASS 2026.1.2

    Added after 31 [minutes]:

    Another observation is that discovery messages for "internal sensors" (like chip temperature, RSSI, etc) do have avty_t in them.
    Only energy related sensors don't have it.
    Makes me wonder if maybe SetupEnergyStats could be responsible for that.
  • ADVERTISEMENT
  • #2 21822138
    avgapon
    Level 2  
    I think that the effect could be a regression from https://github.com/openshwprojects/OpenBK7231...mmit/d491a71a938135f92a7dc3f838e8f983e7101de7
    
    commit d491a71a938135f92a7dc3f838e8f983e7101de7 (tag: 1.17.673)
    Author: Tester23 <openshwprojects@gmail.com>
    Date:   Thu Sep 5 18:19:26 2024 +0200
    
        made avty disable global
    


    If I read the intent correctly, it was to make flag 35 apply to all kinds of "entities", not only those considered as sensors (isSensor variable in hass_init_device_info).
    But after the change, "avty_t" is always disabled for sensors, regardless of the flag.
    I do not think that it was the intent?
  • ADVERTISEMENT
  • #3 21822144
    p.kaczmarek2
    Moderator Smart Home
    Interesting, if so, it's a bug. If you have a fix, please submit, if not, I'll check it with self test soon. I am not yet certain it's the case.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #4 21822147
    avgapon
    Level 2  
    >>21822144
    I don't have a formal fix, but I think that it should be to check only `!flagavty` instead of `!isSensor && !flagavty` as the code does now.
    I can open an issue or a PR if that would be better.
  • ADVERTISEMENT
  • #5 21834377
    p.kaczmarek2
    Moderator Smart Home
    Helpful post? Buy me a coffee.
  • #6 21834493
    avgapon
    Level 2  
    >>21834377 >>21834377
    Yes, I did it to get a free firmware build :-) and to expose the proposed change properly.
    I've just tested the new firmware, and after doing "Start Home Assistant Discovery", I now see "avty_t": "~/connected" for all sensors where I expected it to be.
ADVERTISEMENT