Shmoopty / rpi-appliance-monitor

Device to monitor appliances that vibrate, such as clothes dryers or garage door openers
MIT License
416 stars 64 forks source link

Possible to swap LDR sensor module? #13

Open tstack77 opened 7 years ago

tstack77 commented 7 years ago

Thanks for this! I have this built and it definitely works, but I'm still getting false alarms after lots of adjustments to both the ini and the board sensitivity. My washer has a bunch of different modes (autosoak etc) that makes measuring the vibration a bit hit or miss. I would love to use an LDR sensor module and sugru the sensor over the power led on my machines. It seems that I wouldn't need to do anything hardware wise, but I'm a bit unsure about the differences to the python script. I'm not finding a lot of documentation on the 801s, does it simply give a true/false digital reading to the rpi, or is the output not binary?

Thanks again

Shmoopty commented 7 years ago

That is a really interesting idea... I like it.

The hardware you link to should work. Same as with the 801s in my photographs, you'll want to use the DO pin and ignore the AO pin.

You're correct that the 801s gives a binary true/false output, although it turns on and then off with every wiggle. Because of that, some minor changes to the python script would be needed. I think it would be easy for me to modify the script so it would work with either a vibration sensor or a light sensor.

Here's the current logic:

The python script should be able to handle both vibration and light sensors if the logic were changed to:

If you let me know that you've ordered that part, I'll revise the script for you. Deal?

Shmoopty

tstack77 commented 7 years ago

Deal!

I ordered a 4-pack of the sensors last night. Figured worst case I would try my hand at actually learning python (and by learning I mean hacking up your script).

The logic is exactly what I was thinking too, figured it was close enough to your original script to attempt modification.

Shmoopty commented 7 years ago

Update -

I've modified the script. It still works with sensors that turn on and off frequently during an appliance cycle, but it should also work if the sensor stays on, like an operational light sensor would.

Do me a favor, please? Let me know if this script works for your light sensor project? Good luck!

tstack77 commented 7 years ago

Will do! I ordered the sensors from China ($2 for 4 including shipping) and expect them around the 20th. I'll update with some pics.

Thanks again for the modification

tstack77 commented 7 years ago

Good news, the LDR sensor works perfectly for triggering light from an led! I didn't even need sugru to create a light shroud, simpy used 1mm thick 3m double sided tape. Bad news, endless stream of notifications sent when the cycle is finished.

My settings: sensor_pin = 23 seconds_to_start = 20 seconds_to_end = 10 end_message =Dryer Completed Notifications sent via ifttt.

ldr2 ldr1

Shmoopty commented 7 years ago

I'll take a look at the code and see if something smells funny. Thanks for getting back.

tstack77 commented 7 years ago

Thanks Shmoopty, I really appreciate you looking into this.

Over the past few days I've been trying on my own to add Pushover support to your script, but my python skills are proving to be quite insufficient. I've tried the below additions but it's still not firing. I hate to ask for any more of your time but I'm hoping there's something obvious that you can see and I'm missing.

Added to vibration.py: From https://pushover.net/faq#library:

def pushover(msg):
    try:
        import httplib, urllib
        conn = httplib.HTTPSConnection("api.pushover.net:443")
        conn.request("POST", "/1/messages.json",
          urllib.urlencode({
            "token": "pushover_app_token",
            "user": "pushover_user_key",
            "message": "msg",
            "device": "pushover_device",
          }), { "Content-type": "application/x-www-form-urlencoded" })
        conn.getresponse()
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        pass
        if len(pushover_app_token) > 0:
            pushover(pushover_app_token, message)

pushover_app_token = config.get('pushover', 'APP_TOKEN')
pushover_user_key = config.get('pushover', 'USER_KEY')
pushover_device = config.get('pushover', 'DEVICE')

Added to vibration_settings.ini:

[pushover]
app_token = ##########
user_key = ##########
device = Galaxy
Shmoopty commented 7 years ago

Regarding "endless stream of notifications", which notifications are they? Start, end or both?

Are they really endless, or do they stop eventually?

Fork this project with your pushover mods and I think I'll have time to take a look. Then you'll get credit in the project too.

tstack77 commented 7 years ago

Project forked and modified script uploaded.

I never really tested if the end-notifications ever stopped on their own. I could try to run it in a terminal without sending the notification if an answer isn't apparent from the uploaded script.

HIT2022 commented 4 years ago

@tstack77 Were you able to get past the endless notifications? My washer is giving me a similar level of difficulty so I'm considering the LDR switch.

tstack77 commented 4 years ago

@tstack77 Were you able to get past the endless notifications? My washer is giving me a similar level of difficulty so I'm considering the LDR switch.

I was, but it took a bit of a rewrite and I can't remember exactly the solve (two years ago and such). The LDR sensor approach has been rock solid and it's been run since without issue. If you have a light on your machines I definitely recommend it.

Edit: I did end up making a sugru cover over the sensor to stop any random light source triggering a notification. Give it a go and I'll respond if you run into issues