How do I create MQTT Sensor

I’m trying to create a MQTT sensor for generic temp probe on victron cerbo using MQTT.

I can see the value on my MQTT broker and on home assistant but cant see it to create gauge on dashboard. It is the value in yellow line.
An example of sensor config would be appreciated.

  - platform: mqtt
    name: "Temperature"
    state_topic: "tele/sonoff6/SENSOR"
    value_template: "{{ value_json['AM2301'].Temperature }}"
    unit_of_measurement: "°C"

Here’s one of mine. And below is the same sensor in MQTT explorer…

Hopefully that and the page Nick linked above will get you started.

3 Likes

I just re-read and you said you can see it in Home Assistant - does that mean it was discovered?? If so you should be able to find it in the MQTT integration and in Developer Tools. That will let you look at it and either add it to Lovelace UI or manually add it to configuration.yaml

When I open my Mosquitto broker and I listen on venus-home/N/d4124333cb72/temperature/24/Temperature the value as in picture is returned to me.

Yes but either

  1. The device needs to support discovery ; or

  2. You need to set up a sensor in configuration.yaml

Yep, that’s my question how to set up sensor in config.yaml.

Which we have pointed you to in the posts above.

As a hint - your state_topic: will be venus-home/N/d4124333cb72/temperature/24/Temperature and your value_template: will be something like: {{ value_json.value }}.

There are plenty of examples in the JSON section of the link Nick posted.

Thanks, I did go trough everything. Will keep on trying.

Show us your code and tell us what you are seeing in logs, states etc

Configure a sensor in configuration.yaml, use the examples given as a start. If you haven’t edited that file before then you need to install the File Editor add-on. You will also need to restart HA after you save your edits.

If you do the above and it still doesn’t work, paste the sensor config from configuration.yaml and we’ll have a look.

1 Like

Thankyou everyone it is working 100%

2 Likes

I am having the same issue. I have read the mqtt sensor documentation but my mqtt message is more complex than the examples. I would like to create a sensor that reports the confidence value of a match in the attached message.

{
    "id": "1661617146.021728-agmwcn",
    "duration": 0.6,
    "timestamp": "2022-08-27T16:19:32.873Z",
    "attempts": 17,
    "camera": "tv_cam",
    "zones": [
        "main"
    ],
    "misses": [
        {
            "name": "kate",
            "confidence": 94.15,
            "match": false,
            "box": {
                "top": 118,
                "left": 187,
                "width": 25,
                "height": 33
            },
            "checks": [
                "box area too low: 825 < 10000"
            ],
            "type": "latest",
            "duration": 0.61,
            "detector": "compreface",
            "filename": "a11d36d5-7670-4435-94f1-ec52234e607d.jpg",
            "base64": null
        },
        {
            "name": "jane",
            "confidence": 95.74,
            "match": false,
            "box": {
                "top": 119,
                "left": 185,
                "width": 29,
                "height": 33
            },
            "checks": [
                "box area too low: 957 < 10000"
            ],
            "type": "latest",
            "duration": 0.67,
            "detector": "compreface",
            "filename": "cffa9055-41c9-400f-a039-3409af38d6e6.jpg",
            "base64": null
        },
        {
            "name": "raiden",
            "confidence": 41.86,
            "match": false,
            "box": {
                "top": 101,
                "left": 186,
                "width": 29,
                "height": 28
            },
            "checks": [
                "confidence too low: 41.86 < 75",
                "box area too low: 812 < 10000"
            ],
            "type": "latest",
            "duration": 0.67,
            "detector": "compreface",
            "filename": "cffa9055-41c9-400f-a039-3409af38d6e6.jpg",
            "base64": null
        },
        {
            "name": "joe",
            "confidence": 95.36,
            "match": false,
            "box": {
                "top": 45,
                "left": 113,
                "width": 75,
                "height": 86
            },
            "checks": [
                "box area too low: 6450 < 10000"
            ],
            "type": "snapshot",
            "duration": 0.75,
            "detector": "compreface",
            "filename": "fe6b0044-8478-45d6-881f-7b141676de35.jpg",
            "base64": null
        }
    ],
    "match": {
        "name": "joe",
        "confidence": 97.06,
        "match": true,
        "box": {
            "top": 52,
            "left": 131,
            "width": 93,
            "height": 112
        },
        "type": "snapshot",
        "duration": 0.18,
        "detector": "compreface",
        "filename": "29141dd6-8d09-4660-a955-6dec80093b6e.jpg",
        "base64": null
    }
}

My attempt that doesn’t work is

mqtt:
  sensor:
    - name: "joe_face"
      state_topic: 'double-take/matches/joe'
      json_attributes_topic: 'double-take/matches/joe'
      value_template: '{{ value_json.confidence }}'

Based on your JSON, the value_template should be: ‘{{ value_json.misses[0].confidence }}’

I am having a similar problem with mqtt sensors, guess it is not clear where the sensor would show up after it is added. I have the below in my config.yaml and I do not see the Front Porch Motion sensor in my devices or on MQTT broker.

mqtt:
  binary_sensor:
    - name: Front Porch Motion
      state_topic: "HomeSeer-Ctrlr/mcsMQTT/main/Front_Entry/_Front_Door_Motion"
      payload_on: "8"
      payload_off: "0"

Does it appear in states in developer tools?

Hi, I would like to create a Mqtt sensor that asks my Router for the external IP address every hours.

With Mqtt Explorer I tried to make the request to the router, like this:

In Home Assistant, how can I create this sensor?

Thanks

I tried this way but it doesn’t work.
This is my first time trying to create a Mqtt sensor

mqtt:
  sensor:
    - name: "Teltonika RUT Wan IP"
      state_topic: "router/get"
      value_template: "{{ value.json.wan }}"

Try this, replacing ??? with whatever’s under the red box:

mqtt:
  sensor:
    - name: "Teltonika RUT Wan IP"
      state_topic: "router/111887???"
      value_template: "{{ value_json['wan'] }}"

Note the underscore in value_json; and little point concealing your private IP addresses. A 10.x.x.x IP address isn’t public.

That’s the sensor, though — the router is publishing that for you to read. You talk about making a request?