Light, Relay & rules [solved?]

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
amigaroxx
New user
Posts: 4
Joined: 11 Jun 2018, 22:00

Light, Relay & rules [solved?]

#1 Post by amigaroxx » 31 Mar 2019, 20:18

Hi Guys,

After countless hours I can't get my head around setting the rules of something I think should be quite easy. But no luck getting it to work.

All I want to do is to switch the relay when the light gets below 3000 lux. How hard can it be?

My configuration (20103 - Mega - mega-20190315 Git build)

Relay:
Device: Switch input - Switch
Name: Relais
Enabled: Yes
Internal PullUp: Yes
Inversed Logic: NO
GPIO: 14
Switch Type: Switch
Switch Button Type: Normal Switch
Send Boot state: NO
Name: Switch

BH1750
Device: Light/Lux - BH1750
Name: Light
Enabled: YES
I2C Address: 0x23 (default)
Measurement mode: Resolution_high
Send sensor to sleep: NO
Interval: 5 [sec]
Name . Lux
Decimals . 0

Initially I tried the example from the tutorial. Pretty straight forward, but does not work. This code just switches on/off in intervals of 5 seconds (interval time of the lux)

on Light#Lux<3000 do
if [Relais#Switch]=0
GPIO,14,[Relais#Switch]
endif
Endon

Next, I tried these variants with no luck either:

on Relais#Switch do
if [Light#Lux]<3000
gpio,14,1
else
gpio,14,0
endif
endon

on Light#Lux<3000 do
if [Relais#Switch]=1
gpio,14,0
else
gpio,14,1
endif
endon

The sensor Is working. When I boot the ESP with >3000 lux, the status will change of the relay and actually switch when I remove the light source. Bringing back the light source does not turn the relay switch :(

What am I doing wrong? All help is appreciated.

Update.

While browsing this awesome forum for some other interesting topics, I found this topic. I borrowed the code, and behold it bloody works.

Code: Select all

on Light#Lux do
 if [Light#Lux] < 3000
  GPIO,14,1
  else
    GPIO,14,0
   endif
endon
This code make sense to me, but the syntax or build-up is still unclear to me. It works now.. I'm a happy camper.

Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests