@bravenel, I have found that I am unable to save a Date/Time value coming from a device to a Variable in Rule Machine. I havenāt tried doing this before, so maybe thereās a way and Iām not aware of how to do this yetā¦
Otherwise, is this something that could be added?
In the screenshot below, it is possible to see that the option to save from a deviceās attribute is not available when using a date/time variable:
Why am I asking for this?
I have created a rule that will adjust the charging amperage of my vehicle based on the amount of over-production from my solar array.
I want to change this value (add or take away from it) based on what has it has been set to previously. This data can come from either the device itself (best case) or the ruleās previously set value. I want to compare the last polling update of the device (which is stored as a state) to the value in a variable where I store the last time the rule ran.
The driver I use to connect to the vehicle polls it to get theirs data and I want to minimize the polling. I could forgo this by polling more often, but I would prefer to avoid this as much as possible. The vehicle will on occasion change the value, so I can not always rely on the value I stored in the app.
Here is a screenshot taken from the deviceās states showing this date/time:
In general, drivers don't support date and time attributes. Having this attribute in a custom driver doesn't mean the date time value conforms to that which is required for a DateTime variable. So it doesn't make sense to open this particular can of worms since it probably would not work, but creates some expectation that it would.
I think what you would need to do is use a DateTime variable connector, and set that with the setDateTime() command, passing a properly formatted string.
You can see there the correct string format for this date/time:
This is the only mechanism I can think of that is going to allow you to go from a string (e.g. "2023-07-20T10:41:15.000-007") to a DateTime variable. Rule Machine does not have a method to do this, but a small custom app could do it.
Ideally, I would want to trigger the app with a change to the lastUpdate value, but it could also be triggered by a button press or switch update event if thatās easier to do.
The lastUpdate attribute is indeed a string:
attribute "lastUpdate", "string"
Not sure if it makes a difference, but this is how it gets populated in the driver:
Since the attribute is just set to now, all you have to do is trigger the rule from that attribute changing, and set the DateTime variable to now. You don't need to do anything with the actual attribute value, since you know exactly what it is (plus a couple hundred milliseconds).