Setting a time trigger from a device attribute

I have a device which report in an attribute the time of a future event. Is it possible to use this as a trigger in an automation?

Yep...just use the custom attribute option in Rule Machine.

I cound not figure it out because I tried but when setting a time, there is no choice for doing it from an attribute. The option is not available.

Edit: To make it clearer, I would like the rule to start at the time reported by the device. the device has an attribute that's a time stamp and you want to schedule some actions to run at that time? What is the device? How and how often is the attribute updated?


The device is a virtual one seeking a timed event from an api. It is check every 60 sec but the time itself change at most twice a day.

I'm honestly a little stumped at the moment. The problem is getting the date/time from the attribute since it's either a string or number object. Rule Machine would be pretty limited here.

I'm leaning towards you'll need an app. @bertabcd1234 can you think of anything?

The value could be parse into a date object internally but attributes dont have a datetime type. Even if it would, I dont think RM support that.

That's my assessment as well. You could easily parse the date/time with an app and schedule actions to run that way.

If you need to trigger when the attribute time changes:
Custom Attribute / 'your device' / attribute / Comparison - changed

Does that work?

Nope--same issue as you, thinking it's not possible to get a date/time string parsed into a DateTime variable using only Rule Machine (certainly possible with an app).

However, another idea: is the driver code your own (@ymerj)? If so, your driver should have a way to know when the date/time really is and be able to expose an event at that time via some more easily accessible means, e.g., generating a button event on your device (like "button 1 pushed" if you aren't using this capability for anything else)--much more easily used in RM or any app.

Of course, if it's not your code (or you don't feel like modifying whatever code it is), that is trickier. :slight_smile:

1 Like

Since a datetime variable could be use as a trigger in RM, I thaught doing the same with an attribute wouldn't be far fetch.

Thanks but no, it won't work. When the time change is irrelevant. It is the scheduled time reported by the device that matter.

Great! This look like a solution. I have access to the code (HADB) but it has to pass scrutiny. I'll try it on my personnal copy. Thanks.

Does RM have the ability to pull a Unix timestamp from epoch and put that in a variable or something (along with calculating an offset from the occurrence of some other event if needed)?

You could definitely do that in the driver code, and if you update the attribute periodically from the driver (as something like now()), then you would be able to trigger when it changes and has become a bigger number than the timestamp value you wanted to use as the trigger in RM.

From my poking yesterday, using d/t in RM is pretty limited compared to what you could do in an app/driver. I would think that if you're going to manipulate the driver to handle checking the time, then just having the device do something (switch, button, etc.) would be a much better option for use in RM.

On second thaught, the solution with scheduling a button event at the reported time restrict it to that exact time and there is no possibility of setting a negative offset. @tomw I don't know if it is what you are talking about (you lost me there). I was also thinking about a companion app maybe.

Yep, that's a better suggestion. I was proposing that you put the logic at the RM level, but doing it internally to the driver and keeping it simple by exposing only an event already supported in RM (button pressed, switch flipped) is a lot cleaner.

1 Like