MotionEye, home assistant, camera motion, automation

Hey guys!
If you want a motion sensor that won’t disappear on reboot, and you don’t want the input_boolean, you can use a MQTT Binary Sensor.

binary_sensor:
  - platform: mqtt
    state_topic: "home/livingroom/camera/motion"
    name: Living Room Camera Motion
    device_class: motion

EDIT

Then on motioneye, just use the “RUN A COMMAND” with:

mosquitto_pub -h localhost -u MY_MQTT_USER -P MY_MQTT_PASSWORD -t home/livingroom/camera/motion -m "ON" -r

Just change MY_MQTT_USER and MY_MQTT_PASSWORD with your credentials

and change the payload to OFF for the RUN AN END COMMAND!

4 Likes

I’ve tried MQTT a few times and I just can not get it. I need MQTT for dummies.

Well for this you only need to install the Mosquitto broker add-on and you are good to go!

Nice one mate. New to MQTT and it was simple to add the topic to the HA. Need to test the notifications from the camera command.I suppose that should be triggered by motion eye with a real detection and I cannot test by changing the state of the motion sensor via MQTT?

Need to test it as at work. But thanks

It works mate. But the motion detection is slow to trigger. Like a minute after the actual motion occurred. Is it any motion eye settings?? Would be great if you could help

Thanks for very neat and useful steps. I’ve tried the script method. I’m using IFTTT notification method till now and along side using above command. When the camera detect any motion, I get notification from IFTTT, but not from HA, instead I get a notification in notifications section that an invalid login detected from my camera IP.

-Initially used the command as is with only TOKEN replaced by token - nothing happened.
-Later removed Authorization: Bearer TOKEN and replaced with token (just like screenshot), getting login error in HA notifications section.

I can’t understand whats wrong

You have to add trusted networks so that your login from camera isnt restricted.

Checkout trusted networks home assistant and you will find all the info.

Thanks, I’ll try that. I heard that the Hass Dev team mentioned that trusted networks option will be deprecated in next builds. Is it right?

Good morning ,
I come back to the topic , i am still a bit confused about the final configruation.
I red many solution but i would like to understand if someone can just post the passages to perform the following actions :
motioney - when a movement is detected recall hassio which has to send a push notification on the phone.
Thanks

Hello!
Start by creating an input_boolean:

input_boolean:
  stairsmotionsensor:
    initial: off

Also create a binary sensor:

binary_sensor:
  - platform: template
    sensors:
      stairsmotionsensor:
        entity_id: input_boolean.stairsmotionsensor
        device_class: motion
        value_template: '{{ is_state("input_boolean.stairsmotionsensor", "on") }}'

When you are done, open motioneye and go to your camera settings>Motion notifications and turn on both “run a command” and “run an end command”. Keep this window open and open another window with home assistant. Go to your profile (bottom left) and go to long-lived tokens at the bottom of the page. Click “Create Token”. Name it as you like, it doesnt matter and click OK. Copy the Token and dont lose it until you finish setting up Motioneye.
Now, return to Motioneye and paste this at “Run a Command”:

curl -X POST -k -H "Authorization: Bearer PASTETHETOKENHERE" -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.stairsmotionsensor"}'  https://HASSIOIP:8123/api/services/homeassistant/turn_on

Paste this for the “Run an End Command”:

curl -X POST -k -H "Authorization: Bearer PASTETHETOKENHERE" -H "Content-Type: application/json" -d '{"entity_id": "input_boolean.stairsmotionsensor"}'  https://HASSIOIP:8123/api/services/homeassistant/turn_off

Thats it. Now, as long as there is motion, you will have a “binary_sensor.stairsmotionsensor” showing the motion in your interface. You can use this sensor as a trigger for your automations too. :wink:

10 Likes

Many thanks ,
I will try this evening and i ll let you know.
I also added an automation in order to trig the push

  • alias: ‘Motion Detected’
    trigger:
    platform: state
    entity_id: device_tracker.xxx
    to: ‘not_home’
    trigger:
    platform: state
    entity_id: input_boolean.cameramotion
    to: ‘on’
    condition:
    - condition: state
    entity_id: input_boolean.cameramotion
    state: ‘off’
    action:
    service: notify.mobile_app_xxx
    data_template:
    message: “Motion detected”

I am only concerned on the underlined part if it has to be on/on or on/off

Really kind

The trigger has to be on, but remove the condition.

All good , was http to https :slight_smile:

1 Like

Interesting topic, but is there any way to send back a command to MotionEye to turn off motion sensing at the source for those who are using Hassio + rpi and are slowly killing the sdcard. I mean does the motioneye container has some API for input commands? Because silencing the already triggering Motioneye in Node red or in HA automatisation is not an elegant solution .

Thx

You could use a switch in HASS to toggle the motion sensor in motion (and not in motioneye):

  - platform: command_line
    switches:
      camera_44:
        command_on: 'curl -k "http://192.168.2.204:7999/2/detection/start"'
        command_off: 'curl -k "http://192.168.2.204:7999/2/detection/pause"'
        command_state: 'curl -s "http://192.168.2.204:7999/2/detection/status"'
        value_template: '{{ "ACTIVE" in value }}'
        friendly_name: Motion Sensor Camera 44

Explained here!

3 Likes

Thanks, mate! I’m gonna try it today!

It worked flawlessly, thank you again @PetrolHead!

Hi John, stumbled upon your answer while searching for an easy way to use my Unifi G3 within HA. Sadly MotionEye “forgets” my cam sometimes, showing me an empty/blank image. But when it works, your way is my new solution for now, so thanks a lot!

Hi,
I’ve been trying to set this up but I never receive motion within Home Assistant?

On this section:

curl -X POST -k -H “Authorization: Bearer PASTETHETOKENHERE” -H “Content-Type: application/json” -d ‘{“entity_id”: “input_boolean.stairsmotionsensor”}’ https://HASSIOIP:8123/api/services/homeassistant/turn_on

The token is literally just pasted in there yeah? no quotes, just as is? And keeping the leading [space]?
The HASSIOIP if I’m using HA Cloud, should I put the cloud address? I imagine not as all this should be happening within my network so IP should suffice?

I created the input_boolean via the automations>helper feature called: input_boolean.front_motion
And my template looks as below:

binary_sensor:
  - platform: template
    sensors:
      front_motion:
        entity_id: input_boolean.front_motion
        device_class: motion
        value_template: '{{ is_state("input_boolean.front_motion", "on") }}'

But it’s never changed from clear since I created it. (I know motion events are triggering as my google drive is filling up :sweat_smile:)
image

Think I’ll try a new long-lived access token as I keep getting notifications of failed connection attempts since I created all of this, so am wondering if I mis-copied the key.

You just replace the text PASTETHETOKENHERE with your token. spaces and quotes remain as they are.

Show me your automations and also the command_on from motioneye (remove the token if any)