LED, LDR and timer using Rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
whatsupskip
Normal user
Posts: 125
Joined: 28 Feb 2018, 07:40
Location: Melbourne, Australia

LED, LDR and timer using Rules

#1 Post by whatsupskip » 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.
Friends with kangaroos and some time koala rescuer.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: LED, LDR and timer using Rules

#2 Post by grovkillen » 05 Dec 2018, 07:04

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: LED, LDR and timer using Rules

#3 Post by toffel969 » 05 Dec 2018, 09:23

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 ?
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests