Wemo Motion

Moderator: leecollings

Post Reply
D5120
Posts: 4
Joined: Friday 29 July 2016 15:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Contact:

Wemo Motion

Post by D5120 »

Hi, new to the forum, and fairly new to Domoticz.

I have the majority of my home automation set up and working, including Harmony Remotes, Phillips Hue lights, Netatmo weather sensors, and a number of dummy devices doing a lot of cool stuff.

I'm really struggling with the final piece of the jigsaw, and wondered if somebody could offer some assistance.

Using the Wemo shell script from the Wiki, I'm able to control all my Wemo sockets, which is cool.

Additionally on my network, I have Wemo Motion detector. The suggestion the Wiki is to use ouimeaux. Due to the amount of devices on my network, ouimeaux runs dog slow, and times out before seeing all my Wemo devices, so I've gone back to the shell script.

So, this is my logic

I've created a number of shell scripts (I know I could have done most of it in one script, however I was testing each bit as I went)

wemo_motion_main.sh
Calls a shell scripts that gets the state, and calls another script if motion detected, if not, exit

Code: Select all

#!/bin/bash

status(){
doit=$(/home/pi/domoticz/scripts/wemo/wemo_motion_state.sh)
}

status
echo $doit

if [ "$doit"  = "ON" ]
then 
echo "Motion Detected"
/home/pi/domoticz/scripts/wemo/wemo_motion_update.sh
else 
echo "No Motion Detected"
fi
wemo_motion_state.sh
Simply get the state of the motion detector, ON or OFF

Code: Select all

#!/bin/sh
/home/pi/domoticz/scripts/wemo/wemo_control.sh 10.0.51.183 GETSTATE

wemo_motion_update.sh
Makes the call to Domoticz to switch on and off the switch

Code: Select all

#!/bin/sh
curl "http://xxx:[email protected]:8084/json.htm?type=command&param=switchlight&idx=255&switchcmd=On"
sleep 2 
curl "http://xxx:[email protected]:8084/json.htm?type=command&param=switchlight&idx=255&switchcmd=Off"
wemo_motion_loop.sh
Simple script to loop every 5 seconds(ish)

Code: Select all

#!/bin/sh
max=11
for i in `seq 1 $max`
do
    echo "$i"
now=$(date +"%T")
echo $now
./wemo_motion_main.sh
sleep 5
done
Now running wemo_motion_loop.sh from the command line works...if I dance around in front of the motion sensor for at least 5 seconds, motion is detected, and the status of the dummy switch gets updated.

So I thought, simple...add a cron job, to run every minute, call wemo_motion_loop.sh and we're sorted.

Code: Select all

*/1 * * * * /home/pi/domoticz/scripts/wemo/wemo_motion_loop.sh
When I run under cron, the script doesn't work.

I guess I'm being a muppet, and missed something obvious...

Thanks in advance.
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Wemo Motion

Post by ben53252642 »

Don't use cron, use screen

/usr/bin/screen -S WemoMotionMonitor -d -m /home/pi/domoticz/scripts/wemo/wemo_motion_loop.sh

It will run constantly in the background, you can view it by typing screen -x getting the screen session then typing screen -x NAMEOFTHESESSION

You might want to add that into startup so it runs on boot once you have everything setup right.

This may be of interest:
https://github.com/unrelatedlabs/java-wemo-bridge

Also I see no reason why not to try 1 or 2 seconds. :D
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
D5120
Posts: 4
Joined: Friday 29 July 2016 15:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Contact:

Re: Wemo Motion

Post by D5120 »

Interesting, thanks very much Ben, I'll give them a blast :)
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Wemo Motion

Post by ben53252642 »

I forgot, to detach from a screen session use cntrl a d (press the 3 buttons on the keyboard).

Think of screen like multiple "windows" for linux terminal, those windows remain running even if you disconnect from the terminal session. It's a good way to run programs in the background and on boot.

I have a lot of screen sessions used in this way.
screen 5.png
screen 5.png (29.03 KiB) Viewed 1028 times
If I wanted to connect to the KettleBridge session the command I'd use would be: screen -x 13950.KettleBridge

to disconnect back to the main terminal I'd use cntrl a d
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest