Mqtt - entity is non numeric

Hi, I have Cumulus MX sending mqtt messages to HA. It works for a few hours then suddenly:


Logger: homeassistant.helpers.template
Source: helpers/template.py:1378
First occurred: 7:19:56 (582 occurrences)
Last logged: 7:36:58

Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.tempTA }}’
Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.humidityOut }}’
Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.humidityIn }}’
Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.rainfall }}’
Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.wgust }}’


My sensor configuration in configuration.yaml looks like this:


  • platform: mqtt

    state_topic: “CumulusMX/Interval”

    name: “VP2 temp out”

    unit_of_measurement: “°C”

    icon: mdi:temperature-celsius

    value_template: ‘{{ value_json.tempOut }}’


Totally lost. Help appreciated!

Please format your post correctly (see point 11 here).

Have you used something like MQTT Explorer to see if the MQTT messages are still being published?

Sorry, my bad with the code :wink:

Yes, when I listen to the topic via Mosquitto broker it updates perfectly.

  - platform: mqtt
    state_topic: "CumulusMX/Interval"
    name: "VP2 temp out"
    unit_of_measurement: "°C"
    icon: mdi:temperature-celsius
    value_template: '{{ value_json.tempOut }}'

When looking at the log, it says
‘dict object’ has no attribute ‘tempOut’ when rendering ‘{{ value_json.tempTH }}’

Sounds like the cumulusmx is sending incorrect data. What exactly is received (use mosquitto_sub)

I’m not sure what you mean with mosquitto_sub. Listening to the topic returns this:

Message 1 received on CumulusMX/Interval at 8:35:
{
    "time": "08:35:28",
    "tempOut": 15.6,
    "tempIn": 20.2,
    "tempTA": 9.6,
    "humidity": 63,
    "wgust": 2.7
}

Any chance the sensor configuration in yaml is wrong? But apparently it works for a while, then giving up. i was thinking that maybe somenthin is missing, like “state”…? Or the ’ ’ around the value.json string should be with " " instead.

When the error occurs what is the mqtt data?

mosquitto_sub is the standard commandline tool to connect to your broker. If you run

mosquitto_sub -h SERVERADDRESS -u USER -P PASSWORD -t CumulusMX/Interval

you may catch what data is sent at the time you get an error.

1 Like

At a guess, you’re getting occasional empty or different messages on the topic, which you need to filter out. Try:

 value_template: >-
    {% if tempOut in value_json %}
      {{ value_json.tempOut }}
    {% else %}
      {{ states('sensor.vp2_temp_out') }}
    {% endif %}

…which uses the prior value of the sensor if the incoming data can’t be processed. I don’t think you’ve posted all of your sensors with the references to other data points, but a similar approach could be used for all.

1 Like

Exactly what I was trying to say.

If I use this on my wind sensor, who just showed up “non numeric” :pleading_face: I pasted your code in Visual Code:

  - platform: mqtt
    state_topic: "CumulusMX/Interval"
    name: "VP2 windGust10m"
    icon: mdi:weather-windy
     value_template: >-
    {% if wgust in value_json %}
      {{ value_json.wgust }}
    {% else %}
      {{ states('sensor.vp2_temp_out') }}
    {% endif %}

But Visual code protests with this:

Quite new into deeper digging in Home Assistant, and I appreciate your help!

Bad indentation, it says so right there.

By that it means that " " are missing somewhere?

No it means your indentation is incorrect. Try:

  - platform: mqtt
    state_topic: "CumulusMX/Interval"
    name: "VP2 windGust10m"
    icon: mdi:weather-windy
    value_template: >
      {% if wgust in value_json %}
        {{ value_json.wgust }}
      {% else %}
        {{ states('sensor.vp2_temp_out') }}
      {% endif %}
1 Like

Lovely :heart_eyes:, no protest from Visual Code. Now I’ll restart and see if this fixes the problem.

2021-06-02 102601

Nope, no luck… Wind gust is still showing up as “non-numeric”.

Mosquittto reads this:

Message 26 received on CumulusMX/Interval at 10:27:
{
    "time": "10:27:03",
    "tempOut": 18.3,
    "tempIn": 21.1,
    "tempTA": 10.9,
    "humidity": 54,
    "wgust": 3.1
}

Sensor code now looks like this, and seems to work well in VSC:

  - platform: mqtt
    state_topic: "CumulusMX/Interval"
    name: "VP2 windGust10m"
    icon: mdi:weather-windy
    value_template: >
      {% if wgust in value_json %}
        {{ value_json.wgust }}
      {% else %}
        {{ states('sensor.vp2_wgust') }}
      {% endif %}

This is why it’s important to understand code, not just copy and paste it. Indentation is critical in YAML, and you don’t seem to be clear on what my template is doing.

I think you want sensor.vp2_windgust10m in your template for this sensor — the template is referencing its own sensor.

1 Like

maybe because states are always strings even if they look like a number.

try this:

- platform: mqtt
    state_topic: "CumulusMX/Interval"
    name: "VP2 windGust10m"
    icon: mdi:weather-windy
    value_template: >
      {% if wgust in value_json %}
        {{ value_json.wgust }}
      {% else %}
        {{ states('sensor.vp2_wgust') | float }}
      {% endif %}

Also requires a unit of measurement for pretty graphs.

1 Like

Well, first of all thanks for your effort and support everyone! :pray:

Now I’ve been running mqtt overnight without any problems. I have a guess what could trigger the error.
Cumulus sends data to Mosquitto via a readable .txt file. It looks like this right now:

{"time":"<#timehhmmss>","temp":<#temp rc=y>,"tempin":<#intemp rc=y>,
"humidity":<#hum>,"wgust":<#wgust rc=y>}

I have added sensors that match the inputs above, just to start over.

Before this I’ve done edits and added data fields with notepad++ and saved as a .txt file in a long single line, then after some time I got this annoying “entity is non numeric” error.

Yesterday I edited the “stock” file from Cumulus MX with Sublime text, making some minor adjustments to meet my needs, and inputs were automatically shifted to a new line (a 2:nd line, see above), not a single line with all inputs. So far no errors.

I guess you couldn’t be bothered analysing this properly