MotionEye, home assistant, camera motion, automation

Hmmm that didn’t work either…
…maybe my issue is coming from the text input into motioneyeos’s webhook input…?

here’s what have:
http://192.168.1.XX:8123/api/services/script/camdetecon?api_password=My_Password

HTTP Method: POST (query)

input_boolean.yaml
cameramotion:
initial: off

scripts.yaml
camdetecon:
alias: booleanopen
sequence:

  • service: input_boolean.turn_on
    entity_id: input_boolean.cameramotion
  • delay: 00:00:10
  • service: input_boolean.turn_off
    entity_id: input_boolean.cameramotion

am I forgetting something?

thanks for your help!

It looks ok to me. One question. You have a file named input_boolean.yaml?
If yes, then you need to define this file in the configuration.yaml, right?
Also, use three back-ticks ` to have the correct formatting.
do it like this:

input_boolean:
  cameramotion:
    initial: off

io

So please post your configuration with the correct formatting to see what is wrong. Also show me the part where you setup the input_boolean in the configuration.yaml file.
The setup I posted, should work…

Did you make any progress? does it work?

im surprised you couldnt get it to work with my configuration its easy. I would also check motioneye settings to see if it registers motion, if not play with the motion settings such as mask and motion gap etc. If you have everything configured with mqtt how mine is shown, you wouldnt use a webhook. Also with mine the password is just letters and numbers no fancy characters. if you need help with my setup let me know ill walk you through it. i had it setup to show the cams on home assistant but i no longer use that since i just view it from motioneye browser gui.

Yeah I gave up given my luck…
I would appreciate a detailed walkthrough.
Thanks for doing this!

Update

Authetication: Bearer YOUR TOKEN
to create token visit general settings in home assistant and scroll to bottom of page

Hassbian

First create camera in motioneyeos, once it is visible and motion is enabled copy and paste these commands into the area shown in image below:
curl
commands:`
ON

curl -X POST -H “Authetication: Bearer YOUR TOKEN” \ -H “Content-Type: application/json” \ -d ‘{“state”: “on”, “attributes”: {“friendly_name”: “upstairscam”}}’ \ http://remoteiptohomeassistant:8123/api/states/binary_sensor.upstairscam

OFF

curl -X POST -H “Authetication: Bearer YOUR TOKEN” \ -H “Content-Type: application/json” \ -d ‘{“state”: “off”, “attributes”: {“friendly_name”: “upstairscam”}}’ \ http://remoteiptohomeassistant:8123/api/states/binary_sensor.upstairscam

NO SPECIAL CHARACTERS FOR PASSWORD ONLY UPPER AND LOWER CASE LETTERS ALONG WITH NUMBERS FOR EXAMPLE:
HAssBian101

create this in your hassbian homeassistant configuration.yaml
sudo su -s /bin/bash homeassistant
cd /home/homeassistant/.homeassistant
nano configuration.yaml
binary

TO CREATE YOUR OWN JUST CHANGE THE NAME IN THE FRIENDLY NAME TO THE SAME NAME YOU USE AS YOUR BINARY SENSOR along with camera name in motioneyeos as state topic..

you should now see this after restarting homeassistant:
home

Now add automation

7 Likes

hopefully that helps

how did u configure the motion trigger? I detects like ghost motion all the time :frowning:

i think you change the minimum motion frames.

Hey, @argykaraz

Thank you so much for the idea of using my favourite Home Automation platform and my least disliked CCTV Framework (liked would be an overstatement). I had never thought of using them together but here’s what I’ve done with your idea…

I have set the ‘command’ to:

    mosquitto_pub -h 192.168.0.3 -t cameras/motion/pats -u john -P mypassword -m ON

and my ‘end command’ to:

    mosquitto_pub -h 192.168.0.3 -t cameras/motion/pats -u john -P mypassword -m OFF

Screenshot%20from%202018-05-03%2019-55-25

I am not a fan of putting my password in things ie putting my mosquitto password in motioneye but needs must (a program that stores it’s own admin passwords etc in plain text).

In Home Assistant I have some binary_sensors set up eg

    platform: mqtt
    name: "motion (drive)"
    state_topic: "cameras/motion/drive"
    payload_on: "ON"
    payload_off: "OFF"
    device_class: "motion"

That obviously controls the binary_sensor and sets it up as a motion detector.
Screenshot%20from%202018-05-03%2019-13-39

After that was done I changed my image settings in Motioneye to make sure that it was creating an image when motion was detected.
Screenshot%20from%202018-05-03%2019-58-18

I then turn to Node-RED to do some jiggery-pokery. In Node-RED I now have this…

which is:

