These notes help configure Home Assistant (HA) to use remote ssh commands to change the infrared mode of a UniFi Protect G4 Pro camera. The concepts can be used for other ssh remote commands from HA.
I am running
Home Assistant Supervised
. It is installed on a Raspbian Raspberry Pi 4 with the root volume on a USB attached SSD. I think it used to be called Hassio on generic Linux.
Note that with this installation, Home Assistant is in a container and the real path to the HA configuration is /usr/share/hassio/homeassistant
. HA processes reference the location as /config
. The remainder of this document refers to /config
meaning files have to be placed in the real path of /usr/share/hassio/homeassistant
.
Create an HA Command Line Switch
using the command_line
platform. I used a script in the command so it could easily be modified without restarting HA. I made a myscripts
directory in the HA config structure to hold my scripts.
switch: - platform: command_line switches: # set garage camera to day or night uvc_control_garage_ir: friendly_name: Garage Camera IR # on is night command_on: "/config/myscripts/uvc-control.sh night" # off is day command_off: "/config/myscripts/uvc-control.sh day"
These are the UniFi camera commands related to the infrared system. Use auto
mode for daytime and use manual
mode with an IR level setting for the night mode. Note that changes made with these commands are not reflected in the camera user interface Infrared settings.
- Set day mode
- ubnt_ipc_cli -T=ubnt_ispserver -m='{"functionName":"ChangeIspSettings", "irLedMode":"auto"}'
- Set night mode
- ubnt_ipc_cli -T=ubnt_ispserver -m='{"functionName":"ChangeIspSettings", "irLedMode":"manual"}'
- IR LED intensity 0-255, 0 turns off LEDs, use with night mode
- ubnt_ipc_cli -T=ubnt_ispserver -m='{"functionName":"ChangeIspSettings", "irLedLevel”:255}’
Prepare the systems for remote ssh commands.
-
Generate public and private ssh keys with
ssh-keygen
-
Place the private key in the HA system at
/config/.ssh/id_rsa-ha
-
Append the public key to
/etc/dropbear/authorzied_keys
in the UniFi camera. - Note: The camera key will be erased with each camera reboot.
The uvc-control.sh
script executes a command on the UniFi camera with ssh from the HA system. To coerce the ssh command to work, the public and private keys must be distributed and the quotes have to be just right.
Here are the remote ssh commands with appropriate quoting.
- Command off
- ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no "ubnt_ipc_cli -T=ubnt_ispserver -m='{\"functionName\":\"ChangeIspSettings\", \"irLedMode\":\"auto\"}' "
- Command on
- ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no "ubnt_ipc_cli -T=ubnt_ispserver -m='{\"functionName\":\"ChangeIspSettings\", \"irLedMode\”:\”manual\”}’ "
- Use this with the command on to set the IR intensity
- ssh -i /config/.ssh/id_rsa -o StrictHostKeyChecking=no "ubnt_ipc_cli -T=ubnt_ispserver -m='{\"functionName\":\"ChangeIspSettings\", \"irLedLevel\”:255}’ "
Reference:
- The UniFi infrared system configuration config json file: /var/etc/persistent/ubnt_isp.conf
- UniFi Forum Infrared Scheduling
No comments:
Post a Comment