Ubiquiti UniFi G3 as motion detector

Does anybody know if the Ubiquiti UniFi G3 can be used as a motion detector? This would be very convenient as I don’t have to put up cables for additional motion detectors.

If not, my plan is to use the Aeotec multi sensor 6. How would you wire this one as it uses usb?

i fount solution in google (dont remember site)
i ran script.sh on unifi server:

#!/bin/bash

Unifi Video Vars

UNIFI_MOTION_LOG=/var/log/unifi-video/motion.log

MQTT Vars

MQTT_SERVER=“IP##########”
MQTT_TOPIC_BASE=“camera/motion”

MQTT User/Pass Vars, only use if needed

MQTT_USER="#############"
MQTT_PASS="##############"

Camera Defs

CAM1_NAME="##############"
CAM1_ID="################3"

------------------------------------------------------------------------------ –

Script starts here

if [[ -n “$MQTT_USER” && -n “$MQTT_PASS” ]]; then
$MQTT_USER_PASS="-u $MQTT_USER -P $MQTT_PASS"
else
$MQTT_USER_PASS=""
fi

while inotifywait -e modify $UNIFI_MOTION_LOG; do
LAST_MESSAGE=tail -n1 $UNIFI_MOTION_LOG
LAST_CAM=echo $LAST_MESSAGE | awk -F '[][]' '{print $2}'
LAST_EVENT=echo $LAST_MESSAGE | cut -d ':' -f 5 | cut -d ' ' -f 1

if echo $LAST_CAM | grep -n1 $CAM1_ID; then
# Camera 1 triggered
if [[ $LAST_EVENT == “start” ]]; then
echo “Motion started on $CAM1_NAME”
mosquitto_pub -h $MQTT_SERVER $MQTT_USER_PASS -r -t $MQTT_TOPIC_BASE /$CAM1_NAME -m “ON” &
else
echo “Motion stopped on $CAM1_NAME”
mosquitto_pub -h $MQTT_SERVER $MQTT_USER_PASS -r -t $MQTT_TOPIC_BASE /$CAM1_NAME -m “OFF” &
fi
fi
done

#################
i see sensor:
[sensor.template_pir_motion_camera1]

#################
sensors.yaml

  • platform: template
    sensors:
    template_pir_motion_camera1:
    friendly_name: ‘Camera motion’
    value_template: >
    {%- set pirs = [states.sensor.camera1_ruch] %}
    {% for pir in pirs %}
    {% if as_timestamp(pir.last_changed) == as_timestamp(pirs | map(attribute=‘last_changed’) | max) %}
    {{pir.last_changed.astimezone(now().tzinfo).strftime(’%-H:%M’)}}
    {% endif %}
    {% endfor %}

then i can see motion in HA:

obraz

i found:

1 Like

Thanks!

Do you find this solution stable and fast like a pir?

for me works stable.

its is possible to have on one view name of sensor and bottom time of last move like here:
obraz

how do this, name of sensor and bottom last activity?

I am having trouble getting this working… my config is as follows

binary_sensors:
- platform: mqtt
  state_topic: "homeassistant/camera/motion/front_door"
  name: "front_door_camera_motion"
  friendly_name: "Front Door Camera Motion"
  payload_on: 'ON'
  payload_off: 'OFF'
  value_template: >
    {%- set pirs = [states.binary_sensor.front_door_camera_motion] %}
    {% for pir in pirs %}
      {% if as_timestamp(pir.last_changed) == as_timestamp(pirs | map(attribute='last_changed') | max) %}
        {{pir.last_changed.astimezone(now().tzinfo).strftime('%m/%d @ %-H:%M')}}
      {% endif %}
    {% endfor %}
  device_class: motion
  qos: 0

and its not clear to me what I would put in groups.yaml after this to get last movement…

Can someone show me the entire config to get this working ?

device_class: motion
no supported from 87 version, any idea how to tun this?

Is parsing the log still the only way to get HASS to know there has been motion on the UniFi cameras?

When @balloob started to work for Ubiquiti I hoped for a fully integrated solution but now that cooperation is over. Anyone knows if the situation is the same with UniFi Protect and the new Cloud Gen2+ ?

1 Like