Skip to main content

MQTT

MQTT

The mqtt integration allows Viseron to connect to an MQTT broker and publish and subscribe to topics.

It is also used to integrate with Home Assistant.

Configuration

Configuration example
mqtt:
broker: mqtt_broker.lan
port: 1883
username: !secret mqtt_user
password: !secret mqtt_pass
mqttmap required
MQTT configuration.

Topics

Viseron internally manages entities, which in turn are published to MQTT topics. Available entity domains are:

  • binary_sensor: Binary sensors show on/off states
  • image: Images are published as JPEGs
  • sensor: Sensors show any values
  • toggle: Toggles are used to switch things on or off
tip

You can observe the logs to find the entity ids.

Binary sensor topics

{client_id}/binary_sensor/{camera_identifier}_connected/state

Shows if Viseron is connected to a camera.

Payloads
{
"state": "on",
"attributes": {}
}

{client_id}/binary_sensor/{camera_identifier}_recorder/state

Shows whether the recorder is recording or not.

Payloads
{
"state": "on",
"attributes": {
"last_recording_start": "2022-09-14T06:53:34.602066",
"last_recording_end": null,
"path": "/recordings/front_door/2022-09-14/06:53:34.mp4",
"thumbnail_path": "/recordings/front_door/2022-09-14/06:53:34.jpg"
}
}

{client_id}/binary_sensor/{camera_identifier}_object_detected/state

A JSON formatted payload is published to this topic when any configured label is in the field of view.

Payloads
{
"state": "on",
"attributes": {}
}

{client_id}/binary_sensor/{camera_identifier}_object_detected_{label}/state

A JSON formatted payload is published to this topic when a specific configured label is in the field of view.

Payloads
{
"state": "on",
"attributes": {
"count": 2
}
}

{client_id}/binary_sensor/{camera_identifier}_zone_{zone}_object_detected/state

A JSON formatted payload is published to this topic when any configured label is in the specific zone.

Payloads
{
"state": "on",
"attributes": {}
}

{client_id}/binary_sensor/{camera_identifier}_zone_{zone}_object_detected_{label}/state

A JSON formatted payload is published to this topic when a specific configured label is in the specific zone.

Payloads
{
"state": "on",
"attributes": {
"count": 2
}
}

{client_id}/binary_sensor/{camera_identifier}_motion_detected/state

A JSON formatted payload is published to this topic when motion is detected.

Payloads
{
"state": "on",
"attributes": {}
}

{client_id}/binary_sensor/{camera_identifier}_face_detected_{person name}/state

A JSON formatted payload is published to this topic when a tracked face is detected.

Payloads
{
"state": "on",
"attributes": {
"camera_identifier": "<camera_identifier>",
"camera_name": "<camera name>",
"name": "<person name>",
"confidence": "<detection confidence>",
"coordinates": "<detection coordinates>"
}
}

Toggle topics

{client_id}/toggle/{camera_identifier}_connection/command

Used for turning on/off a camera. Payload should be ON or OFF.

Payloads
ON

{client_id}/toggle/{camera_identifier}_connection/state

Camera connection state.

Payloads
{
"state": "on",
"attributes": {}
}

Image topics

{client_id}/image/{camera_identifier}_latest_thumbnail/image

A JPEG encoded image is published to this topic when a new recording starts. The object that triggered the recorder will have its bounding box drawn.

{client_id}/image/{camera_identifier}_latest_thumbnail/attributes

A JSON formatted payload with attributes (currently empty)

Sensor topics

{client_id}/sensor/{camera_identifier}_object_detector_fps/state

A JSON formatted payload is periodically published to with an estimate of the current object detectors processing FPS.

Payloads

preprocessor_fps and inference_fps is used to calculate the state, which is the same as the theoretical_max_fps

{
"state": 34.2,
"attributes": {
"preprocessor_fps": 305.2,
"inference_fps": 34.3,
"theoretical_max_fps": 34.2
}
}

{client_id}/sensor/{camera_identifier}_operation_state/state

A JSON formatted payload is published to this topic to indicate the current status of the camera

Payloads
{
"state": "scanning_for_objects",
"attributes": {}
}

{client_id}/sensor/{camera_identifier}_image_classification/state

Viseron state topic

{client_id}/state

A JSON formatted payload is published to this topic to indicate the current status of Viseron.

Payloads
online

Last Will Topic

{client_id}/lwt

MQTT Last will and Testament

Payloads
online

Home Assistant MQTT Discovery

Viseron integrates into Home Assistant using MQTT discovery.

note

Home Assistant integration is disabled by default. You enable it by adding home_assistant to your mqtt config.

Viseron will create a number of entities depending on your configuration.

The paragraphs below show a few of the most notable ones.

Cameras

  1. A camera entity named camera.{camera_identifier}_latest_thumbnail is created.

Sensors

  1. A status sensor named sensor.{camera_identifier}_operation_state is created. The state is set to idle, recording, scanning_for_motion, scanning_for_objects or error_scanning_frame depending on the situation.
  2. A sensor that shows current the object detector FPS.

Binary Sensors

A variable amount of binary sensors will be created based on your configuration.

  1. An entity showing if any tracked object is in view.
  2. An entity for each tracked object showing if the label is in view.
  3. An entity for each zone showing if any tracked object is in the zone.
  4. An entity for each tracked object in a zone showing if the label is in the zone.
  5. An entity showing if motion is detected.
  6. An entity showing if a face is detected.
  7. An entity showing camera connection.

Switch

  1. A switch used to arm/disarm a camera. When disarmed, no system resources are used for the camera.

Troubleshooting

To enable debug logging for mqtt, add the following to your config.yaml
/config/config.yaml
logger:
logs:
viseron.components.mqtt: debug