#MQTT state template in UI

1 messages · Page 1 of 1 (latest)

teal fern
#

Hi guys, first post here.

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. When I try, I get "Unknown" as state (as per the docs when command and state payloads do not match).

The yaml specifies which topic to subscribe to for state updates, and which values to accept for on and off respectively.

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. Using {% if value_json.output == True.... I could probably repeat the command payloads, but given the intricacy of the command payload and the relative simplicity of the state topic (.output), specifying which values HA should accept for what is a much more attractive option.

I'd like to move to the MQTT settings UI due to having created many other MQTT entities, liking the grouping by device, etc. (My yaml entities do not appear there.)

I've looked in the docs, the forum and this Discord and haven't been able to find an example 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 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. :)

teal fern
#

Am I asking the question wrong? Or maybe better to post on forums? It's been a few days with no response. 🙂