This is how you add an INSTAR Full HD MQTT camera to Home Assistant.
MQTT Broker
You start by configuring the MQTT broker inside the cameras webUI under Network. Here you can set:
- MQTT Server Address: Leave at 127.0.0.1 to use the internal broker
- MQTT Server Port: Default 1883, adjust if needed
- Username /Password: Set your own login
Now we can add our MQTT broker to Home Assistant under Settings / Integrations / MQTT via the Lovelace UI. The server address is the IP of our INSTAR Full HD camera. Add the port and login you choose in the earlier step.
MQTT Interface
The complete MQTT API is documented here. It basically mirrors the cameras webUI. E.g. to switch the motion detection areas you have to navigate the webUI to Alarm / Areas. The MQTT topic to switch Area 1 on or off is alarm/area1/enable
. The payload of this topic is:
-
{“val”:”0”}
/switch off -
{“val”:”1”}
/switch on
Since we can have more than one camera on our network, we also need to add an ID for the camera we want to contact. This ID always starts with instar
followed by local
(to contact the camera that runs the MQTT broker), all
(to send the message to all INSTAR cameras on the MQTT network) or the LAN MAC address of a camera to target it specifically:
instar/local/alarm/area1/enable
instar/all/alarm/area1/enable
instar/000389888811/alarm/area1/enable
And one more thing – every of those, so called COMMAND Topics, also has a corresponding STATE Topic:
instar/local/alarm/area1/enable
instar/local/status/alarm/area1/enable
We use the first one to update / switch something on our camera and – once this happened successfully – receive a state update to set the state of our Lovelace UI switch.
Lovelace UI Switches
Now we want to create switches that allow us to control our camera from Home Assistant. Create a file named switches.yaml
next to the main configuration.yaml
file in the .homeassistant
folder and import it into the latter switch: !include switches.yaml
. Now add the following content to the switches file:
- platform: mqtt
name: 'Alarm Area 1'
state_topic: 'instar/local/status/alarm/area1/enable'
command_topic: 'instar/local/alarm/area1/enable'
qos: 1
payload_on: '{"val":"1"}'
payload_off: '{"val":"0"}'
optimistic: false
retain: false
- platform: mqtt
name: 'Alarm Area 2'
state_topic: 'instar/local/status/alarm/area2/enable'
command_topic: 'instar/local/alarm/area2/enable'
qos: 1
payload_on: '{"val":"1"}'
payload_off: '{"val":"0"}'
optimistic: false
retain: false
- platform: mqtt
name: 'Alarm Area 3'
state_topic: 'instar/local/status/alarm/area3/enable'
command_topic: 'instar/local/alarm/area3/enable'
qos: 1
payload_on: '{"val":"1"}'
payload_off: '{"val":"0"}'
optimistic: false
retain: false
- platform: mqtt
name: 'Alarm Area 4'
state_topic: 'instar/local/status/alarm/area4/enable'
command_topic: 'instar/local/alarm/area4/enable'
qos: 1
payload_on: '{"val":"1"}'
payload_off: '{"val":"0"}'
optimistic: false
retain: false
Back on the Lovelace UI click to add a new Entity Card and as entities select the switches you just added:
switch.alarm_area1
switch.alarm_area2
switch.alarm_area3
switch.alarm_area4
Lovelace UI Push Buttons
In some cases we don’t need switches but stateless buttons, for example to manually trigger an alarm on our camera or have it move between preset positions. This can be done with a script. First create a file called scripts.yaml
and import it into the main configuration script: !include scripts.yaml
. Open this file and add the following lines:
9010_pushalarm:
sequence:
- service: mqtt.publish
data_template:
topic: instar/local/alarm/pushalarm
payload: '{"val":"1"}'
qos: 1
9010_gotopos1:
sequence:
- service: mqtt.publish
data_template:
topic: instar/local/features/ptz/preset
payload: '{"val":"0"}'
qos: 1
9010_moveright:
sequence:
- service: mqtt.publish
data_template:
topic: instar/local/features/ptz/move
payload: '{"val":"right"}'
qos: 1
9010_movestop:
sequence:
- service: mqtt.publish
data_template:
topic: instar/local/features/ptz/move
payload: '{"val":"stop"}'
qos: 1
The first one of those topics triggers an alarm on your camera, the second turns your camera into preset position 1, the third has it moving horizontally to the right and the fourth stops the movement.
Just like with the switches add another entity card to the Lovelace UI and select those scripts as entities from the drop down menu.
Automations
Please refer to the tutorial on Github for automation examples like having your camera automatically turn between a day and night position and using different motion detection areas depending on the position your camera is in.