[{"id":"a44c8cc5.3106c","type":"mqtt in","z":"839343ea.c64e3","name":"Drive Camera","topic":"cameras/motion/drive","qos":"2","broker":"2c553bf7.b54c64","x":100,"y":100,"wires":[["351a3f7.b860ec"]]},{"id":"351a3f7.b860ec","type":"switch","z":"839343ea.c64e3","name":"Motion ON or OFF","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"},{"t":"eq","v":"OFF","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":100,"wires":[["963127ea.8d9638"],["cd591b63.543c88"]]},{"id":"cd591b63.543c88","type":"exec","z":"839343ea.c64e3","command":"find /CCTV/Drive -type f -iname '*.thumb' -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f 2- | tail -n 1","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Get the final video thumbnail","x":580,"y":140,"wires":[["48645b4c.3d1714"],[],[]]},{"id":"1410272c.30db59","type":"fs-ops-copy","z":"839343ea.c64e3","name":"Copy to the HA dir","sourcePath":"","sourcePathType":"str","sourceFilename":"payload","sourceFilenameType":"msg","destPath":"/home/john/.homeassistant/www/assets/images/cctv","destPathType":"str","destFilename":"drive.jpg","destFilenameType":"str","link":false,"overwrite":true,"x":1200,"y":80,"wires":[[]]},{"id":"963127ea.8d9638","type":"exec","z":"839343ea.c64e3","command":"find /CCTV/Drive -type f -iname '*.jpg' -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f 2- | tail -n 1","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Get the initial image","x":550,"y":60,"wires":[["48645b4c.3d1714"],[],[]]},{"id":"48645b4c.3d1714","type":"string","z":"839343ea.c64e3","name":"Get rid of the trailing newline","methods":[{"name":"trim","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":910,"y":80,"wires":[["1410272c.30db59"]]},{"id":"2c553bf7.b54c64","type":"mqtt-broker","z":"","name":"Main","broker":"192.168.0.3","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

Let me know if need any help with the modules required etc.

So, that then copies the initial image to the www subdir of the HA filesystem and then the final thumbnail once the motion event has finished.

That means that I can then create a camera in HA with…

    platform: local_file
    name: "drive_motion"
    file_path: "/home/homeassistant/.homeassistant/www/assets/images/cctv/drive.jpg"

What does that mean?

It basically means that I can delete the 5 or 6 cameras that I have on my HA overview and replace them with the up to date image. This should save on quite a few resources.

Watch out for a new video on this

Because of the advantages of this over having 5-6 cameras using the traditional method. I am pretty sure I will be doing a video on this on the HASSCASTS YouTube Channel tomorrow.
http://YouTube.com/hasscasts

OK: So if anybody has any questions about this then please don’t hesitate to give me a shout :slight_smile:
John

27 Likes

i think you have your password posted on the off topic…

Thanks very much for pointing that out. What a moron! I can’t believe I changed it in the first one and not the second one :-/

I will now change my password but luckily I don’t have external access anyway; all my ports are closed etc :slight_smile:

Thanks again for pointing it out, it is very much appreciated.
John

1 Like

Wow! Very detailed and informative. I am glad I gave you that push you needed. Great job, but I am not using mqtt. It will sure be helpful for someone else!

Hi @HassCasts
I was working through your solution and when I open my motioneye notifications section I only have one field for “Run a command” and can’t figure out how to get the “Run an End command” field to show up. Is there a trick to getting the second field to show up? Thanks for any help you might be able to provide.

Nevermind @HassCasts I found my problem, I’m running Motioneye in Docker and must have pulled down an older version. I grabbed another version and it has both fields available. Now to get this all working :smiley:

thank you very much for this guide. small question. Im running mosquitto in docker.
how do I run the command in docker as my base os doesnt have mosquitto.

Ok, so the Motioneye ccrisan/motioneye:dev-amd64 docker image does not have the mosquitto client. So this (straight mqtt) method wont work on docker yet.

@sycohexor method does work.

Thanks for your input on this. I have created both an input_boolean and a script to fire (and reset) the innput_boolean under hass.io 0.73.0 and I can test both successfullly using the following API calls using POSTMAN in Chrome without API passwords. I do have any internal calls whitelisted though under my HTTP configuration (trusted_networks:)

http://10.0.x.x:8123/api/services/input_boolean/turn_on?entity_id=input_boolean.motion_entrance (works)

http://10.0.x.x:8123/api/services/script/trigger_ss_entrance_boolean (works)

I’m trying to call mine from Synology Surveillance Station however and this is not working despite the forum chatter saying that the Synology action rule wizard defaults to sending POST requests. More head scratching required :slight_smile:

Been a long time since I made this post. I am more into HA than ever and you guys contributed to that. Thank you very much.

I have one more question for you guys.
I changed my setup to use SSL, and the webhook is not working. I changed my webhook to use https but the script is not triggering. The obvious reason (i am just guessing here) is that motioneye cant accept the self singed certificate.
Any thoughts on this?

Are you using the motioneye addon? Can’t get mine to publish mqtt

MQTT is not supported by default…apparently he has custom setup with mqtt