SmartThings Community

[OBSOLETE] [BETA MILESTONE 1] CoRE (Community's own Rules Engine)

Just need some guidance re variables. Just messing with a simple piston that will send an SMS if battery level of any sensors in the condition drops below 30%.

In the trigger group I’ve named a variable in the ‘save matching device list’ called ‘batterylow’

Can this ‘batterylow’ variable be then used to fill the sms message with name of device that is low. How is the syntax for the sms message set…

“{batterylow} has low battery”

do i need to use @ or $ symbols anywhere??

1 Like

You got it right. Use any name for the “Save matching device list to variable” and then use that name between { } in the SMS message.

When saving the info to a variable you can use @ to make that variable global. This means other pistons will have access to it as well. You don’t have to, unless you need that info in other pistons. You won’t be able to set any variable starting with $ as those are reserved system variables - they change on their own :slight_smile: The example you showed should work.

1 Like

Just a note here. Using a trigger will only provide one device at a time in your list, because only the device that triggerred the evaluation actually dropped below 30% at that time.

Dropped below is different from is below. This is because Dropped below involves transition. It senses the transition of a value past a threshold. So you won’t get all devices in your list, because only one “transitions” past the 30% threshold at any given time.

Use a condition instead. IF [devices].battery is below 30% … this will still happen every time a battery level changes, but all devices below 30% would match true. But be advised, every time a battery level changes, you’ll get an SMS, if any is below 30%. So if you have a chatty device that keeps reporting battery changes (should not happen in real life as they are supposed to conserve their battery, not waste it on reporting that battery is going down) you’ll definitely see a lot of SMSs coming your way. You can fix this with a time trigger and the condition on battery. This way you can make the time trigger happen daily at whatever time you want it, so you only get up to one SMS a day…

1 Like

Perfect, works like a dream!!

1 Like

Edit: I’ve updated this as a Latching Piston to make sure motion active keeps things in the right state if the motion sensor doesn’t got out of active state due to constant motion, which a simple piston will do.

Just wanted to post a more complex but still pretty simple example that can help others get a quick understanding of the complexity you can easily achieve without going full tilt with variables and groups.

Previously this worked in a backward manner with RM, it’s easier to read here but works the same with the added “flash” notification that a light is about to turn off, without using flash…

Scenario: Walk into bathroom, light turns on. Leave in under 3 minutes, light will flash after 2 minutes of inactivity, stay on for one more minute, then turn off. So if you’re in the tub falling asleep, the flash will let you wave your arm to keep the light on. If you are in the bathroom for 2 minutes (minimum of activity) the fan will come on, assuming you are in the shower. After no motion from that scenario, the light will still wait it’s two minutes, flash, one minute, turn off, the fan will wait 10 minutes to finish venting the room, then shut off.

Piston Mode: Latching

If…

–Bathroom Motion Sensor -> motion is active

Then…

–Using Bathroom Light

  • Turn on

–With Bathroom Fan

  • Wait 2 minutes
  • Turn on

But If…

–Bathroom motion Sensor -> motion is inactive

Then…

–Using Bathroom Light (Cancel on piston state change)

  • Wait 2 minutes
  • Turn off
  • Turn on after 1000ms
  • Wait 1 minutes
  • Turn off

–With Bathroom Fan (Cancel on piston state change)

  • Wait 10 minutes
  • Turn off
8 Likes

Edit: I’ve updated this as a Latching Piston to make sure motion active keeps things in the right state if the motion sensor doesn’t got out of active state due to constant motion, which a simple piston will do.

Here’s another that uses motion, lux, power, and lights.

Scenario: Dining room is dark when light outside isn’t cloud free…so turn it on when lux is low, unless watching TV or other lights in the Living Room/Dining Room are already on.

Piston Mode: Latching

If…

–Living Room Motion Sensor -> motion is active

And

–Living Room Theater Outlet -> power is less than 30W

And

–Bloomsky -> illuminance is less than 3600lux (yes my BS is working fine with this!)

And

– Each of Dining Room Light, Living Room Light or Kitchen Sink Light -> switch is off

Then…

–With Dining Room Light

  • Turn on

But if…

Living Room Motion Sensor -> motion is inactive

Then…

–With Dining Room Light (Cancel on piston state change)

  • Wait 5 minutes
  • Turn off
  • Turn on after 1000ms
  • Wait 1 minute
  • Turn off
3 Likes

Don’t forget to vote for CoRE’s own icon

1 Like

I’m trying to execute the following, and I’m having a hard time understanding where to put limitations.

This is what I want: I have motion sensors at the top and bottom of my stairs. I want to turn on the upstairs lights when walking up the stairs and have them turn off when walking down the stairs, given that these actions happen within a certain time range of the day, in a certain mode and given a certain light is already turned off. That is, if it’s NOT that time range OR NOT in that mode OR that certain light is NOT off, nothing should happen.

I’m trying to use a time frame, mode and a light as conditions to limit the piston from running.

What I’ve written, which, I don’t think will work, is the following AND-IF:

IF
Bottom motion sensor becomes active
and
Top motion sensor is inactive

THEN
nothing

AND
Time is between x and y
and
Mode is Home
and
My Light is off

THEN
Using Master Bedroom light and Office Area light, turn on

ELSE
Using Master Bedroom light and Office Area light, turn off

My questions is how do I add conditions to allow operation of the piston, and at the same time have conditions that create THEN/ELSE actions?

Am I making any sense at all here…?

I’m have set up the following using Or-If.

IF
lux less than 11
AND
Between 7:45am and 11:55pm
THEN
Turn On

OR IF
motion sensor active
time between 11:54pm and sunrise
THEN
turn on

ELSE
wait 5 minutes
turn off

My issue is that when the light turns on in the first IF, the lux value goes above 11 and thus the ELSE parameter becomes active.
Apart from setting the lux value to turn the light on to a value that is above lux value when the light is on, I don’t know how to get round this.
Any ideas anybody?

I used “Cancel on piston state change” to prevent something like this, you’d apply it to the Else statement I believe. Then when motion state changes on/off during the Or If, you get a clean slate, I think…I’m still trying to get mine to work more reliably, turns out it flashes on/off as per the Else statement if there is CONSTANT motion for the duration. Doesn’t hurt to give it a try!

Thanks for the reply.
Wouldn’t that mean that if I am away then there will be no motion then the light would stay on?

Probably…but I’ve had a light and fan shut off per an Else statement when only ONE of them had the cancel option enabled. So, think about EVERY time the rule will reevaluate, if even once after the cancel command runs (motion inactive for example) it should reset and start the else countdown again.

1 Like

In rule machine I could trigger lights on when motion starts and then turn them off after x minutes but only if motion isn’t detected with that x minutes. If motion was detected repeat the above process until lights turn off due to no motion after x minutes.

How do I do this in Core?

Simple Rule
IF
Motion Sensor is active

THEN
turn on

ELSE
wait 5 minutes(your own value)
turn off

If motion is detected in the 5 min period before lights turn off, timer is reset.
Works OK for me.

I have missed quite a bit out here where you select the devices etc.

That’s what I thought would work. I haven’t tried it yet. Right now I am using Rule Machine and wanted to convert over to this. I didn’t want to rip out all of my current rules until I understood how to use this tool.

The easy way: enable cancel on piston state change for the turn off action.

The more flexible way: Any action will (by default) override its own future scheduled tasks. What you want will happen automatically. Behavior is defined in the Task Override Scope for the action. If you use the scope Local, when motion is detected, the action that normally turns the light on will remove all turn off scheduled tasks forvthe specified devices, so you’ll get exactly what you want.

scope Local? Not sure what you mean by this.

Each action has advanced options. There are two actually:

Task Override Scope (None, Action, Local, or Global)

Task Cancellation Policy (None, Cancel on piston state change)

There is a short explanation on the override scope there… It prevents different actions fighting over the same device. Action means that when an action is executed, anything pending that has been previously scheduled by the SAME action is cancelled. Local refers to any action within the same piston. If action #1 schedules front light off in 5 minutes and action #2 turns it off now and has the local scope, action #1 is then cancelled…

Ok, I figured out my own question:

Using a latching piston did the trick.

My use case: with motion sensors at the bottom and top of my stairs, when I go up the stairs, turn on the stairway and upstairs lights. When I come down the stairs (and reach the bottom) turn off the upstairs and stairway lights.

IF
Bottom Motion becomes active (trigger)
and
Top Motion is INACTIVE (cond)
and
(Time is between x and y, and mode is Home, and bedside light is off) (cond)

THEN
Set dimmers and turn on lights

BUT IF
Bottom Motion becomes active (trigger)
and
Top Motion is ACTIVE (cond)
and
(Time is between x and y, and mode is Home, and bedside light is off) (cond)

THEN
Turn off lights

1 Like

Can someone help me understand something, please? First, what is ‘Save State’? Secondly, can anyone give me some examples on how one might use variables? I understand what they are, just not sure how you would use them in the context of the app. I realize they will store values though.

I love, love CoRE so far, it has an almost Android Tasker feel to it so in that respect it is familiar, but different too, so I have some things to get used to.

Thanks for all the hard work that is going into this.