Rule Engine - Recurring time trigger

I’m currently using WebCORE but I have to say I love the SharpTools Rule Engine approach. Unfortunately some functions are still not implemented. Maybe I missed something, but how can I create a recurring time trigger? For example, I would like to check my TV status every 5 minutes, to turn on or off the radio, depends on the TV status? It works great with WebCORE, but unfortunately I can’t find a way to do this with ST Rule Engine.

Any input is highly appreciated!

Thanks!

@Joern_B Glad you liked Rule Engine. :slight_smile:

Maybe I am missing something here, but why don’t you add the TV on/off as the event trigger, and then control the radio on/off in the flow? So it is event driven, instead of having to check periodically?

@James, the TV DH is a community delveloped device handler and unfortunately Smartthings doesn’t update the status. A reliable solution is to poll or refresh the status by using a 5 minute recurring trigger. It’s not perfect, but better than nothing and works very well. Unfortunately that’s currently not possibel with SharpTools rule engine.
Are there any plans to implement such a function or do you know a workaround?

I see. Sorry that the recurring timer trigger is not currently supported, but we’d definitely love to hear the feature requests from our users. Our development approach is community driven so the priority would be based on the interests received.

What options or feature do you need for this recurring timer? I am thinking of adding start_datetime and end_datetime options can be helpful. Ex: creating recurring timer in advance and only want it to be effective during the coming weekend.

Thanks for your response. It’s used for the daily use. Just the trigger every 5 minutes and then I combined this with some conditions like Smartthings location status “home” and the time "from 10:00 am to 8:00 pm. If the conditions are fulfilled, it will be refresh the TV status every 5 minutes. If the TV is off, it turns on the radio (Sonos), and if I turn on the TV it switches off the radio with the next refresh.

@Joern_B thanks for the details. Can you share a link to the DTH?

If the device handler fundamentally requires polling in order for it to work properly, I’m confused why this isn’t natively implemented as part of the device handler?

1 Like

@josh thanks for the reminder. I agreed that checking the DH may be a better way to resolve this particular issue. The event driven is more ideal and efficient.

@josh and @James thanks for your response. I totally agree with you, that an event trigger would be way more efficient and I absolutely would like to go without polling. If you could help with this in any way, I would really appreciate it. When I installed this device handler and got it to work with this workaround I was was happy and I also saw a lot of comments in the original thread, where people were not able to get this to work. Set it and forget it… I’m using SharpTools for Android since day one when I started using Smartthings but never knew anything about the rule engine and dashboard.

You did really a great job, thanks for all your hard work. I would like to move over from WebCORE to Rule Engine. Than I was thinking about my poll piston for the TV and wasn’t able to set this up in the rule engine.

Thanks in advance for any help with this and again, thanks for the great job!

Here is the link to the original thread with the DTH
https://community.smartthings.com/t/new-sony-bravia-tv-integration-for-2015-2016-alpha/64357

It looks like the driver exposes a poll() / refresh() method but does not schedule its own refreshing.

I read through about half of the topic (200/400+ posts!) and from what I can tell it seems like the original device author expected SmartThings to periodically run the poll() command. I vaguely recall that in the really early days, SmartThings automatically polled devices with the Polling capability, but it was unreliable and ultimately has been deprecated.

The SmartThings Documentation for the Polling capability indicates the following:

Allows for the polling of devices that support it. Deprecated, devices should schedule their own polling using the scheduling API or use the Ping capability.

Device Self Polling

One approach would be for the device to implement a runEvery5Minutes(poll) scheduling call. This would tell the driver to run poll every 5 minutes without needing anything external. (scheduling docs)

If you want to make this modification yourself, you can open the code for this DTH, find the updated() method (around line 592) and add the runEvery5Minutes(poll) line to the end of the method. It would end up looking something like:

def updated(){
	log.debug( "Preferences Updated rebuilding IP Address, MAC address and Hex Network ID")
	state.tv_poll_count = 0
	ipaddress()
	iphex()
	refresh()
	runEvery5Minutes(poll)	
}

Then you’ll need to edit / save the device preferences so the updated() method gets called.

Third Party Polling SmartApp

Alternatively, you can use a third party SmartApp to perform the polling. The Pollster SmartApp was created for this purpose… it should be noted that it was created in 2014 back when this was more of a need. You may have noted that official SmartThings device handlers are either purely event driven or implement their own built-in scheduling now.

Or the approach you are already taking with WebCoRE is fine - internally it runs on the SmartThings servers using their scheduling system.

Other Thoughts

If the rules are not triggered by the TV power status changing, but instead are conditioned upon the TV power status, you could adjust the rule so that it would poll the status before checking the condition (maybe adding a small delay between polling and checking the condition if needed).

2 Likes

Thanks @josh, awesome found. Haven’t got a chance to look at the DH code yet. Daddy duty this afternoon. :rofl:

You are really awesome! I added the one line item of code the the device handler and it works. That’s so cool. Now the DTH is doing the poll by itself and I can proceed using rule engine.

Another quick question. In WebCoRE you know, you are able to combine and structure trigger and conditions with brackets. Do you plan to implement something similiar, or how can I combine triggers and conditions in a more complex way? Is this currently possible?

Thanks a lot for your help!

1 Like

Cool, glad the polling is working in DH for you now. For conditional trigger, you can do it by adding the IF Condition block in the Flow section and desired actions in either Then or Else path. So the rule will be triggered but will execute by following your condition logic.

See example below that I’d only get notification if the event is triggered, and condition if matched. (You can also add multiple conditions in the IF_Condition block, and edit the condition block to change its logic from AND (ALL) to OR (ANY).

Let know if this helps.

1 Like

Thanks for your response. I will try it out and will play around a little bit with the rule engine. In case I will have further questions, I will come back here to ask.

2 Likes

I just wanted to chime in and say that I am playing with SharpTools as a potential replacement for Hubitat’s native stuff. I woudn’t to use both though.

I have a use case to consider for a periodic event, which I can’t figure out how to do here.

I have a remote location that is three hours away. In winter, there is nobody nearby.

Call me paranoid, but I have a periodic event that powers up all of the technology in the place (network stuff, webcams, etc) every5 minutes. This is cheap to run and protects me from myself in the event I fat-finger a dashboard button or something and turn off my router, which I have done.

Just wanted to throw that in there.

Hi yep I also have a requirement for a recurring rule trigger where I want to pole an API to get the latest crypto values every x minutes. I can then set dashboard signals to indicate if the value reaches a point where it would be good to sell the crypto etc.

8 posts were merged into an existing topic: Crypto Polling (Rule/Tile)

Hi Ben-
I split out a copy of the discussion around polling crypto APIs in a Custom Tile to it’s own thread here:

I’ve also left the original use case here since it helps illustrate how a recurring rule timer might be used. :slight_smile:

1 Like