Setting task interval by mqtt or http

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
WaTho
New user
Posts: 4
Joined: 04 Jul 2019, 10:29

Setting task interval by mqtt or http

#1 Post by WaTho » 17 May 2021, 17:24

Hi,

is it possible to set the task interval by mqtt or http command? Usually i need the measurements once a hour, but sometimes i like to set a shorter interval. I can change the interval for every device in the web-interface, but it would be easier to use commands. Also it would then possible to automate it, e.g. "set the measurement interval to 5 minutes for the next hour and then back to the old value".

Thanks in advance.

User avatar
Ath
Normal user
Posts: 3419
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Setting task interval by mqtt or http

#2 Post by Ath » 17 May 2021, 17:40

You can force an extra interval by issuing the 'TaskRun' command. You can send that command either from MQTT or HTTP, best would be to add an event in the rules

Code: Select all

on TriggerTaskNow do
  if %eventvalue1% > 0
    TaskRun,%eventvalue1%
  endif
endon
this would need a command like `event,TriggerTaskNow=3` when the intended task to trigger/run is 3.

This will run it only once.
If you want to change the frequency you would have to do something with a LoopTimerSet command. Please be aware that the normal interval will still be running as well.

NB: There is no command available to change the interval of a task.
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 3419
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Setting task interval by mqtt or http

#3 Post by Ath » 17 May 2021, 21:38

I had a little more time now, so I took a stab at that repeating option:

Code: Select all

on TriggerTaskLoop do // argument 1 = task number, argument 2 = interval in seconds, minimum = 10 else the loop is stopped
  if %eventvalue1% > 0
    if %eventvalue2% >= 10
      Let,88,%eventvalue1% // 88 is just a random variable number
      LoopTimerSet,1,%eventvalue2% // Start repeating timer
    else
      LoopTimerSet,1,0 // Stop timer
    endif
  endif
endon

on rules#timer=1 do
  if %v88% > 0 // Valid?
    TaskRun,%v88%
  endif
endon
This way you can send from a couple of sources (Tools page, html, MQTT) the command 'event,TaskTimerLoop=3,600' and this will trigger task# 3 every 10 minutes.

Disclaimer: Untested code 8-)
/Ton (PayPal.me)

WaTho
New user
Posts: 4
Joined: 04 Jul 2019, 10:29

Re: Setting task interval by mqtt or http

#4 Post by WaTho » 18 May 2021, 13:14

Thank you very much for your answers.

I have implemented your first version. For now the automation takes place in the hub. There i have a script which runs the http-command every 10 seconds. It would be better, if the repeating takes place on the microcontroller to reduce the traffic. So i will try your new version too.

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests