MQTT switch conditional on/off based on a payload from another topic?

Hello everyone,

I have a mqtt switch that toggles on/off with this config:

unique_id: Relay
      name: "Relay"
      state_topic: "application/abc000/device/12300/command/down"
      command_topic: "application/abc000/device/12300/command/down"
      payload_on: '{"devEui":"xYzAcE", "confirmed":true, "fPort":7, "data":"QrsT"}'
      payload_off: '{"devEui":"xYzAcE", "confirmed":true, "fPort":7, "data":"QrsU"}'
      qos: 0
      retain: false

Now, let’s say the user toggles this switch on. Can HA first verify the below condition before toggling the switch to the “on” position?

The condition:

Only if the value of “acknowledged” in below payload is true, then toggle “on”, else keep it as “off” :

{
    "deduplicationId": "abcd12345",
    "time": "2025-01-20 00:00:13",
    "deviceInfo": {
        "tenantId": "abc-123",
        "tenantName": "Undisclosed",
        "applicationId": "abc000",
        "applicationName": "Devices",
        "deviceProfileId": "babc000",
        "deviceProfileName": "Relay switch",
        "deviceName": "Relay",
        "devEui": "12300",
        "tags": {}
    },
    "queueItemId": "a7-5eB",
    "acknowledged": true,
    "fCntDown": 17
}

Similarly, I want to do the “off” toggle as well - if the user toggles this switch off, can HA first verify the same above condition (ie. acknowledged must be true in the payload) before toggling the switch to the “off” position?

The condition payload topic is application/abc000/device/12300/event/ack

Hope this makes sense. I’m wondering if there’s a easy way to do this in the switch’s yaml config code.

Thank you.