HACamera class

class HACamera : public HABaseDeviceType

HACamera allows to display an image in the Home Assistant panel. It can be used for publishing an image from the ESP32-Cam module or any other module that’s equipped with a camera.

Note

You can find more information about this entity in the Home Assistant documentation: https://www.home-assistant.io/integrations/camera.mqtt/

Public Types

enum ImageEncoding

Values:

enumerator EncodingBinary
enumerator EncodingBase64

Public Functions

HACamera(const char *uniqueId)
Parameters

uniqueId – The unique ID of the camera. It needs to be unique in a scope of your device.

bool publishImage(const uint8_t *data, const uint16_t length)

Publishes MQTT message with the given image data as a message content. It updates image displayed in the Home Assistant panel.

Parameters
  • data – Image data (raw binary data or base64)

  • length – The length of the data.

Returns

Returns true if MQTT message has been published successfully.

inline void setEncoding(const ImageEncoding encoding)

Sets encoding of the image content. Bu default Home Assistant expects raw binary data (e.g. JPEG binary data).

Parameters

encoding – The image’s data encoding.

inline void setIcon(const char *icon)

Sets icon of the camera. Any icon from MaterialDesignIcons.com (for example: mdi:home).

Parameters

icon – The icon name.

Protected Functions

virtual void buildSerializer() override
virtual void onMqttConnected() override

Private Functions

const __FlashStringHelper *getEncodingProperty() const

Returns progmem string representing the encoding property.

Private Members

ImageEncoding _encoding

The encoding of the image’s data. By default it’s HACamera::EncodingBinary.

const char *_icon

The icon of the camera. It can be nullptr.