Webcore Help - Basic Question

Hey webcore users, having some trouble with an automation. It is really really simple. Motion detection does trigger a log item and run the piston. However, the light never turns on. Anything obvious I should be checking?


/**************************************************************/
/* KitchenLightMotion - ON at night                           */
/**************************************************************/
/* Build      : 8                                             */
/* UI version : v0.3.114.20220203                             */
/**************************************************************/
 
execute
if
Any of Dining Room Light's, Kitchen Island Lights', or Kitchen Main Lights' motion is active
and
Time is between 40 minutes to sunset and 30 minutes past sunrise
then
with
Kitchen Island Lights
do
Set level to 18%;
Turn on;
end with;
end if;
end execute;

Screenshot version if you like the color coding:

Typical Log item when motion is detected:

9/2/2024, 7:20:40 AM +53ms
+2ms 	╔Received event [Kitchen Island Lights].motion = active with a delay of 22ms, canQueue: true, calledMyself: false
+94ms 	║Runtime (6791 bytes) initialized 92 LockT > 1ms > r9T > 3ms > pistonT > 1ms (first state access 86 m:2 3 89) (v0.3.114.20240115_HE)
+95ms 	║╔Execution stage started
+101ms 	║╚Execution stage complete. (7ms)
+162ms 	║Setting up scheduled job for Mon, Sep 2 2024 @ 7:26:00 PM EDT (in 43519825ms)
+165ms 	╚Event processed successfully (163ms)

I would change 2 things.

Any of motion sensors changes to active

Remove the trigger (orange lightning bolt line 15) from the Time condition

1 Like

(edited) Ok got the "changes to" fixed.

I couldn't figure out how to remove the trigger lightning bolt from TIME. However I realized that once I changed to "changes to" in the first clause, it went away automatically! I'll see if it works tonight, thanks!

1 Like

I'm at lunch on my phone. When I get back to my computer, I'll show you.

Click on the statement that you want to change the trigger (lightning bolt)

Then on the cog

Then on Subscription method

Then on Never subscribe. Then Save

The minus sign indicates that you have changed the subscription method

Any feedback?

If it’s still not working change “time is between sunset and sunrise” to “time is not between sunrise and sunset”.

It helps to check the current values of your system variables. Sunset and sunrise are both today. So I believe the way you have it, it’s checking between today’s sunset and today’s sunrise. I can’t recall if this never matches true or if it only matches during the day - I believe the former.

You can also change it to “time is between sunset and nextsunrise” I believe.

Edit: and yes, I believe you need to enter this line as a condition not a trigger as @Pantheon suggests.

I have used this thought process for years since learning it from WCmore back in my SmartThings days. It might require a little thought to write code that way. In essence, it removes the time/date change at midnight that might cause some problems with execution timing.

I think it goes beyond the break at midnight. Webcore handles sunset and sunrise as points in time (epoch time), not times of day (5:45am). So in essence, I believe the OP is trying to match a time range that starts later than it ends… from today’s sunset to today’s sunrise. IIRC, this will not work in WC… but if it does happen to work, it’ll only match during the day.

Yes. That was my "initial" exposure to this coding option, which has now expanded...

1 Like

I believe mine too. Imagine if we were trying to code through the break at midnight during Y2K. :wink:

1 Like

Initially, I had a little difficulty mentally getting the "not" part. But after using it a few times, a light bulb in my brain turned on, and I now understand its application. I use this method often.

No luck so far. So I will try the ‘not’ method, the above makes sense to me I think! Will report back tomorrow hopefully…

I tend to keep my "conditions" and "triggers" separate. I recommend reading two posts:
Triggers And Conditions 1
Triggers And Conditions 2

There are many different ways to write your piston. My BASIC approach would be as follows:

If Any motion sensors change to active <- Trigger
  Then
    If Time is not between sunrise and sunset  <- Condition
      Then
        with Light
          Do
            Set level to 18%
            Turn On
        end WITH
     end IF
end IF

This piston might progress to accommodate other factors:

  1. How long should the lights stay on after motion changes to inactive?
  2. What happens to the lights (on/off) if a person stays in the area for several minutes?
  3. What happens if someone walks out of the room and then walks back in?
  4. What other conditions might result in turning the lights on or off?

So BASIC pistons can grow, gaining a life of their own. Just food for thought :slight_smile:

1 Like

I like this style, so I changed it to it, and still nothing - is there a way to see what webcore is evaluating each statement to? Or a way for me to say "print(we got to section 2)" in logs so that I can tell if it's getting into each IF statement appropriately?

What I CAN say is that this works without any issue... so at least I believe it's something wrong with the time, sunrise, and sunset clauses...

The only thing I can think of is that the "time" is a string and the "sunrise/sunset" are "datetime" type in the variables page. Am I using some incorrect "time" variable?

image

Edit to add:
And, if I use the {$now} variable which is a "datetime" type, I don't get the option in webcore to add an offset to sunset/sunrise times which is pretty annoying! But I also tried this and it doesn't work either (and it is now past sunset):