The sensor is correctly sending the JSON payload, and MQTT subscriptions running on my desktop are receiving the updates, but the value is never updated on the Home Assistant dashboard (the state remains as the literal “Unknown”). Value updates correct if I subscribe to the topic in Mosquitto.
Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 12:31:50 (4933 occurrences)
Last logged: 13:51:06
Template variable error: 'value_json' is undefined when rendering '{{ value_json.wgust10 }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.windavg10m }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.avgbearing }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.press }}'
Template variable error: 'value_json' is undefined when rendering '{{ value_json.windspeed }}'
My guess it’s that is some metadata used to configure whatever tool.
The screenshot seems to show valid JSON, but ofc we don’t know unless the OP post a complete payload in text (not image) format.
EDIT: Actually, a random JSON validator tells me numbers like +0.3, with the “+”, is not valid JSON
The way he posted the data is confusing. what he posted is valid json, however the topics contents is not. Just take what’s in the data field (remove the exterior quotes) and run it through a json checker. It’s littered with errors.
It’s interesting, the company I work for purposely outputs +'s on positive numbers. However we are doing that on human readable text files. (It’s a readability thing to reduce mistakes). I would have never thought that was invalid json. Then again, I always have json libraries handle the creation of the numerical format when serializing.
I had already encountered that kind of semi-weird 'non valid" error on numbers with explicit “+” signs (not sure it was JSON), so that made me test it.
Thank you all for taking your time!
The sensors has worked for almost a year with “<#timehhmmss>” , but started to drop out recently, random more or less. Yesterday it worked overnight and stopped in the morning.
I use it for my my Davis Vantage Pro 2+ weather station, connected through Cumulus MX software. The template mqtt that shows an example on how to properly config Cumulus MX to send JSON looks like this:
See above. At least from the image of the payload you showed, the templates will only work as long as tempchangeh decreases. Wrap that one (you can do all actually) between double quotes.
I’m having a similar issue I think, but I don’t understand from the comments here what the actual solution was in this case - and if I then can use that.
in my case I have simple dht22 sensor, that I have sending both
and still in both cases I get: ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.temperature }}'
At least one of those should work, I would have thought — provided your MQTT setup is working. To check, please remove the value_template line altogether, and then share a screenshot of the Developer Tools / States page for the sensor once it has updated. Like this, but for your sensor:
Right now on mobile, but in home assistant log I see:
2023-02-14 14:19:34.773 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.dht22_temperature has device class None, state class None and unit °C thus indicating it has a numeric value; however, it has the non-numeric value: {"humidity":26.51,"temperature":21.24} (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mqtt%22