MQTT sensor Unknown

Hi guys, I’d really appreciate some help

I’ve installed Mosquito (hass.io, 0.90.2), I’m trying to set up an MQTT sensor which I will publish to using my own attributes, in this case for testing purposes the only attribute is x (if this works i’d like multiple, though unsure of how the syntax for value_template for multiple attributes)

this is in my configuration file

sensor:
  - platform: mqtt
    name: "Test"
    state_topic: "home/plants/1"
    value_template: "{{ value_json.x }}"
    json_attributes_topic: "home/plants/1/attributes"

this is the JSON I’m sending (tried to send to both topics)

{
“x”:908
}

in the frontend/dev-info etc… I can see the sensor “Test”, the value is “Unknown” and it has no attribute x or anything else for that matter.

also in the integration page under mosquito there is no sensor x or sensor test.x

any idea what im doing wrong?

thanks

Try and change this:

{
“x”:908
}

to this:

{
"x":"908"
}

and see if that works better

1 Like

holy crap that actually worked… I wasted hours on that crap haha…

but doesnt that mean my value is a string now and not an integer? not ideal but I can probably live with that.

I tried updating that attribute a few times, hass does not seem to keep the history of these values, is that a limitation of the mqtt sensor? the history is critical for me, if not I will need to find another way then

Just drop the double-quotes delimiting the value.

{ "x": 908 }

The original issue was you weren’t using plain double-quotes (") but fancy double-quotes (). JSON requires plain double, or single, quotes for delimiting strings.

It records a history of an entity’s states, not attributes.