Trouble with MQTT Number integration

Home Assistant is running on Raspberry Pi #1. I have Raspberry Pi #2 running Node-red and a local MQTT broker. They talk over WiFi. I am writing MQTT autodiscover config topics on that RPi#2’s broker and I have my Home Assistant’s MQTT integration configured to connect to that broker. A dozen MQTT integrations for this device are being pulled in as entities belonging to a single Home Assistant device and most are working just fine.

The issue is two MQTT Number entities… while they get discovered as entities, they show as unavailable. They have no initial value. I am trying to use these two entities to allow for two setpoints to be adjusted from the Lovelace interface.

Here’s the config payload I’m setting:

{
    "name": "Disinfect Duration (min)",
    "command_topic": "homeassistant/number/decon-fridge/number_disinfect_duration/set",
    "unique_id": "decon-fridge.number.disinfect_duration.001",
    "device": {
        "name": "decon-fridge",
        "identifiers": [
            "decon_fridge_001"
        ],
        "manufacturer": "Manufacturer",
        "model": "2021",
        "sw_version": "0.01"
    }
}

When I view MQTT info with the above config, the only topic subscribed to for this entity is “config”…it seems the “command” topic is unrecognized.

If I create a “state” topic and write to it with MQTT Explorer I can get a value to populate in Lovelace and then I can change the setpoint from Home Assistant (changes from Home Assistant come through on the “command” topic which Home Assistant was, previously, not subscribing to). But I receive an error when trying to view the device’s MQTT info:

2021-05-03 10:19:06 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.result.entities[3].subscriptions[1].messages[0].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[0].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[1].payload=b''(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[2].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[3].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[4].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[5].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[6].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[7].payload=b'30'(<class 'bytes'>, $.result.entities[6].subscriptions[0].messages[8].payload=b'30'(<class 'bytes'>

Things are working currently (albeit with the MQTT info error which prevents access to the MQTT info page) but it just doesn’t seem like this is how it should work.

I tried this and it works correctly:

number:
- platform: mqtt
  name: mqtt number test
  state_topic: number/get
  command_topic: number/set
  • Publishing a value of 50 to number/get makes 50 appear as the state value of number.mqtt_number_test.
  • Using the UI to change the state value to 55 resulted in the value being published to number/set.

Screenshot from 2021-05-03 14-43-05

However, because the two topics are different, anything set in the UI is, of course, temporary and will revert to displaying the value in state_topic.

In contrast, if the topics are the same then the published value (from Home Assistant) immediately becomes the current value.

number:
- platform: mqtt
  name: mqtt number test
  state_topic: number/set
  command_topic: number/set

Yeah, I’m seeing that it works too but I’m getting an error when I try to open MQTT Info on the device in question:

2021-05-03 14:32:30 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.result.entities[6].subscriptions[1].messages[0].payload=b'30'(<class 'bytes'>

30 was the setpoint I published to the state topic to get Lovelace to allow me to enable the number input.

When I delete the ‘state’ topic with MQTT Explorer I get a warning in homeassistant:

2021-05-03 14:35:51 WARNING (MainThread) [homeassistant.components.mqtt.number] We received <b''> which is not a Number

It seems like Home Assistant is expecting the data in a different format to be able to display it on the MQTT info page of the device but Lovelace doesn’t seem to care?