Is it possible to have condition like "If weather is cloudy then offset -30 minutes else offset 0 minutes"


#1

1) Give a description of the problem
Is it possible to have condition like “If weather is cloudy then offset -30 minutes else offset 0 minutes”

2) What is the expected behavior?
If weather is cloudy then turn on the lights 30 minutes before sunset else turn on the lights at sunset

3) What is happening/not happening?
(PUT YOUR INFO HERE)

**4) Post a Green Snapshot of the piston!


5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

So…if 30 minutes before is your target time. Then you could write a piston to start AT that time. Then you could check the weather (is it cloudy) and if it is then turn on the lights right away…otherwise (else) wait 30 minutes and then turn on the lights.


#3

You could also put this in the offset field (choose the expression option instead of value):

((contains($weather.conditions.current_observation.weather, cloudy))==‘true’?’-30’:’0’)


#4

Thank you Mike for replying. I did not think about this solution. thanks.


#5

You sir, are the Man. Thank you, thank you. I will try this.


#6

Nice. One question (or clarification). If that’s a daily timer…when does that evaluate, does it evaluate the current day or does it evaluate the previous day? Or are you saying use Time (happens daily) instead of a Timer? (OK that was more than one question… ) :slight_smile:

I think if he uses a Timer it would actually evaluate the day before…


#7

He didn’t post the full piston so I don’t know… but yes, depending on the trigger it may schedule based on previous days weather.

If that’s the case, suggest a dud block allong the lines of:

every hour
DO
nothing

This will force the piston to re-check and resubscribe hourly.


#8

Sorry about that, I have added the piston screenshot.


#9

Yeah… you’ll need the standalone timer top or bottom of the piston… just to force a reschedule every hour… good catch @Mike1616

You’d also do better having the 3 IF statements separated into 3 seperate blocks, rather than using the ELSE statements.

IF
A
THEN
AA
END IF

IF
B
THEN
BB
END IF

IF
C
THEN
CC
END IF

Every 1 Hour
DO
(Blank)
END DO


#10

Damn - didnt think of this and needed this for another piston thank you sir!!!


#11

Thank you , I will make the changes. Just out of Curiosity why three separate it’s instead of else?


#12

Just easier to read and re-arrange as the 3 blocks are complete on their own.

ELSE is better used to be the reverse of the conditions. If this do that otherwise do that. (Not if this do that otherwise if this do that)

Both methods work though.


#13

Thank you for the clarification. Any suggestions on the fade in the first do block, the level stays at 30% and does not increase. I have tried a manual fade by bumping up the level by 10% every two minutes, but that didn’t work either.


#14

can you post the logs for that first block or around the time of the first block … it looks right to me from a quick look … the only thing I do different is that I dont turn the light on, I just

Set Level 30%
Set Color Temp 6k
Fade to 75% over 30m (only while HOME)
Send PUSH
etc

I have found through other mistakes that setting level alone will turn the bulb on … the only time I explicitly use turn on in this scenario is with my Lutron Caseta which are somewhat testy in this regard


#15

Unfortunately the other events overwrote the logs. I will save the logs tonight and share. And I will also try removing the turn on based on your recommendation to see if that makes a difference. Do you have any starting value for the fade?


#16

I suspect the fade is being cancelled as the trigger (time) only stays true for a short while.

Click on the ‘with’ and change TCP to ‘never’


#17

Thanks, I have changed the TCP, will test it tonight. On another note, is there a syntax error in the statement that you provided? Webcore doesnt like it . Am I missing quotes or something?


#18

Since ‘cloudy’ is the string being searched for, I believe it needs to be in quotes.

((contains($weather.conditions.current_observation.weather, ‘cloudy’))==‘true’?’-30’:’0’)


#19

Thanks. That worked.
So after all the suggestions from all of you, this is what the piston looks like:


#20

Question (to anyone on this thread)…can this expression:

((contains($weather.conditions.current_observation.weather, ‘cloudy’))==‘true’?’-30’:’0’)

be put in a global variable and be evaluated/parsed at run-time within the piston using it?