Condition is a Month

I am trying to convert a piston that controls part of a pool system. It is easy in webCoRE, but I don’t see a way to make the month of the year a condition. Piston attached.

Is there a way to do the same thing?

If June, July, August, turn off at 8:00 PM
If September, October, turn off at 7:00 PM

You can use the /date labs endpoint for this:

Thanks Josh for the fast information. Is there a YouTube on how to use this information. I’m making no sense of it in writing.

Not sure if there is a video, but this may get you going until Josh has a moment to respond.

The basic idea is to get the current month in a variable. Once you’re done that, you can use that as a condition in your rule to run it only during the months you choose. You are going to do that by coding a HTTP Get which will return the current month and will be stored in a variable.

1 - Create a variable named ‘month’ for example

2 - Create a rule that runs once a day at some arbitrary time, best in the morning if in the US or Canada.

3 - In the Flow section of the rule, create an Action, HTTP, GET. Put the URL https://lab.sharptools.dev/date in the URL field. (You can add a timezone for granularity, but it shouldn’t matter if you have the rule run in the morning.)

4 - That GET URL will return the month, among other data. You then need to tell the rule to store the month value returned in your variable.

5 - Action, Set Variable and choose your ‘month’ variable. Source:Variable, Context Variables Tab, Response, HTTP, Response Data, Put ‘M’ in the Input Data Key.

When this rule runs, it will obtain the month and place the month as a numerical value into your variable. Go to the variables section where you created the variable and you’ll see the value populated. If you’re doing this in September, the value will be 9. You can now use the ‘month’ variable in your rule in an IF statement to determine whether or not your rule should run based on the value of the ‘month’ variable.

image

1 Like

Thanks @Bry

That works. !!! :white_check_mark:

How would I separate August and September in my actual rule? Just a comma between? My rule will be looking for August and September. I’m assuming I don’t need different rules for each month.

Now… is there a way to do the same thing and get the forcasted high and low for the day?

I have Pistons that work based on both of those…

You’ll have to put the test for two months in an IF in the flow, because AFAIK you can’t have an ALL in the Trigger. So trigger on something arbitrary and then IF with an ALL.

(No idea on the forecast . . . )

1 Like

Thanks so much. This is taking me back to the days when I was learning WebCoRE… Some days were good, some, not so much!

1 Like

What platform are you using and how are you currently getting the highs and lows?

1 Like

I’m using WebCoRE. It has been bullet-proof.

Every night at 11:50 PM I set a variable for the high and low for “tomorrow” at TWC. {@twcHIGH} and {@twcLOW}. Then I use those variables to tell my other Pistons IF they should do stuff.

Picture2

Picture1

If you have a SmartWeather device which uses the same data source, you can pull the data off that device fairly easily.

…it’s not clear if the SmartWeather device will continue to exist after the Groovy shutdown though. It’s a cloud integration that uses the same TWC source, but the DTH itself is Groovy, so I’m not sure if they will handle it in a special way with the shutdown.

As an alternative, you can setup an Open Weather Map account and can query the data. It’s a few steps to get setup, but once you have the concept down, it provides a lot of functionality:

:link: Rules / Variables based on Date or Calendar - #14 by josh

Thanks Josh.

I’m pulling from The Weather Channel. I am going to try the steps that @Bry sent me for the Month and see if I can get the forecast for “Tomorrow”. It is not a SmartWeather device. Seems to be the same concept. There was a reason I had to pull at 11:50 PM, but I currently can’t recall why. I believe it may have been a time zone issue.

Do you think I can set a variable using data from The Weather Channel?

Not without an API call. WebCoRE was running as a Groovy SmartApp, so it could access the TWC data from the SmartThings Groovy API directly. Of course Groovy is on it’s way out…

The SmartWeather device is using the same data source – I can’t remember exactly what data it exposes, but if that device had the required attributes, you could use it. (Other hubs have a variety of different weather ‘devices’, but for whatever reason, there weren’t a lot of different weather devices created by the community in the SmartThings ecosystem)

Otherwise, if you don’t have a weather device available, making an API call as linked above would be the way to do it today.

Yup, exactly why I’m trying to learn SharpTools. I have 3 months to get everything transferred and WORKING!! It looks like some things I’ll have to do without. :tired_face:

If there’s something you feel is missing, feel free to post and we’ll help out!

With SmartThings killing off Groovy, sometimes it’s going to mean doing things slightly different than before. We’re listening to feedback though and where we see strong demand for things, we’ll build them in as first-class features where it’s reasonable. Of course, there’s lots of people coming over from WebCoRE, so we’re prioritizing based on which feature requests receive the most community interest!

1 Like

@josh

Using your example, I’ve set up an Open Weather Map account, received a key, and created the variable. Since I want Fahrenheit, I need to use “units=imperial” but have no idea where to put that.

Any idea?

You can add it onto the end of the URL:

https://api.openweathermap.org/data/2.5/weather?lat=-33&lon=96&appid={{API_KEY}}&units=imperial

That works. I test it in a Browser and it returns about a million data points. It does not set my variables though. I thought I set it correctly to have one set “tempMax” and one to set “tempLow”.

When I create the context variable I have 2 options.
Picture1
Which is correct?

How do I get just the "tempMax and tempMin from all of that data?

Which endpoint are you using from Open Weather?

You want the Response Data. Then depending on which endpoint you are using from Open Weather, that will determine which ‘property’ you want to grab from the response.

If you haven’t already, I would read through the other thread as it covers some of this in more details.

There’s also an example and description of how the object.property notation works in that thread.

http://api.openweathermap.org/data/3.0/onecall?lat=40.1681&lon=80.1987&units=imperial&appid=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx