Lights... I must be a bit dim

Hello. I’ve got these stupid “colour night vision” security cameras. Didn’t realize when I got them that colour night vision actually means no_night_vision_at_all_when_the_camera_mounted_led_is_off! Completely useless for indoor use. So i’ve installed them at the front and back doors of the house. At night they are configured outside of HA at 10% brightness. This is fine for surveillance. As a deterrent and to assist me find my way up the stairs at night, i’d like to integrate the led with the frigate person occupancy sensor. I’ve been messing about and have been able to replicate the relevant POST requests to set the led brightness anywhere between 0 and 100 and to retrieve the current LED value programmatically on the PI where the HA is running. Now, i’m a HA noob. I admit it. I’ve spent about a week failing to be able to implement these c programs as scripts in home assistant. I gave up trying to run them as scripts in HA but to instead run the program as a daemon and interface with mqtt. This looks promising at first, my device is discovered by HA, i can publish state changes and see HA doing the same but the entity state value is forever “unknown”… Ack… Before i got into excruciating details about my config and what done, what would you do? We can programatically affect changes to the led and retrieve it’s current status. What’s the path of least resistance here? I want to be able to set the scene when my alarmo is triggered or enable a frigate motion sensor when i walk down the stairs at night. Am I on the right track? Should I be looking at taking this in a new direction? Appreciate your advice! Cheers

I love the pun in your title :wink:

Is that necessary to use frigate or do you only want it to work when it recognises (or doesn’t recognise) a particular person?

I may have understood your requirement, but can’t you use a motion sensor (that includes lux) to trigger whether the LED is off or on (based on motion and light conditions) and be done with it?

Hi Jchh. I don’t have any other sensors apart from those provided by frigate.

agh, OK. Well if you are prepared to get another sensor, my idea could work for you.

So I got this working via script, what a headache! I’m sure that i’m doing this the wrong way, running an external program by trigger shouldn’t be this hard… That being said, HA configuration wasn’t the only problem. Beware docker. If your HA instance is in docker, then the executable that you want to call must be run from the same instance. It took me a while realize this. But even after figuring this out, i was having issues with shared libraries in the compiled code, and it just would not run! I couldnt figure out how to get my code to compile with static libraries to run in the docker instance(i need to read up on docker). Since that was not working but the code was executing on the docker host I though well why not use ssh to run it, but that didn’t work. The .ssh folder in the HA docker instance kept getting reset due to it being ephemeral - thanks docker - so i employed a dirty trick. I modified the docker configuration and mounted my .ssh folder in a separate folder on my host, this way changes are preserved and my private key doesnt keep getting deleted on reboot. Cool, now i can execute code on the host. All the remains is the HA config, no problem!

Turns out, it’s a problem. I got there in the end. This is how I did it.

Define some shellcode. Define the script to run the shellcode. Define a trigger, in my case i had luck using a boolean switch. Create scene that activates the switch. create an automation that calls the script when the switch changes to a particular state.

I then created a second automation which was a breeze. It gets triggered via a frigate camera sensor(front door person occupancy). Sets the scene below which turns on the led. Waits 2 mins. Then sets another scene to turn the led off. Whoot!

Here’s the yaml.

  frontdoorled100: ssh <user>@<ip address> /opt/homeassistant/camera_led_controls <ip address> 100

      - service: shell_command.frontdoorled100


  name: frontdoorled100
      editable: false
      friendly_name: frontdoorledswitch
      state: 'on'
      entity_only: true

  alias: fontdoorled100
  - platform: state
    entity_id: input_boolean.frontdoorledswitch
    to: 'on'
  condition: []
  - service: script.frontdoorled100
    data: {}
  mode: single

Understand this, if you are going to run code on another machine via ssh, and you done it like i done it - you’re a fool. Please secure your root private key… My HA is only available externally via VPN so i accept the risk.

What i’d like to know is - is there a better way to do this?