logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

BK7231N Switches with OpenBK in HA Turning On at 3 AM - Firmware Issue?

4139ggn 4281 35
Best answers

Why do my BK7231N/OpenBK switches turn on around 3 AM in Home Assistant?

The thread points to a Home Assistant/MQTT integration issue rather than an OpenBK firmware bug: the logs show HA sending `1` to the device as soon as it reconnects, which makes the relay turn on [#20939162][#21097124] The devices were not rebooting at that time, so the behavior was tied to MQTT reconnects and HA state handling, not uptime resets [#20999305][#20904882] Changing `retain` and enabling OpenBK flag 21 (`[MQTT] Retain power channels`) did not solve it [#20939175][#20939306] The working fix was to enable Home Assistant auto-detection and remove the manual MQTT entries from `configuration.yaml` [#21112094][#21203425] If needed, clean up stale MQTT topics as well, but the reported fix was switching to HA discovery [#21112634]
ADVERTISEMENT
  • #1 20895546
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Hello!
    For months, I have had several switches with BK7231N and OpenBK in their latest versions integrated into HA. Always updated via OTA once a month or so.
    The problem is that for some time, some lights have been turning on when waking up.
    They are set to remember their last state upon reboot. And I have noticed that they always turn on at approximately the same time, 03:00 am.
    Could someone tell me what could be happening?
  • ADVERTISEMENT
  • #2 20896313
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    That's a very strange issue. Do they also reboot at that 03:00 AM?

    Do they also turn on when you disconnect them from MQTT (clear IP, username, password and client name of your HA)?
    Helpful post? Buy me a coffee.
  • #3 20897585
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    I haven't tried leaving it disconnected from MQTT.
    But tonight, again. This is the record he leaves in HA.

    Graph showing on and off cycles of the living room light. Event logs for living room light with date and time of turning on and off.
  • #4 20897614
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    What about OBK up time?
    Helpful post? Buy me a coffee.
  • #5 20897656
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    is at -1. May it maintain its status
  • #6 20897704
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    What is -1? It seems that you have misunderstood me.

    I have asked about OBK uptime, the one that can be read here:
    Screenshot of a user interface showing device information.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 20898164
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    Okay! Today that I added another device, I realized that this particular one (the one that turns on by itself), when it restarts, turns on.
    I do not understand why...
  • #8 20898234
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    You can configure your device to either keep state after restart, or to always set high value after restart, or to set low value after restart. You can also do the same manually in autoexec.bat by executing channel-related commands there.

    So, tell me, does the device reboot at that 3AM? You can tell that by looking at the device uptime.
    Helpful post? Buy me a coffee.
  • #9 20899305
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Today, again.
    Now I have looked at the connection time:
    "Online for 16 hours, 38 minutes, and 8 seconds"
    From what I understand, there has been no reboot....
  • #10 20901913
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Hello! I've been reviewing the history of Home Assistant. And from what I see, every day around 03:01:00 it does this cycle:
    "It became Unavailable"
    "It is turned off"
    "It's on"

    So it stays on all night...
  • ADVERTISEMENT
  • #11 20901925
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    Maybe you have your router scheduled to reboot at 3AM?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #12 20902319
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    I have been able to verify that there are MQTT devices that reboot every night and others do not.
    I have to find out why.
    Anyway, why doesn't it save its status like the others?
  • #13 20902352
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    You can set OBK device to remember it's last state. It's possible to configure it in the Configure Startup menu.
    Helpful post? Buy me a coffee.
  • #14 20902458
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    This is how I have it configured...
    The same thing has happened to me with some other lamp with OpenBK. But every time I update it, it has disappeared...
    But this time no matter how much I update, nothing

    User interface for configuring device channels.
  • #15 20904882
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    This night there were two lights that turned on. And they have waited a little longer, until 04:00:00.
    Both devices run OpenBk. And I have found that they have been connected for more than two days.
    That is, they have not been restarted...
    Any ideas?
  • #16 20904909
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    As I said, disable MQTT and check if they still turn on.

    If only MQTT devices reboot, then check your Home Assistant uptime and Home Assistant logs, I don't think that OBK device can turn itself on its own, I think HA must be sending something.

    You can also post device config here. Which drivers you have enabled? Anything like DGR, Wemo? Still, you said it does not happen without MQTT, right?
    Helpful post? Buy me a coffee.
  • #17 20905085
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    No, that is connected to MQTT.
    Tonight I'll disable "mosquitto" to see what happens.
    But I checked again and it seems that something happens between 3 and 4 at night.
    Many devices become unknown and reconnect a few seconds later. I don't know if it's some kind of glitch that does "something" and throws everything away for a few seconds.
    Mosquitto perhaps?
  • #18 20922408
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Hello, good!
    Well, I updated to version 1.17.405 and that power-up disappeared at 03:00.
    But... This morning when I woke up, I had another switch on!
    I have reviewed it, and I want to remember that it was at version 1.0.0, so I have updated it to the latest (1.17.442).

    What happened? It is true that this one had already done it once. But since the last time I updated it, it stopped doing that.
    Why did it do it again today? Why at 03:00?

    In the image, it looks like three different lights (03:00, 04:00, and 05:00). We were all asleep at home.

    Chart showing switch activity from 18:00 to 10:00 with highlighted periods of being on between 3:00 and 8:00.
  • #19 20924127
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Today when I woke up, I had two switches on!
    I have updated again to the latest version (1.17.424).
    I have discovered that when the switch is reset, it starts with the switch on!

    I don't understand what's wrong...

    Screenshot of start value settings for channels with the option to remember the last state.
  • #20 20924149
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    Can you setup a clear instance of Home Assistant and check if it also restarts then?

    Added after 47 [seconds]:

    4139ggn wrote:

    I have discovered that when the switch is reset, it starts with the switch on!
    Screenshot of start value settings for channels with the option to remember the last state.

    You have set it to "remember last state"..
    Helpful post? Buy me a coffee.
  • #21 20924406
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    p.kaczmarek2 wrote:
    Can you setup a clear instance of Home Assistant and check if it also restarts then?

    I do not know what you mean

    p.kaczmarek2 wrote:
    You have set it to "remember last state"..

    Yes, if it is off, let it be off and the other way around. But if I restart it, it turns on!
  • #22 20939156
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1
    Today without any update two switches have turned on.
    I have updated them again to the latest version. And when it reboots with the update, they turn on again.
    I have looked at the OpenBK registry and what catches my attention is what is marked in bold. I don't know why the state changes when it restarts.


    Quote:
    Info:MAIN:Time 12, idle 252346/s, free 73344, MQTT 0(1), bWifi 1, secondsWithNoPing -1, socks 3/38
    Info:MQTT:mqtt_connection_cb: Successfully connected
    Info:MQTT:mqtt_subscribed to Interruptor barra/+/set
    Info:MQTT:mqtt_subscribed to cmnd/Interruptor barra/+
    Info:MQTT:mqtt_subscribed to Interruptor barra/+/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic Interruptor barra/0/set
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 0
    Info:GEN:CHANNEL_Set channel 0 has changed to 1 (flags 0)
    Info:MQTT:Channel has changed! Publishing 1 to channel 0
    Info:MQTT:Publishing val 1 to Interruptor barra/0/get retain=0
    Info:CFG:####### Flash Save Channel 0 as 1 #######

    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic Interruptor barra/0/get
    Info:MAIN:Time 13, idle 236018/s, free 85048, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 14, idle 256572/s, free 85048, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 15, idle 252747/s, free 85048, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MAIN:Time 16, idle 258704/s, free 85048, MQTT 1(1), bWifi 1, secondsWithNoPing -1, socks 2/38
    Info:MQTT:Channel has changed! Publishing 0 to channel 0
    Info:MQTT:Publishing val 0 to Interruptor barra/0/get retain=0
    Info:CFG:####### Flash Save Channel 0 as 0 #######
  • #23 20939162
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    This is a very big progress, @4139ggn ! But you haven't marked enough on your log dump.

    Here, look:
    Screenshot of a log with a highlighted section in a red box.
    The fragment in red frame indicates that your HA sends value 1 to OBK just when OBK connects to it.

    Now, the question is, why HA sends it?

    I am not sure if I have asked about it already, but have you tried to enable "retain" on a device, in flags settings? Maybe it can help as a work around.
    Helpful post? Buy me a coffee.
  • #24 20939175
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    Where should I look at this, what do you say about retaining?
    In the configuration.yaml the configuration is this:

    Quote:
    - unique_id: "Interruptor barra"
    state_topic: "Interruptor barra/0/get"
    name: "Interruptor barra"
    command_topic: "Interruptor barra/0/set"
    qos: 1
    payload_on: 1
    payload_off: 0
    retain: false
    availability:
    - topic: "Interruptor barra/connected"

  • #25 20939224
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    Wait, so you're not using automatic hass discovery? You can try to set retain to true, instead of false.
    Helpful post? Buy me a coffee.
  • #26 20939306
    4139ggn
    Level 5  
    Posts: 36
    Rate: 1

    I have switched to automatic detection of Home Assistant.
    I have also made sure to have Flags enabled:
    "Flag 21 - [MQTT] Retain power channels (Relay channels, etc)"
    I restart the device and it turns on.
    I have tried restarting Mosquitto. And it also lights up!
  • #27 21092693
    Nakano
    Level 10  
    Posts: 25
    Rate: 2

    Hello, have you managed to solve the problem?
    I have a similar situation, only it is not about the lights, but about the gate. Every call after losing the connection to the MQTT triggers the switches (2ch) and opens or closes the gate.
  • #28 21097124
    jtauscher87
    Level 7  
    Posts: 13
    Rate: 2

    I have the same problem, I have two Bekens with identical config/flags etc and still, one is turning on after reboot or wifi loss, whereas the other device works like a charm. Retain true/false doesn't make any difference. As soon as it connects to HASS MQTT broker the device turns on.

    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 0
    Info:GEN:CHANNEL_Set channel 0 has changed to 1 (flags 0)
    Info:MQTT:Channel has changed! Publishing 1 to channel 0 
    Info:MQTT:Publishing val (303 bytes) to tele/GarageLicht/STATE retain=0
    Info:MQTT:Publishing val 1 to GarageLicht/0/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic tele/GarageLicht/STATE
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic GarageLicht/0/get
    Info:MQTT:Publishing val (303 bytes) to stat/GarageLicht/RESULT retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic GarageLicht/0/set
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 0
    Info:GEN:No change in channel 0 (still set to 1) - ignoring

  • #29 21097127
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14649
    Help: 655
    Rate: 12661
    Well this clearly means that your Home Assistant send value 1, doesn't it?
    
    Info:MQTT:MQTT client in mqtt_incoming_data_cb data is 1 for ch 0
    Info:GEN:CHANNEL_Set channel 0 has changed to 1 (flags 0)
    

    How is it configured in HA?
    Helpful post? Buy me a coffee.
  • #30 21097137
    jtauscher87
    Level 7  
    Posts: 13
    Rate: 2

    Its configured as suggested. Retain true/false doesn't make any difference. Its clearly a mosquitto fault but i have no clue why one bekens works fine and one doesn't.

    # GarageLicht:
    - unique_id: "GarageLicht_relay_0"
    name: "GarageLicht 0"
    state_topic: "GarageLicht/0/get"
    command_topic: "GarageLicht/0/set"
    qos: 1
    payload_on: 1
    payload_off: 0
    retain: true
    availability:
    - topic: "GarageLicht/connected"

Topic summary

✨ The discussion revolves around the issue of BK7231N switches running OpenBK in Home Assistant (HA) that unexpectedly turn on at approximately 3 AM. Users report that the switches are configured to remember their last state upon reboot, yet they activate without user intervention. Various troubleshooting steps are suggested, including checking MQTT connections, device uptime, and Home Assistant logs. Some users find that disabling MQTT resolves the issue, while others discover that the problem persists despite configurations to retain the last state. A common theme is the need to ensure proper integration with Home Assistant, with some users resolving their issues by enabling automatic detection and removing manual configurations from configuration.yaml. The discussion highlights the complexity of MQTT interactions and the importance of device settings in preventing unintended activations.

FAQ

TL;DR: If your OpenBK switch turns on around 03:00 and logs show "HA sends value 1", the usual cause is Home Assistant MQTT behavior after reconnect, not a spontaneous OpenBK relay change. This FAQ helps Home Assistant, Mosquitto, and OpenBK users stop night-time self-activation by checking uptime, MQTT topics, and discovery settings. [#20939162]

Why it matters: A relay that flips ON at 03:00 can light rooms, trigger gates, or create unsafe automations after Wi‑Fi or broker reconnects.

Setup choice What the thread showed Result
Manual configuration.yaml MQTT setup Some devices received .../0/set 1 after reconnect Unwanted turn-ons persisted
Home Assistant auto-discovery Problem disappeared after removing manual YAML entries Stable behavior reported
MQTT reconnect without cleanup Devices went unavailable, then reconnected within seconds Some relays turned ON

Key insight: The strongest evidence in the thread is the OpenBK log line showing MQTT received data 1 on the command topic right after reconnect. That points to Home Assistant or retained MQTT state, not random firmware self-activation.

Quick Facts

  • The failure window clustered around 03:00–04:00, including 03:01:00, 04:00:00, and even 05:00 in one history screenshot, which strongly suggests a scheduled network or broker event rather than random relay noise. [#20922408]
  • One affected device reported "Online for 16 hours, 38 minutes, and 8 seconds" after the night event, so at least that case was not caused by a full device reboot. [#20899305]
  • The thread mentions multiple OpenBK builds during testing, including 1.17.405, 1.17.424, and 1.17.442; updating alone did not consistently fix the issue across devices. [#20922408]
  • In the decisive log dump, OpenBK received MQTT payload 1 on topic Interruptor barra/0/set, changed channel 0 to 1, then later published 0 again; that shows an external command path, not a local spontaneous toggle. [#20939156]
  • A later resolution reported that enabling Home Assistant auto-discovery and removing manual configuration.yaml entries fixed the unwanted activations. [#21112094]

Why do BK7231N switches running OpenBK turn on by themselves around 3 AM in Home Assistant?

They usually turn on because Home Assistant or MQTT sends an ON command when the device reconnects around 03:00, not because OpenBK randomly flips the relay. The clearest proof is the OpenBK log showing MQTT received data is 1 for ch 0, then CHANNEL_Set channel 0 has changed to 1. The thread also shows many devices going unavailable between 03:00 and 04:00, then reconnecting seconds later, which matches a broker, router, or HA event window. [#20939156]

How can I tell whether an OpenBK device is actually rebooting at night by checking its uptime?

Check whether the uptime resets near the event time. If the web interface still shows a long session, such as Online for 16 hours, 38 minutes, and 8 seconds, the device did not reboot at 03:00 that night. That distinction matters because a reconnect without reboot points to MQTT, Home Assistant, or network interruptions instead of a firmware crash or power cycle. [#20899305]

What does the OpenBK uptime value mean, and where can I find it in the web interface?

OpenBK uptime is the elapsed time since the device last booted, shown in the device web interface status area. It tells you whether the switch truly restarted or only lost MQTT or Wi‑Fi briefly. In the thread, the developer explicitly asked for the OBK uptime visible in the web UI screenshot, because that value is the quickest way to separate reboot problems from reconnect problems. [#20897704]

Why would a Home Assistant MQTT setup send a '1' to an OpenBK command topic right after the device reconnects?

Home Assistant can send 1 right after reconnect because it restores or republishes state through the MQTT command topic when the device comes back online. The OpenBK log in this case shows mqtt_incoming_publish_cb topic Interruptor barra/0/set, then data is 1 for ch 0, then channel 0 changes to 1. The thread’s expert conclusion was direct: “your HA sends value 1 to OBK just when OBK connects.” [#20939162]

How do I stop OpenBK relays from turning on after Wi‑Fi loss or MQTT reconnect in Home Assistant?

The most successful fix in the thread was to enable Home Assistant auto-discovery and remove old manual MQTT YAML entries. That user reported the issue stopped after switching to discovery and deleting configuration.yaml definitions. If the relay still activates, test with MQTT disabled for one night, then inspect whether .../0/set 1 appears after reconnect. [#21112094]

What is MQTT retain, and how does the OpenBK 'Retain power channels' flag affect switch state recovery?

"MQTT retain" is a broker message setting that stores the last published payload on a topic, so newly reconnected clients immediately receive that saved value. In the thread, the OpenBK maintainer suggested enabling Flag 21 - [MQTT] Retain power channels as a workaround, and also testing retain: true in Home Assistant. It can help state recovery, but users reported it did not fix every device. [#20939306]

Home Assistant MQTT auto-discovery vs manual configuration.yaml for OpenBK devices — which is better for avoiding unwanted turn-ons?

Home Assistant auto-discovery worked better in this thread. Manual configuration.yaml setups were repeatedly linked with reconnect events that sent .../0/set 1, while the original poster later said the problem disappeared after enabling Home Assistant detection and removing manual YAML entries. That makes discovery the safer choice here for avoiding false ON commands after MQTT reconnects. [#21203425]

How do I enable Home Assistant auto-discovery for OpenBK and safely remove the old manual MQTT YAML entries?

Use this 3-step method. 1. Enable Home Assistant detection in OpenBK. 2. Remove or comment out the old manual MQTT switch entries from configuration.yaml. 3. Restart the device and verify Home Assistant recreates it through discovery. The thread’s confirmed fix was exactly that sequence: enable auto-detection, eliminate manual YAML, and the unwanted turn-ons stopped. [#21112094]

Why does an OpenBK switch configured to 'remember last state' still power up ON after a restart?

It powers up ON because the remembered state is not the only factor; Home Assistant can still send an ON command after reconnect. In the thread, the user expected “remember last state” to restore OFF, but logs later showed MQTT pushing 1 to the command topic. So the startup setting may be correct, yet the relay still turns ON because an external MQTT command overrides it moments later. [#20939156]

What should I check in Home Assistant logs, Mosquitto, and router settings if multiple MQTT devices go unavailable between 3:00 and 4:00 AM?

Check for any scheduled restart or reconnect event between 03:00 and 04:00. The thread specifically suggests reviewing Home Assistant uptime, Home Assistant logs, Mosquitto behavior, and whether the router is scheduled to reboot at 03:00. If several devices become unavailable for a few seconds and then reconnect, that pattern fits a network or broker interruption more than a single bad relay. [#20904909]

How can MQTT Explorer help clean up stale retained topics that make OpenBK switches or gates self-activate?

MQTT Explorer can remove stale retained topics so reconnecting devices do not receive an old ON state again. One participant advised deleting the troubled MQTT topics, then starting the correctly configured switches and setting retain to true. That is especially useful when a gate or 2-channel relay self-activates immediately after broker reconnection, even before Home Assistant fully re-adds the device. [#21112634]

What's the best way to test whether Home Assistant, Mosquitto, or OpenBK firmware is causing random relay activation?

Isolate each layer one at a time. First disconnect MQTT and leave the device overnight. Next restart Mosquitto and watch whether the relay turns ON immediately. Then compare OpenBK uptime with Home Assistant logs. If the device stays online for more than 16 hours yet still switches ON after reconnect, the fault path is upstream of the relay logic. That method was repeatedly recommended in the thread. [#20905085]

How do I read OpenBK logs to see whether the relay changed state locally or because MQTT sent a command?

Look for an incoming MQTT publish before the channel change. In the decisive example, the log shows mqtt_incoming_publish_cb topic Interruptor barra/0/set, then mqtt_incoming_data_cb data is 1 for ch 0, and only after that CHANNEL_Set channel 0 has changed to 1. That sequence proves the relay changed because MQTT sent a command, not because the relay logic toggled locally. [#20939156]

Why do two OpenBK or Beken devices with the same flags and config behave differently when reconnecting to the same MQTT broker?

Because the broker or Home Assistant may hold different topic history or entity state for each device. The thread includes cases where two Bekens had identical flags and config, yet only one turned ON after reboot or Wi‑Fi loss. Another user reported three BL602 devices from the same batch, but only one self-activated after MQTT loss. Matching firmware alone did not guarantee matching reconnect behavior. [#21100362]

What is OpenBK, and how does it work with BK7231N, BL602, Mosquitto, and Home Assistant MQTT devices?

"OpenBK is open-source device firmware that runs on chips such as BK7231N and BL602, exposes relay and channel control, and integrates with Home Assistant through MQTT brokers like Mosquitto. In this thread, users ran OpenBK on switches, lamps, and even a gate controller. The practical problem was not basic compatibility, but MQTT reconnect behavior that could send 1 to a relay command topic. [#21092693]
ADVERTISEMENT