Last active
January 5, 2026 04:49
-
-
Save auxesis/7efbfeb9671d023abe3a080cb5338e94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # ## Setup | |
| # | |
| # Install hueadm: | |
| # | |
| # ```bash | |
| # npm install -g hueadm | |
| # ``` | |
| # | |
| # Discover available bridges: | |
| # | |
| # ```bash | |
| # hueadm discover | |
| # ``` | |
| # | |
| # Record the IP address of the bridge. | |
| # In the following example, we use 192.168.1.20 as the IP address of the bridge. | |
| # | |
| # Register a new user: | |
| # | |
| # ``` | |
| # hueadm -H 192.168.1.20 register $(whoami) | |
| # ``` | |
| # | |
| # Take the above output from `hueadm`, and add to config file: | |
| # | |
| # echo '{"user":"12aosnt4123stGH12DAoeSNa2-arhjGAo4Heao", "host": "192.168.88.250" }' > ~/.hueadm.json | |
| # | |
| HOME_NETWORK_NAME="INSERT YOUR NETWORK NAME HERE" | |
| HOME_PUBLIC_IP="xxx.xxx.xxx.xxx" | |
| currentPublicIP=$(curl -s -4 https://ifconfig.me) | |
| LIGHT_ID=1 # get from running: hueadm lights -l | |
| function currentWifiNetworkName() { | |
| /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk -F: '($1 ~ "^ *SSID$"){print $2}' | cut -c 2- | |
| } | |
| notAtHome () { | |
| if [ $currentPublicIP != "${HOME_PUBLIC_IP}" ]; then | |
| return 0 | |
| fi | |
| return 1 | |
| } | |
| cleanup () { | |
| hueadm light ${LIGHT_ID} yellow bri=220 > /dev/null | |
| exit | |
| } | |
| camera_on_action () { | |
| echo "$(date | tr -d '\n'): Camera On: changing light to red" | |
| hueadm light ${LIGHT_ID} 'red' bri=220 > /dev/null | |
| } | |
| camera_off_action () { | |
| echo "$(date | tr -d '\n'): Camera Off: changing light to green" | |
| hueadm light ${LIGHT_ID} 'green' bri=220 > /dev/null | |
| } | |
| if notAtHome ; then | |
| echo "Not at home, so not changing lights." | |
| else | |
| hueadm light ${LIGHT_ID} 'purple' bri=220 > /dev/null | |
| fi | |
| trap cleanup EXIT | |
| # First boot | |
| last_camera_state="$(log show --last 24h --predicate 'subsystem contains "com.apple.UVCExtension" and composedMessage contains "Post PowerLog"' | grep VDCAssistant_Power_State | tail -n 1 | awk '{ $2 ; gsub(/;$/,"") ; print $3}')" | |
| case $last_camera_state in | |
| On) | |
| camera_on_action | |
| ;; | |
| Off) | |
| camera_off_action | |
| ;; | |
| *) | |
| echo "Should not have reached here!" | |
| exit 1 | |
| ;; | |
| esac | |
| # The loop | |
| log stream --predicate 'subsystem contains "com.apple.UVCExtension" and composedMessage contains "Post PowerLog"' | | |
| while read event; do | |
| power_state=$(echo $event | grep VDCAssistant_Power_State) | |
| if [ -n "$power_state" ]; then | |
| if notAtHome ; then | |
| echo "Not at home, so not changing lights." | |
| continue | |
| fi | |
| hour=$(date +%k) | |
| if [[ $hour -lt 7 ]]; then | |
| echo "Not working, so not changing the lights." | |
| continue | |
| fi | |
| state="$(echo $power_state | awk '{ $2 ; gsub(/;$/,"") ; print $3}')" | |
| case $state in | |
| On) | |
| camera_on_action | |
| ;; | |
| Off) | |
| camera_off_action | |
| ;; | |
| *) | |
| echo "Should not have reached here!" | |
| exit 1 | |
| ;; | |
| esac | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment