Switch unknown state on HA start or yaml reloading within HA

I’m a very new user & on a steep learning curve here so please bear with me.

I have a wifi relay switch (Tuya type flashed with the openBK firmware - https://github.com/openshwprojects/OpenBK7231N). I’ve installed the latest home assistant on a RPi3 & set the device up in configuration.yaml as follows:

# openBK switch
switch:
  - platform: mqtt
    name: "obk8DB4B177 1"
    state_topic: "obk8DB4B177/1/get"
    command_topic: "obk8DB4B177/1/set"
    qos: 1
    payload_on: 1
    payload_off: 0
    retain: true
    availability_topic: "obk8DB4B177/connected"

I setup a card on the dashboard for this entity and all works OK except on startup of HA or reloading the yaml. When I do this, the switch/relay state is shown as unknown and is not properly showing the switch state as on or off in HA until it the switch is operated either from the dashboard in HA or by pressing the toggle button on the unit.

The results of activating the switch from HA or by the toggle button are:

  1. Clicking the icon on the dashboard card when the relay is in the on state turns the relay off and modifies the displayed state to off.
  2. Clicking the icon on the dashboard card when the relay is in the off state does nothing - Displayed state is still unknown.
  3. When the state shows as unknown, if the pushbutton on the unit is pressed the status in HA is updated correctly.

Any guidance is appreciated. I’ve looked through the forums and manuals, but not yet found anything that seems definitively helpful. I have been assuming that there is a way of querying the on/off status of the device from HA on startup, but maybe this is not possible? Of course thngs are complicated a bit by the openBK firmware, but maybe I’m expecting HA do do something it can’t do. If thats the case, I’ll stop now :slight_smile:

Thanks,

J

From the docs.

In an ideal scenario, the MQTT device will have a state_topic to publish state changes. If these messages are published with a RETAIN flag, the MQTT switch will receive an instant state update after subscription, and will start with the correct state. Otherwise, the initial state of the switch will be unknown.

Take a look in the firmware settings to publish the state with the RETAIN flag.

I found that, but didn’t quite get it at the time. I’ll concentrate on that then.
It seemed to me that this would fail if the switch state changed during the time HA was restarting. Perhaps I missunderstood.

I guess I expected HA to be capable of interrogating the device at will to find the service status.

Thanks,

J

Did you ever solved your problem?

I have this switch and have a same problem - state is unknown right after HA restart. After some state change, HA is updating regularly.

I understand what @VDRainer want to say, but in web UI, I cannot find where I would be able to change the way device is publishing it’s state.

Thx.

The guy who wrote the firmware for the switch produced a firmware version with an option which broadcasts the switch status once a minute. This solved things for me at the time.

I did figure out that I could do something using node red to periodically interrogaqte a switch or sensor to get its state. I used that for a home made heater controller I built. Now that returns temperature, humidity and output status when interrogated using a node red flow in HA. I probably have to optimise that, but seems promising.

1 Like

I’m in the same situation. When I reboot, I have to find the device in settings; and from there I can turn on/off.
Then I go to “home” and its real state appears.
Any solution?