How to recreate MQTT entity from yaml in reworked MQTT UI configurator

Hi guys and girls,

I’m stuck trying to move the below MQTT entity from yaml to the reworked MQTT settings UI within HomeAssistant UI.

Specifically, I struggle with the state templating.

  - switch:
      name: "Elhegn"
      unique_id: "A13_K1_OUT1"
      command_topic: "A13_K1/rpc"
      payload_on: '{"id": 1, "src":"homeassistant", "method": "Switch.Set", "params": {"id": 0, "on": true}}'
      payload_off: '{"id": 1, "src":"homeassistant", "method": "Switch.Set", "params": {"id": 0, "on": false}}'
      state_topic: "A13_K1/status/switch:0"
      value_template: "{{ value_json.output }}"
      state_on: true
      state_off: false
      qos: 1

I’ll be clear; the above works perfectly, I just want to switch to configuring via UI, because my yaml configured entities does not show up in the MQTT configuration UI.

When I try, I get “Unknown” as state (as per the docs when command and state payloads do not match), so this is expected. Solving it seems beyond me though.

What I specifically struggle with is that the yaml and the template seem to me to work in completely different ways. The yaml above specifies which state topic payloads to interpret as on or off respectively. This makes sense to me. Templating seems to instead want to translate the payloads into something else, but unless I translate them very literal into the exact (and complicated and different for each output) command payload, it won’t solve the state unknown issue.

I can’t seem to get similar behavior for the value template? I use the same state topic of course. I can point to {{ value_json.output }} but this does not match the command payload still - it simply looks in the right place in the JSON array.

Using {% if value_json.output == True… I could (I tried) probably repeat the command payloads, but given the intricacy of the command payload and the relative simplicity of the state topic (value_json.output being simply true or false), specifying which values HA should accept (like in the yaml) is a much more attractive option. I just can’t seem to understand how to make templates work in that way?

I’ve looked on Google, in the docs, this forum and asked in the Discord(a few days ago) and haven’t been able to find an example anywhere to achieve what I’d like, despite the relatively simple nature (on/off) of the state. I can’t figure out if that should warn me off that this is not intended use, or if it’s just that it’s too dumb a use case to document. Has me stuck though.

Thank you so much for any help. :slight_smile:

Nicolai