Coder Social home page Coder Social logo

Comments (9)

williamkennyAK avatar williamkennyAK commented on July 28, 2024 1

Even better, I've found an alternate BusyBox that includes wc and nc. Using these I've created a script to post to a home assistant webhook. I'll document it a bit better and submit the code here.

from merkury1080p.

williamkennyAK avatar williamkennyAK commented on July 28, 2024 1

Here is the shell script I'm using with the included instructions you provided in Comment 2:

!#/bin/sh

#DEBUG_FILE=/mnt/mmc01/output.log
DEBUG_FILE=$1
# Define Webhook to trip
WEBHOOK="driveway_motion"
# Build the PATH to POST
POST_PATH="/api/webhook/${WEBHOOK}"
# Hostname or IP of Home Assistant
HOST=192.168.x.x
# Port Number
PORT=8123
# This can be just about anything for our purposes
BODY="Put here HTML body...."
# Get the Body Length for proper POST form data
BODY_LEN=$( echo -n "${BODY}" | /mnt/mmc01/busybox wc -c )

contains() {
    string="$1"
    substring="$2"
    if test "${string#*$substring}" != "$string"
    then
        return 0    # $substring is in $string
    else
        return 1    # $substring is not in $string
    fi
}

# contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.

IFS='$\n'
echo -n "" > $DEBUG_FILE
while true; do
read -r BUF;
if [ $? -ne 0 ]; then
    sleep 1;
    continue
fi
if contains "$BUF" "--motion detection alarm --"; then
    #echo "motion detected"
        echo -ne "POST ${POST_PATH} HTTP/1.0\r\nHost: ${HOST}\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ${BODY_LEN}\r\n\r\n${BODY}" | \
        /mnt/mmc01/busybox nc -i 3 ${HOST} ${PORT}
fi
echo $BUF >> $DEBUG_FILE
done

I then create an automation in HA that sets an input boolean and resets it to off 30 seconds later.
This then triggers my object detection using the DOODS addon and finally sends me a telegram notification.

Turn this cheap camera into a $300 object detection beast!!!

Later this week I will fork and draw up a pull request.

from merkury1080p.

williamkennyAK avatar williamkennyAK commented on July 28, 2024 1

@guino unfortunately, the included wget lacks the ability to use --method. Unless I'm unaware of some wget-fu, this was the only way I could accomplish it.

from merkury1080p.

guino avatar guino commented on July 28, 2024

@williamkennyAK curl -- I haven't seen any busybox with it. The busybox posted for the SD card ( https://github.com/guino/Merkury720/tree/main/mmc ) has wget which should be able to do web requests similar to curl. This link also has relevant Home Assistant information: https://github.com/guino/BazzDoorbell/wiki/How-do-I-integrate-with-Home-Assistant,-HomeBridge,-Domoticz,-etc

from merkury1080p.

williamkennyAK avatar williamkennyAK commented on July 28, 2024

I ended up going a slightly different route. I used the ffmpeg camera integration with the ffmpeg_motion integration to trigger a motion event.
https://www.home-assistant.io/integrations/ffmpeg_motion/

from merkury1080p.

guino avatar guino commented on July 28, 2024

@williamkennyAK you should have been able to use the existing busybox (wget) to perform the post, but as long as it works it doesn't hurt to have more options -- can you post a zip or link of the busybox you used (that works with the script) ?

EDIT: Nevermind - the busybox we've been using has nc so this should work as-is.

from merkury1080p.

guino avatar guino commented on July 28, 2024

@williamkennyAK that makes sense, I did not notice the wget in busybox was not POST capable. It's odd that homeassistant doesn't allow for 'GET' requests like domoticz, homebridge, etc -- in any case I assume you could also have used mqtt with the mosquito_pub tool provided in the link of the 2nd post above.

Like I said, always nice to have more options.

from merkury1080p.

williamkennyAK avatar williamkennyAK commented on July 28, 2024

V2:

This is a work in progress but here we go:

#!/bin/sh
# notify.sh
# [email protected]
# GitHub: williamkennyAK
#
# Parses ppsapp logs for keyword to trigger local motion notifications
# Generates motion alerts from tuya linux based cameras
# ADD LINK TO REPOS...
#
# usage:
#
# /mnt/mmc01/ppsapp | /mnt/mmc01/notify.sh <keyword> <worker> <logfile> <loglevel>
# * denotes required
# * keyword       - keyword to look for in ppsapp logs
# * worker        - script or binary that executes notifications
# * logdir        - /full/path/to/log/dir
# * loglevel      - 0: silent
#                   1: motion detected only
#                   2: motion detected and worker output
#                   3: EVERYTHING ** use this sparingly as it can build up quickly **
#                      It's main use is to figure out the keyword to use
keyword=$1
worker=$2
workerlog="$3/worker.log"
log="$3/notify.log"
loglevel=$4
while true; do
    read -r BUF;
    case "$BUF" in
        *"${keyword}"*)
            case $loglevel in
                "1")
                    echo "############# MOTION DETECTED #############" >> $log
                    $worker
                    ;;
                "2"|"3")
                    echo "############# MOTION DETECTED #############" >> $log
                    echo "############## WORKER LOGGED ##############" >> $log
                    $worker >> $workerlog
                    ;;
            esac
            ;;
    esac
    case "$loglevel" in
        "3")
            echo "${BUF}" >> $log
            ;;
    esac
done

I then modify custom.sh with this line:

  /mnt/mmc01/ppsapp | /mnt/mmc01/notify motion /mnt/mmc01/post.sh /mnt/mmc01/logs 2 &

With this script you could then use the mosquitto_pub method with this script giving you a bit more control.

My ppsapp denoted a motion trigger in the following way:

[13:17:26.813 INFO pps_tuya_media.c:1808]motion detected upload pic
[13:17:32.874 INFO pps_tuya_media.c:1788]motion detected but in shield time
[13:17:43.041 INFO pps_tuya_media.c:1788]motion detected but in shield time

from merkury1080p.

williamkennyAK avatar williamkennyAK commented on July 28, 2024

Submitted pull request with changes made including web interface for configuration.

from merkury1080p.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.