TP-Link VIGI Camera Lights

Hopefully this is in the correct section.

I found the floodlight toggle switch available on my Reolink cameras incredibly useful, so I have (to some extent) implemented something similar for the VIGI cameras.

I’ve created this python script that allows controlling the white LEDs. It connects to an MQTT broker for control, and takes in a config file for the broker credentials and camera information.

An configuration file with two cameras could look as such:

{
    "mqtt_host": "10.0.0.50",
    "mqtt_username": "MQTTUN",
    "mqtt_password": "MQTTPW",
    "cameras": [
        {
            "name": "front_door",
            "ip": "10.0.0.21",
            "username": "CAMUN",
            "password": "CAMPW"
        },
        {
            "name": "driveway",
            "ip": "10.0.0.22",
            "username": "CAMUN",
            "password": "CAMPW"
        }
}

The script automatically retrieves login tokens and will re-authenticate when they expire.

For each camera specified in config.json, the script will subscribe to the topic vigi_leds/{name}/mode - publish ‘on’ on this topic to turn the white lights on, and ‘off’ (or any other string) to turn them back off. I use a few helper toggles and an automation on the HA side for this.

The script works by changing two settings on the camera - to turn the white LEDs on, it changes the illuminator mode to ‘always on’ and changes the night vision mode to ‘white light’. To turn the LEDs back off, it changes the illuminator mode back to automatic and the night vision mode back to infrared.

The script is licensed under the GPLv3, and may be redistributed or changed with attribution. I know this isn’t particularly elegant or efficient, but it works for my purposes and I hope it can be of use to others as well.

2 Likes

Since I’m currently researching Vigi cameras (especially the C540V model) and you also use a Vigi, I have a question: Since you’ve probably integrated them under HA via HA Onvif integration, can you tell me which entities (controls, sensors, etc.) are available under HA? I’m particularly interested in whether the AI/IVS functions (line, region, object removal, … detections)


are also available under HA when integrated via HA Onvif integration. Unfortunately, I can’t find any comments from other users on this.

BTW: The Vigi cameras are OEM models from Dahua, some of which have a somewhat “slimmed down” feature set, and I’ve been using only Dahua cameras and NVRs for years. When I integrate the Dahua cameras via HA Onvif integration, all of their IVS features are available. Only the human and vehicle classification for motion detection is missing, but that’s not a big deal for me since I only work with line and field detection anyway.

Example: Dahua DH-SD49225XA-HNR camera via Onvif

PS: Of course I am also familiar with the discussion here Support for TP-Link VIGI Two-Way Audio · Issue #1470 · AlexxIT/go2rtc · GitHub. :slightly_smiling_face:

Hi Jim, I must admit that I don’t consume the camera feeds directly. The feeds are consumed by frigate which re-broadcasts.

I did connect one of my C430s through ONVIF to check for you. The camera is on v2.0.3 (240529) and does not expose very much at all.

Apparently the PTZ controls are exposed through ONVIF, but I only have fixed cameras.

There’s a chance that with further poking through the undocumented API, you could get the data. Not sure it’s worth the effort with how easy Frigate is to set up or how easy it is to get cameras that give up the information easily.

1 Like

Thank you for testing this for me! :+1: OK, according to the screenshot, there aren’t really many sensors. However, with the Dahua cameras and the HA Onvif integration, the additional detection sensors only appear in HA once they’ve been triggered for the first time.

Unfortunately, there’s no current, published version of the TP Link Open API. When a user inquired about it in the TP Link forum, he was told to contact TP Link sales, who might then provide API documentation. I don’t want to go to that trouble, so I’m hoping that a few users with Vigi cameras might post their experiences with integrating it via Onvif.

The topic of what is available via Onvif for Vigi cameras is also relevant to my Dahua NVR, since the Vigi camera would then also have to be integrated via Onvif. Even though Vigi NVRs are also slimmed-down OEM models from Dahua. Nevertheless, a Vigi camera cannot be integrated directly into a Dahua NVR, but only via Onvif, and thus only the Onvif features are available there.

Edit: The fact that there’s no motion detection sensor is odd, though, because it should be there immediately and always. The IVS and line detection sensors on Dahua cameras only appear after they’ve been triggered for the first time.

Hi @yetanothercarbot , please how do you integrate this python script into HA?
Thanks.

Sadly, it’s not as straightforward as I’d really like it to be. It runs separately from Home Assistant and requires a little bit of familiarity with the CLI. It’s, in its current state, very much not batteries-included. You will need to have Python3 and pip installed on the PC you run it on.

  1. Download the source code from github
  2. In a command-line window (on Windows, replace python3 with py -3):
    1. Create a virtual environment python3 -m venv venv in the downloaded folder
    2. Activate the virtual environment: on Linux, that’s . venv/bin/activate (note the dot and space in front) and on Windows it’s .\venv\Scripts\Activate.ps1
    3. Install dependencies with pip3 install -r requirements.txt
  3. Create a config file. This describes the connection details for the MQTT broker and the details for each of the cameras it controls. The example in the top post should serve as a starting point – if you have any issues on the configuration side, let me know.
  4. Running the script…this one is a bit more interesting. I run it through pm2, which will also restart the script if it crashes. Adjust the paths for where you downloaded it, but this should get that started: pm2 start --interpreter /home/user/vigi_leds/venv/bin/python3 /home/user/vigi_leds/camera_control.py

Integration into Home Assistant is done with the mqtt.publish action. If you’ve defined a camera called “entryway”, then you can control it by publishing to the vigi_leds/entryway/mode topic. I created boolean helpers in Home Assistant, and then created an automation to push the updates to MQTT:

alias: Camera Light MQTT
description: ""
mode: single
triggers:
  - entity_id:
      - input_boolean.entryway_camera_light
    trigger: state
conditions: []
actions:
  - data:
      topic: vigi_leds/entryway/mode
      payload: "{{ states('input_boolean.entryway_camera_light') }}"
    action: mqtt.publish

(simplified to just one camera – in reality this automation propagates for all cameras)

Overall, yeah, I realise it’s not very user-friendly. It would be better to have it as a HACS integration, but I am not able to do that currently.