Page 1 of 1

LED, LDR and timer using Rules

Posted: 05 Dec 2018, 05:18
by whatsupskip
I really thought I would be able to get this to work, but apparently not.

I am not sure if I am supposed to use a virtual switch.

Idea: LDR measures light level. If light level is < 600 turn on LED and start a 5 second timer.
After 5 seconds turn off the LED.
If the light level is > 600 turn off the LED.

Here is what I have tried, but it doesn't work.

Code: Select all

on LDR#LightLevel<600 do
     timerSet,1,5
     gpio,0,1
 endon

 on Rules#Timer=1 do
     gpio,0,0
 endon

 on LDR#LightLevel>600 do
     gpio,0,0
 endon
Any help would be appreciated.

Re: LED, LDR and timer using Rules

Posted: 05 Dec 2018, 07:04
by grovkillen

Code: Select all

on LDR#LightLevel do
  if [LDR#LightLevel]<600
     LongPulse,12,1
  else
     GPIO,12,0. //shouldn't be needed but just in case.
  endif
endon
If the timer is only used for pulsing the LED pin I'd use LongPulse command instead. GPIO 0 have an internal pull up so you might find it not suitable for what you're trying to do. That is why I use GPIO 12 in the example above.

Re: LED, LDR and timer using Rules

Posted: 05 Dec 2018, 09:23
by toffel969
whatsupskip wrote: 05 Dec 2018, 05:18 I really thought I would be able to get this to work, but apparently not.

I am not sure if I am supposed to use a virtual switch.

Idea: LDR measures light level. If light level is < 600 turn on LED and start a 5 second timer.
After 5 seconds turn off the LED.
If the light level is > 600 turn off the LED.

Here is what I have tried, but it doesn't work.

Code: Select all

on LDR#LightLevel<600 do
     timerSet,1,5
     gpio,0,1
 endon

 on Rules#Timer=1 do
     gpio,0,0
 endon

 on LDR#LightLevel>600 do
     gpio,0,0
 endon
Any help would be appreciated.
Hi

What is the delay setting on the LDR device ? Does the LED get the light level above 600 ?