I’m trying to set up my own circadian daylight piston; I know they exist but I’d like to create one for my own purposes. The theory is this… I have variables for Time1, Time2, Time3, and corresponding Level1/2/3 and Temperature1/2/3. When time($now) is Time1, set @Level to Level1 and @Temperature to Temperature1.
Then I want Level1 to slowly transition to Level2 by Time2. Same thing for Temperature2.
I’ve come up with an expression that has a few parts. First, it’ll determine how much time their is between Time1 and Time2 (e.g. 5 hours), and how much time has passed $now since Time1 (e.g. 1 hour). It’ll divide those 2 values to determine how far along that time span we are $now (e.g. 20%, or 0.2). Then it’ll take the difference between Level2 (e.g. 100) and Level1 (e.g. 90; difference is 10) and multiply that number by how far along (e.g. 0.2 * 10 = 2) and add that number to Level1.
Logically, this makes sense to me… Figure what percentage of that time span has passed, add that proportion of the difference in Levels to Level1. When it runs every 5 minutes, it’ll slowly transition from Level1 to Level2.
Expression is:
($now-Time1)/(Time1-Time2) * (Level2-Level1) + Level1
It works great for certain times, but it spazzes out at others and I can’t figure it out. In my example piston (see attached) testtime takes the place of $now (once it’s actually working). If I make testtime 8:00 AM, works great. If I make it 9:00 AM, works great. If I make it 8:30 AM it gives me a spazzy number. When I plug the expression into the expression editor, each of the “segments” make sense;
1/5 * 10 + 90
= 92
but the entire expression gives me a wrong number of “1.33”
I’ve tried this dozens of ways and I just can’t figure out why it won’t consistently work.
For troubleshooting purposes, my local $sunrise is 7:51 AM and $sunset is 4:40 PM.
Any ideas?

