Driver Polling

Hi all,

Today's query.

How does the capability poll work?

Eg how often does it poll?

I want to add in my driver the ability to turn a dusk till dawn feature on.

Thus want to poll / at set time send a command.

Any pointers appreciated. Examples even better.

Thanks

Dagaz

1 Like

It does nothing on its own — except saying that you need to implement the poll() command (just like how any other capability usually has specific commands or attributes it requires). Like other commands, this would generally be used by apps, often ones that specifically select for devices with this capability so that they know the command exists.

The "Poll these devices" action in Rule Machine is one of the few places I can think of where this command is used in a built-in app. (This will call the command once, unless your rule does a repeat or something else to create different behavior.) In many drivers, it's effectively the same as refresh(), which is a much more commonly implemented command. I suppose this capability might exist to let apps know that certain devices might require this on a regular basis for status updates — but, again, it doesn't do anything on its own.

2 Likes

Thank you. So in a driver there is no way to get it to repeat something every minute for example or at set times?

A Driver is a way to abstract overlapping features into a common set of mechanisms. Poll is an optional capability, just like switchLevel or motionSensor.. adding it to a driver means you intend to add code to be run when a Poll command is sent...

Sent by what and that's the thing I think you're missing. Generally you have an App that allows for devices to be selected that have a common Capability. Then all the selected devices from the larger list can have commands sent to them.

Again, the Poll capability is optional. By convention, ZWave + drivers don't have Poll, which prevents them from being selected inside the ZWave Poller App.

Can drivers repeat? Sure. Drivers for many of the cloud based services will poll on a schedule. Weather and WiFi Thermostats come quickly to mind as examples.

How the device is used drives the decision to put repeats into a Driver or an App.

4 Likes

That makes sense. Don't suppose you have any links to driver code with the schedule code?

Am quite new to coding hubitat. Started Friday lol but am enjoying.

Eg would like something to run every minute and round up ignoring the seconds then match against sunset to trigger a command.

Currently have rm to do it but would be neater to have the function in the driver with a preference.

Thanks for all the help and support

Dagaz

OK so had to change thought a bit.

now got it scheduling. need to test this evening but the logs show scheduled jobs

in case anyone else struggling this is code that basically sets a schedule based on a preference.
if the preference is on at 1 am it created a scheduled job for sunrise and sunset which then runs some commands.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.