rpi-appliance-monitor icon indicating copy to clipboard operation
rpi-appliance-monitor copied to clipboard

Possible to swap LDR sensor module?

Open tstack77 opened this issue 7 years ago • 11 comments

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

tstack77 avatar May 01 '17 03:05 tstack77

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:

  • Trigger "appliance turned on" if the sensor has switched from "off" to "on" during every second, for the last x seconds.
  • Trigger "appliance turned off" if the sensor has not switched from "off" to "on" during any second, for the last x seconds.

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

  • Trigger "appliance turned on" if the sensor has experienced the "on" state during every second, for the last x seconds.
  • Trigger "appliance turned off" if the sensor has not experienced the "on" state during any second, for the last x seconds.

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

Shmoopty

Shmoopty avatar May 01 '17 17:05 Shmoopty

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.

tstack77 avatar May 01 '17 21:05 tstack77

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!

Shmoopty avatar May 08 '17 03:05 Shmoopty

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 avatar May 08 '17 22:05 tstack77

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

tstack77 avatar May 16 '17 01:05 tstack77

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

Shmoopty avatar May 16 '17 03:05 Shmoopty

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

tstack77 avatar May 16 '17 16:05 tstack77

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.

Shmoopty avatar May 18 '17 13:05 Shmoopty

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.

tstack77 avatar May 19 '17 02:05 tstack77

@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.

HIT2022 avatar Jan 03 '20 21:01 HIT2022

@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

tstack77 avatar Jan 05 '20 03:01 tstack77