VOLTTRON Csv Driver Agent scheduled task

40 Views Asked by At

Is there a way I could call an agent to start a certain time every day?

For example I would like to create an agent that creates an API call at 4AM everyday (to openweathermap) to check the hourly forecast for the day. Basically if the hourly forecast yield's ideal conditions the agent could do building pre-cooling... Else if the hourly weather conditions starting at 4AM through the afternoon hours are not ideal the agent would not do anything (pass). Hopefully that makes sense! just one API call at 4AM to make some decisions, else pass.

Also having some extra logic if current time equals a winter month to pass as well. datetime.datetime.now().month?

#@Core.receiver("onstart")
def onstart(self, sender, **kwargs):
    """
    This is method is called once the Agent has successfully connected to the platform.
    This is a good place to setup subscriptions if they are not dynamic or
    do any other startup activities that require a connection to the message bus.
    Called after any configurations methods that are called at startup.

Usually not needed if using the configuration store.
"""
# Every 120 seconds, ask the core agent loop to run the actuate point method with no parameters
self.core.periodic(600, self.actuate_point)

def actuate_point(self): """ Request that the Actuator set a point on the CSV device """

1

There are 1 best solutions below

0
On

You could use the built in cron scheduler (https://volttron.readthedocs.io/en/main/developing-volttron/developing-agents/agent-development.html?highlight=cron#periodics-and-scheduling). This uses the same style of cron that your linux system uses. Put the following decorator on your function and the specified cron will just work.

from volttron.platform.scheduling import cron

@Core.schedule(cron('0 1 * * *'))
def cron_function(self):
   print("this is a cron-scheduled function")

Some useful crons are located https://crontab.guru/examples.html