Can't use command_template with number mqtt

I’m creating several mqtt numbers to communicate settings on an esp32 that otherwise don’t fit into a standard device category. All of my other esp devices (lights, switches, sensors, etc.) are using json format for mqtt, so my preference is to generally keep using the same json code in my device code.

I need to add “command_template” to my mqtt number in my yaml file so HA publishes in json format instead of just the number. This configuration variable is listed in HA’s “Number MQTT” documentation, but when I add the variable to yaml, I get a “Property command_template is not allowed” error.

NOTE: attaching what I have does NOT show the error! In HA, the error is after command_template.

  - platform: mqtt
    unique_id: number.framesize
    name: "Framesize"
    state_topic: "ha/framesize"
    command_topic: "ha/framesize/set"
    command_template: {"framesize": {{ value }} }
    min: 0
    max: 3
    retain: true
    json_attributes_topic: "ha/framesize"
    json_attributes_template: '{{ value_json.framesize }}'

Seeing if I can validate configuration anyway since it shouldn’t be an error, I get: Error loading /config/configuration.yaml: invalid key: "OrderedDict([('value', None)])" in "/config/z_packages/helpers.yaml", line 7, column 0

Has something changed that isn’t updated in the documentation, or is this a bug? This isn’t a spelling error, and the error shows up as soon as I add the configuration variable, so it’s not related to a possible mistake in the template itself (not tested yet).

Thanks! I appreciate the help!

1 Like

I ended up changing my arduino code to send/receive mqtt not in json format for these numbers.

I initially changed just the callback in ardruino to make sense of the single number HA was sending, then figured I’d leave json alone when the device sends data, but I tried several attribute template variations and couldn’t get them to work as expected. Opening the entity showed the correct value, but the lovelace card said “unknown”. Eliminating json altogether fixed that.

Anyway, this was something that should’ve worked just like my other mqtt device types and templates in yaml… not sure if this is buggy behavior anyone wants to look into.

I am with EXACTLY the same problem - if command send in string all is ok, but I would love to have command in json - did you come back to this problem or you abandoned it and working with commands as strings?

I abandoned it because it was working fine just sending the numbers; not using json.

me too but that is not as it could be :wink: