Dafang camera controll with MQTT swicthes failed after upgrading to 2022.3

There is a breaking change for MQTT switches in HA 2022.3 with the introduction of unknown state. After a restart all my swutches are unknown and I can not control my camera. If I set their status to “off” through Developer tools, controls come alive until the next publish of device states (become unknown again). Here is one of my switches’ configuration, can you please advise what should be added/changed to maintain the state?
switches.yaml:

- platform: mqtt
  name: "dafang_move_right"
  unique_id: dafang_move_right
  icon: "mdi:arrow-right"
  state_topic: "livingroom/dafang/motors/horizontal"
  command_topic: "livingroom/dafang/motors/horizontal/set"
  payload_on: "right"

Horizontal state is reporting the position between 0 and 2600, like 1300 for example, if camera is set to the middle. I tried to figure out more with MQTT Explorer, but couldn’t find a solution. I’m sure something has to be done with the sate, but don’t know what exactly. Thank you for your ideas in advance.

You may want to check that your Dafang MQTT config is set to retained so that when you restart HA, Dafang data is still present on the MQTT server without having to wait for the next refresh…

Thank you for your time. I set the option and restarted HA, but the situation is still the same. Manually configured MQTT switches are still unavailable and for this reason not possible to use them for control. The option you pointed out has effect only on the MQTT entries provided by the camera and not on the manually created controls, is that right? Can you please advise what should be added to the configuration block in the original post? Thank you.

I’m sorry I was on holiday.
Yes entities coming from the cameras via MQTT will have their settings retained if you’ve set the flag.
What do you mean by manually created controls?

I meant the template switches created with the MQTT platform. See the OP for an example. Most probably some options have to be activated here too, but don’t know exactly which ones. I’m asking you as I understood you have more experience with MQTT than me :slight_smile: Thanks.

not 100% sure because I don’t use this function in HA, that being said, when looking at my dafang I see this:
image
I think your payload is wrong and should be ±100 depending on the direction you want to turn.
Also I’d probably replace your switch with a button
And you may want to check some of the availability options on that page too as it seems no availability in your config = not available…

Thanks again for your suggestion. The payload was fine until the upgrade of 2022.3, but you are right, numbers can also be used, which is very useful for preset states. The main issue was caused by the manually configured switches, as they did not have a proper status, as you also pointed out. Unfortunately I was not able to figure out how the availability topic should be used (in some cases there is a separate topic for them, provided by the device itself, but not in Dafang’s case - maybe a value_template could be configured, but I’m not that experienced with MQTT). So I decided to follow your recommendation and deleted the manually configured switches for movements and replaced them by MQTT buttons. They are statless, so I don’t have to take care of their status :smiley: The only issue caused by this change is the Picture glance I use for the camera: buttons placed on it are not directly usable, a “more info” window pops up, where I have a PRESS button. A bit unconvinient, but it works. Thank you again for your kind help.