seeking a rule daytime light curve on aquarium

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
noxin
New user
Posts: 4
Joined: 28 Dec 2023, 12:44

seeking a rule daytime light curve on aquarium

#1 Post by noxin » 20 Feb 2024, 11:09

dear forum,

I use an ESP32 together with an IRF520 module to control the LED strip above my aquarium and i was able to figure out how this works with a rule.
Now I would like to slowly increase the brightness in the morning and slowly reduce it in the evening like sunrise and sunset.
I'm not looking for a complicated light curve, a linear curve is sufficient.
Despite researching in the local forum, I didn't find anything suitable rule, which may also be due to the language barrier.
I would be grateful for a good tip.
( i had to use the g**g**-translator for this post)

regards
noxin

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: seeking a rule daytime light curve on aquarium

#2 Post by TD-er » 20 Feb 2024, 11:33

Have you looked at the sysvars page? (tools->System Variables button)

On there you can see %sunset% and %sunrise%, but also variants like %sunset-1h% and %sunrise+10m%
N.B. for correct sunset/sunrise times, it is important you have your DST & timezone and your GPS position set on the Tools->Advanced page. (and NTP checkbox checked of course)

Let's assume you need to start your "fade on" at %sunrise-15m% and want to fade on for 30 minutes.

Code: Select all

on Clock#Time=All,%sunrise-15m% do
  // ...
  // See: https://espeasy.readthedocs.io/en/latest/Rules/Rules.html#system-events
endon
I guess one step up per minute is good enough, so you can use the looptimer for a fixed amount of calls like this:

Code: Select all

on Clock#Time=All,%sunrise-15m% do
  looptimerset,1,60,30 // Set timer #1 with 60 sec interval for 30 loops
endon
See: https://espeasy.readthedocs.io/en/lates ... oop-timers

Then you need to handle this timer:

Code: Select all

On Rules#Timer=1 do
  //  The 2nd eventvalue (%eventvalue2%) is the count of the current loop.
  // Compute the dim value based on the current loop count
  // Max dim value = 1023, 30 steps, so each step is 34.
  // See: https://espeasy.readthedocs.io/en/latest/Plugin/P000.html#internal-gpio
  let,1,%eventvalue2%*34
  pwm,2,[int#1] // Set GPIO pin 2 to the computed PWM value
endon
Edit:
When using an translator to read this, please do not translate the example rules I gave you as it may also translate rules commands which cannot be processed by ESPEasy.

noxin
New user
Posts: 4
Joined: 28 Dec 2023, 12:44

Re: seeking a rule daytime light curve on aquarium

#3 Post by noxin » 20 Feb 2024, 12:29

hello TDer,

this answer was writen very fast, many thanks for it !
I have set a NTP-service, i will now set dist, timezone and gps-pos.
i will now have to create the correct rule-set, but im confident to get it !

regards
noxin

noxin
New user
Posts: 4
Joined: 28 Dec 2023, 12:44

Re: seeking a rule daytime light curve on aquarium

#4 Post by noxin » 15 Apr 2024, 08:01

hello,

it's shame, but i wasnt able to try out this script before yesterday. script works very fine, it counts up the light, when count is done the esp32 keeps the lights at the highest level.
when this was done i realised that i need to get light fade down the same way. so i figured out this skript:

on system#boot do
gpio,14,0
endon

on Clock#Time=all,07.00 do //start time
looptimerset,1,3,335 //timer 1, interval 3sec, 335 steps
endon

on Rules#Timer=1 do // timer 1
let,1,%eventvalue2%*3 // timer 1, eventvalue 2 is the timer, count up x3
pwm,14,[int#1] //gpio 14 with variable#1, computed by eventvale 2 x 3
logentry,"1: %eventvalue1%, 2: %eventvalue2%" //logentry
endon

on Clock#Time=all,12.00 do //endtime on noon
looptimerset,2,3,335 //timer 2, as above
endon

on Rules#Timer=2 do //timer 2
let,2,[int#1]-%eventvalue2%*3 //timer 2, variable#1 still on value from count of timer 1, eventvalue2 count up but subtract this value from int#1
pwm,14,[int#2] // gpio 14 with substracted value
logentry,"1: %eventvalue1%, 2: %eventvalue2%" //logentry
endon


maybe there is a more smart way or some better to use commands to do the job. i had problems with the "eventvalue". script only worked after i set "logentry". i could not find a reason on that ??
to the loop: it counts up every 3 sec to get a smoother light-curve, 335 counts are no problem.

I couldnt figure out why the script worked after i added the logentry commands.

Thanks again to TD'er !

regards

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: seeking a rule daytime light curve on aquarium

#5 Post by TD-er » 15 Apr 2024, 08:50

It shouldn't matter if you use logentry or not.
Maybe adding this did remove some non-ASCII character?
Or "endon" was not on a separate line?

Oh and by the way, when setting the looptimer, you might want to set the [int#1] value to the correct value.
After a boot, the variables are uninitialized and thus considered to be 0.
Maybe you did test the "countdown" while the variable wasn't initialized?

noxin
New user
Posts: 4
Joined: 28 Dec 2023, 12:44

Re: seeking a rule daytime light curve on aquarium

#6 Post by noxin » 15 Apr 2024, 14:02

hello,

i definetly did not initialize the int#1-value. in old c-64-times it was a good idea to set used variables to zero. i will figure out how this works.
next step is to add a electricity fallout management in case if there is no chance to store values after power off or cut off / Blackout.

regards
noxxin

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 27 guests