Howto configure I/O MQTT Device

Hi there,
i have a MQTT device, which has 32 Outputs.

To set an output it expects:

  • Topic “my/homectrl/cmd”
  • Message “on 27” or “off 27” where 27 is the number of the Pin to be set.

The actual state is published from the device for all outputs:

  • Topic “my/homectrl/output”
  • Message:
{
  "millis": 2061760064,
  "pins": {
    "0": "off",
    "1": "off",
    ....
    "31": "off"
  },
  "state": 0,
  "hex": "0x0"
}

The State of Pin 27 is in “pins.27”
With the Template-Tester I get the right value with the template: {{ value_json.pins['27'] }}

To configure the Light i tried to send a Message to:

  • Topic “homeassistant/light/diele/config”
  • Message:
{
  "name": "Diele",
  "state_topic":   "my/homectrl/output",
  "state_template": "{{ value_json.pins['27'] }}",
  "payload_on": "on 27",
  "payload_off": "off 27",
  "command_topic": "my/homectrl/cmd",
  "unique_id": "esp32_27_diele",
  "device":{
    "identifiers": "esp32_diele_27",
    "name": "Diele"
  }
}

“Diele” is the name of the Light.

Everything seems to work correct. I am able to switch the Light on and off.
But I don’t see the status.The Gui shows two flash-symbols instead of a switch symbol.

diele

My Questions:

  • What am i doing wrong?
  • How can i debug this?
  • Where do i find more Information about this?

it is state_value_template

I have tried both:

  • state_template
  • state_value_template
    and even both together.

But HomeAssistant never get the State.

If I set the entity manually, a switch shows up in the GUI.
But if i then switch the Light, immediately the two flashes reappear.
I can see the Message in the MQTT-Explorer and i double checked the topic and payload.

Is there a way to debug the status parsing?

OK I figured out, that it works with this in configuration.yaml

  - light:
      name: 'Bad Wanne'
      state_topic: "ohs42a/homectrl/output"
      state_value_template: "{{value_json.pins['2']}} 2"
      payload_on: "on 2"
      payload_off: "off 2"
      command_topic: "ohs42a/homectrl/cmd"
      unique_id: "esp32_2_bad-wanne"

But with MQTT-Autoconfiguration publishing this message to homeassistant/light/badwanne/config

{
  "name": "Bad Wanne",
  "state_topic": "ohs42a/homectrl/output",  
  "state_value_template": "{{value_json.pins['2']}} 2",    
  "command_topic": "ohs42a/homectrl/cmd",
  "payload_on": "on 2",
  "payload_off": "off 2",
  "optimistic": true,
  "unique_id": "esp32_2_bad-wanne"
}

I think, that setting of state_value_template is disabled when Autoconfiguration is used.