INSTAR Deutschland GmbH

INSTAR MQTT Server with Home Assistant



Home Assistant Installation on a Raspberry Pi

We already posted an installation guide for Home Assistant for Debian based Linux systems a while ago. But following the installation instruction and the SystemD Service Setup we noticed that a few things changed. But following the updated documentation it turned out to be a breeze to install HASS on our Raspberry Pi 3 with Raspbian Buster.

MQTT Binding

We noticed that now you are able to add an MQTT broker already during the initial setup. There is no longer the need for doing this inside the configuration YAML files:


Home Assistant with your INSTAR IP Camera


When you access the UI for the first time click on adding an extension and choose MQTT from the list. Now type in your INSTAR IP camera IP address (e.g. 192.168.2.165) followed by the port 1883 and your INSTAR MQTT Broker login.


Home Assistant with your INSTAR IP Camera


If you already installed Home Assistant, go to Settings and Integrations and select to add the MQTT Broker there:


Home Assistant with your INSTAR IP Camera

Home Assistant with your INSTAR IP Camera


Testing our MQTT Service

To test if everything is working, we need to go to Developer Tools and MQTT. Here we can setup a subscription for the topic (Listen to a topic) instar/000389888811/status/alarm/area1/enable (please replace the 000389888811 part with the MAC address of your camera).


Home Assistant with your INSTAR IP Camera


In the screenshot you can see that we first received an update that the value for this topic was 0: {"val":"0"}. That means that the alarm detection area 1 was deactivated. Now by publishing the value {"val":"1"} on the topic instar/000389888811/alarm/area1/enable the area gets activated. You can verify this inside your cameras web user interface. You can also deactivate the area again inside the WebUI and see that the MQTT topic switches back to {"val":"0"}.

Adding a UI Switch

We now know that we are able to subscribe to MQTT status topics on our camera and to update these topics via the corresponding command topic. All we need to do now is to add a Switch Component that does this for us and can be assigned to our Home Assistant dashboard.

Switch Component

To keep our main configuration.yaml uncluttered we will create a separate file switches.yaml that contains all our MQTT related switches and import this into the configuration by adding the following line: switch: !include switches.yaml.

We can now add our first switch components - e.g. to activate and deactivate the motion detection areas:

- platform: mqtt
  name: 'Alarm Area 1'
  state_topic: 'instar/000389888811/status/alarm/area1/enable'
  value_template: '{{ value_json.val }}'
  command_topic: 'instar/000389888811/alarm/area1/enable'
  qos: 1
  payload_on: 1
  payload_off: 0
  optimistic: false
  retain: false
- platform: mqtt
  name: 'Alarm Area 2'
  state_topic: 'instar/000389888811/status/alarm/area2/enable'
  value_template: '{{ value_json.val }}'
  command_topic: 'instar/000389888811/alarm/area2/enable'
  qos: 1
  payload_on: 1
  payload_off: 0
  optimistic: false
  retain: false
- platform: mqtt
  name: 'Alarm Area 3'
  state_topic: 'instar/000389888811/status/alarm/area3/enable'
  value_template: '{{ value_json.val }}'
  command_topic: 'instar/000389888811/alarm/area3/enable'
  qos: 1
  payload_on: 1
  payload_off: 0
  optimistic: false
  retain: false
- platform: mqtt
  name: 'Alarm Area 4'
  state_topic: 'instar/000389888811/status/alarm/area4/enable'
  value_template: '{{ value_json.val }}'
  command_topic: 'instar/000389888811/alarm/area4/enable'
  qos: 1
  payload_on: 1
  payload_off: 0
  optimistic: false
  retain: false

For each component - that we assign the switch template to inside our main configuration - we have to define the platform we want to use it on. Now this is the mqtt platform that we added to Home Assistant.

We have both a state_topic and a command_topic. The first one takes the status topic and defines the state our switch is in. The command topic is the one that we use to update the state and trigger our camera to change it's corresponding internal state e.g. switch our alarm area on or off.

Since our camera sends it's values JSON formated {"val":"1"}, we also need to add a template to let Home Assistant know how to extract the value from it, which is done with the value_template. This way we are able to set the value_on and value_off values to 1 and 0, respectively.

Now we are also able to set some MQTT magic. The first one is qos and stands for Quality of Service - where 0 stands for fire-and-forget (your client might loose an status update if it does not receive the message), 1 means that it is verified that a status update is received and 2 is not relevant for us here (with a qos value of 2 it is made sure that every update is received but only received once - which is important e.g. when you are recording time series from measuring sensors). optimistic has to be used when your device does not have a separate state_topic - here you have to assume that the command you just sent worked and the state was updated. With retain you can hold on to the value of a topic even if the client or server cannot be reached. But we don't need this for our setup.

Configuring the User Interface

Now we need to add a new View for our camera by switching the UI into the configuration mode:


Home Assistant with your INSTAR IP Camera


Now click on the + as highlighted in the screenshot below and add a view for your camera:


Home Assistant with your INSTAR IP Camera


Switch to the new view and click on the big + button to add a card that can contain our MQTT switches:


Home Assistant with your INSTAR IP Camera


Choose an Entity Card and select all the switches we just added to our configuration. They should show up automatically - if not, try reloading Home Assistant:


Home Assistant with your INSTAR IP Camera

Home Assistant with your INSTAR IP Camera


Quit the configuration mode to get back to the regular UI and you should be able to see your new card with all 4 alarm area switches. Try switching your alarm areas from your cameras Web User Interface - once you apply your settings there all switched inside Home Assistant should react to the state change immediately.

To learn how add your camera's Live Video to the Lovelace UI, please follow the link.


Home Assistant with your INSTAR IP Camera