Rules / Variables based on Date or Calendar

Day, time and date variables are a good thing
Plus weather variables, current weather, expected rain, temperature and humidity

It would be perfect

Hi there! I hope you don’t mind that I’ve merged these three topics together. While there are some minor differences between them, it sounds like the overall need is for better control over dates/times – either directly through conditions or potentially through a proposed ‘Date/Time’ type of variable.

Would you see this as a potential addition in the ‘Time’ trigger section? Currently, you can use the Time trigger and either trigger every day or adjust it to only trigger certain days of the week.

Perhaps in addition to the ‘daily’ and ‘weekly’ option, there could be some other choice for broader date ranges. Similarly, there’s an IF Condition for Day / Time and perhaps a date range option could be added there as well.

2 Likes

Do you have an example use-cases you could share? We could certainly create variables for current date / month / timestamp, but we’ve held off on it as there hadn’t been any requests for it so far and the use cases weren’t particularly clear.

If you’re just looking to trigger a rule based on different days of the week, you can do this with the Time Trigger. See the screenshots two posts up – you can tap the ‘Everyday’ in my screenshot which brings up the Repeat Options. From here, you can select ‘weekly’ and choose which days of the week you want to trigger things on.

Do you have any weather devices attached to your SmartThings account? If so, do they not include the data you’re looking for?

@josh - variables are so much better that you can use them in notifications, eg “Hi, It’s Monday, September 20, moderate cloudiness”

Do you have any weather devices attached to your SmartThings account? If so, do they not include the data you’re looking for?

I have an outside temperature sensor, but it doesn’t show the weather. The easiest way would be to extract data from the integration with https://openweathermap.org/ and on their basis set constant variables, such as the current weather forecast, humidity, temperature, etc.

Thanks. I suspected there was more than just the ‘variable’ part of things. It sounds like some controls around formatting the dates would be important in that case too. :slight_smile:

Can you share some examples of how you format these date/timestamp variables today? It seems like it could be something that would feel overwhelming to a new user… but perhaps it’s just more of an ‘advanced’ feature and naturally requires a bit more configuration if you want to customize the format.

Currently in Homey Bridge I have one date format and I accept it as it is DD.MM.YYYY you can define 2 or 3 formats permanently in the settings or for very demanding users make 3 variables
current day (e.g. 20), current month digitally or in words (08) and current year 2022 and you can write in the notification

E.g. “Hey, it’s {day}. {Month}. {Year}, current weather: it’s raining”

Similarly, with the time we are from different parts of the world, some use 24 hours, others AM / PM

You can do this with the HTTP Action in SharpTools today. I agree that it makes for a good feature request as a native integration though to simplify this process for people who don’t have weather devices attached to their SmartThings. :smiley:

Let’s take the Open Weather /weather endpoint which provides the current weather. The URL is in the format:

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

And the response is in the format:

{
   "coord":{
      "lon":96,
      "lat":-33
   },
   "weather":[
      {
         "id":500,
         "main":"Rain",
         "description":"light rain",
         "icon":"10n"
      }
   ],
   "base":"stations",
   "main":{
      "temp":286.4,
      "feels_like":286.08,
      "temp_min":286.4,
      "temp_max":286.4,
      "pressure":1032,
      "humidity":88,
      "sea_level":1032,
      "grnd_level":1032
   },
   "visibility":10000,
   "wind":{
      "speed":6.89,
      "deg":143,
      "gust":7.83
   },
   "rain":{
      "1h":0.19
   },
   "clouds":{
      "all":97
   },
   "dt":1661023588,
   "sys":{
      "sunrise":1661040462,
      "sunset":1661080271
   },
   "timezone":21600,
   "id":0,
   "name":"",
   "cod":200
}

So if we wanted to get the main weather report, we would be looking for the weather.0.main element in the response. So we can make the HTTP call and then get the response data using Context Variables (Response > HTTP > Data) and use the object property notation to grab that nested property for use in our notification:

1 Like

Thanks for the feedback. In our Super Tiles, since they are running in the browser, we can infer your ‘locale’ and use that to display things in the timezone and format your computer / tablet prefers.

For Rules, we typically associate things with ‘locations’ since some people have multiple locations attached to their account – for example, their main home and a vacation home. We use that for determining the appropriate localized time for triggering rules. I suspect we could either add user-level or location-level formatting options. Originally I was thinking you might want a rule action like Format Date where you could customize the date for that particular notification just to pull out the parts you are interested in (similar to our Super Tile date/time format options).

I love your advice right away in a few hours :slight_smile: Divine!

Yes, but how do I pair it with variables? I would like to use them in notifications?

My apologies for not being clear – I was just trying to better understand the use-cases. We don’t have it available as Rule Variables today, but if we eventually build it I want to make sure I understand how people use it so we can make the right design. :smiley:

Thanks! :slight_smile:

Sorry, my English is terrible.

Generally, it is about notifications in which you can use the date, sometimes in simple such as hello is a day, and sometimes in emergency such as “At 12:00 on August 20, 2022, a movement in the garage has been detected”

The weather works perfectly, I take the data I need from the API, you are great!

1 Like

I was able to download weather.0.description from the data, but I would like to download the temperature data in the same query and how it adds main.0. temp is unfortunately nothing changes in variables, can you tell me what am i doing wrong?

Ok, I did it, I don’t know why you put “0” there, what does it mean, what does it mean?


Sorry, I call myself variables in Polish, I think you might guess what’s going on: D

So it looks like the temperature is actually under the top-level main property. So you would want to access it as main.temp

Also, don’t forget that you can include the &units=metric parameter at the end of your URL so it puts the temperature in the proper format. :smiley:

(And for those that prefer Fahrenheit, you can use &units=imperial)

I remembered, I remembered and added & lang=PL :slight_smile:

All in all, it’s good to describe it and everyone who has a problem with virtual weather stations, which will not work easily on EDGE, can do something like this by themselves, all you need is CRON, Weather API, @josh friend and done :slight_smile:

1 Like

In object property property notation, each ‘child’ property is accessed with a . and arrays are normally accessed with brackets [n] where n is the index (0 based) of the item.

Let’s take a simpler example:

{
   "animal": {
      "type": "cat",
      "colors": ["red", "orange"] 
   }
}

We would access the type as animal.type.

We could get the list (array) of colors as animal.colors but if we only wanted to get the first color, we would normally access it as animal.colors[0] and if we wanted the second color we would use animal.colors[1] (remember that indexes are 0 based with JSON objects)

Hopefully that arbitrary example helps explain and doesn’t just make things more confusing. :laughing:

2 Likes

Also think we need variable and not a trigger
In this piston and other piston, I’m using a variable to be sure I execute the command once a day, So I compare a variable with a number with sysdate

For that particular use case, you can use a True/False variable. Create one rule that resets the variable to False at 00:00 every day. Then in your other rule that you only want to run once per day, you can add an IF Condition to only run if the variable is False and then set the variable to True within THEN part of the condition. :slight_smile: