I'm trying to extract the time from a driver (string) attribute and convert it to a time variable. I've figured out how to extract the time (24 hour format) into a string variable, but I cannot figure out how to convert it to time variable for my use case.
Hoping someone has some input if this is even possible?
You can do it in Webcore, but I'm not sure about Rule Machine. You would need to chop the first four characters off the front to get rid of the day, and you need to get rid of the nine characters "AKDT 2025" from the end. Then you can set a time, or a dateTime, from that string by just setting a time (or dateTime) variable from the string.
That is if you have any interest in using Webcore for this instead, but maybe someone else knows how to do it in Rule Machine if it is possible, but I don't really use RM.
I was already able to set the time to a string by using RM "token" command and set it to a string variable "extracted time" just can't figure out if I can then convert it to a time variable.
I'm not looking to go down a new "rabbit hole" with webcore at this time, thanks for the input though.
The result reads 9:36pm (correct based on rounding of the seconds), however if I create a condition for the result variable it's showing as 9:35pm? It seems like the UI is displaying the rounded variable value but that the conditional value is not?
Edit: Assuming my results were not unexpected, I was able to account for the rounding by creating another variable token using the "seconds" part of the string and then converting that to an integer that determines if an offset should be used in the sunset variable.
Hi - hope you don't mind me sharing another scenario here I just ran into - your thread gave me inspiration, and I was searching the forum and RM documents trying to find a similar example and I could not so here goes...
I'm using the community Rachio app which has a lot of device attributes - I was trying to get the nextrun which is either written like "Apr 28, 2025 - 2:45:00 PM" or in epoch time "1745880300000" and I struggling with trying to convert either to useable datetime (kept getting a fail when attempting to use the epoch time directly ... well after growing weary of trying to parse out the text string it finally hit me that need to add another hop!
So this works now:
I have to, read the device attribute as string, convert the string to a number, write the number variable to epoch time, and last correct for the time zone.
Figured I would share incase this helps someone else out.