Script runs every 5 seconds instead of once a day

Moderator: leecollings

Post Reply
mdo82
Posts: 9
Joined: Tuesday 17 November 2015 21:26
Target OS: -
Domoticz version:
Location: The Netherlands
Contact:

Script runs every 5 seconds instead of once a day

Post by mdo82 »

I have a script to indicate whether or not waste is being collected.
However, I've set up my main service to update every 24 hours, but it's now running every 5 seconds.

Could I have made a mistake somewhere?

Image

Image

The code i used:

Code: Select all

week    = tonumber (os.date( "%V"))
dag      = tostring(os.date("%a"));
status   = tonumber(otherdevices_svalues['Afval'])
print('script bin_selector executed')

commandArray = {}
print ('Dag=  '..dag)
if (dag=='Sat' or dag=='Sun'  ) then
   weekend = true; weekdag = false
end 

if (dag=='Mon' or dag=='Tue' or dag=='Wed' or dag=='Thu' or dag=='Fri') then
   weekend = false ; weekdag = true 
end

--Bepalen morgen rest   
if(week==39 and dag=='Sun' or week==41 and dag=='Sun' or week==43 and dag=='Sun' or week==45 and dag=='Sun' or week==47 and dag=='Sun' or week==49 and dag=='Sun' or week==51 and dag=='Sun') then
     morgenrest = true; rest = false; morgengft = false; gft = false; morgenpapier = false; papier = false; plastic = false; niets = false
print ('morgen grijze container')
end

--Bepalen rest   
if(week==39 and dag=='Mon' or week==41 and dag=='Mon' or week==43 and dag=='Mon' or week==45 and dag=='Mon' or week==47 and dag=='Mon' or week==49 and dag=='Mon' or week==51 and dag=='Mon') then
      morgenrest = false; rest = true; morgengft = false; gft = false; morgenpapier = false; papier = false; plastic = false; niets = false
print ('vandaag grijze container')
end

--Bepalen morgen gft   
if(week==40 and dag=='Sun' or week==42 and dag=='Sun' or week==44 and dag=='Sun' or week==46 and dag=='Sun' or week==48 and dag=='Sun' or week==50 and dag=='Sun' or week==51 and dag=='Fri') then
     morgenrest = false; rest = false; morgengft = true; gft = false; morgenpapier = false; papier = false; plastic = false; niets = false
print ('morgen groene container')
end

--Bepalen gft 
if(week==40 and dag=='Mon' or week==42 and dag=='Mon' or week==44 and dag=='Mon' or week==46 and dag=='Mon' or week==48 and dag=='Mon' or week==50 and dag=='Mon' or week==51 and dag=='Sat') then
      morgenrest = false; rest = false; morgengft = false; gft = true; morgenpapier = false; papier = false; plastic = false; niets = false
print ('vandaag groene container')
end

if (morgenrest and weekend and dag) then
      commandArray ['UpdateDevice']= '19|1|Morgen Grijze container'
end

if (rest and weekdag and dag) or (rest and weekend and dag) then
      commandArray ['UpdateDevice']= '19|1|Vandaag Grijze container'
end

if (morgengft and weekend and dag) then
      commandArray ['UpdateDevice']= '19|1|Morgen Groene container'
end

if (gft and weekdag and dag) then
      commandArray ['UpdateDevice']= '19|1|Vandaag Groene container'
end

return commandArray
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: Script runs every 5 seconds instead of once a day

Post by pj-r »

You'll have to check what is triggering your script. For me it looks like your script is triggered on every event happening.

Lua scripts will normally get executed:
- time (once a minute)
- device (every time some device state changes)
- or both

So put the script in time mode and add check for what time it is.
domo_event_trigger.png
domo_event_trigger.png (8.43 KiB) Viewed 2246 times
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
mdo82
Posts: 9
Joined: Tuesday 17 November 2015 21:26
Target OS: -
Domoticz version:
Location: The Netherlands
Contact:

Re: Script runs every 5 seconds instead of once a day

Post by mdo82 »

I have to go for a while to find out how exactly that works :)
zicht
Posts: 251
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Script runs every 5 seconds instead of once a day

Post by zicht »

or you can use :

Code: Select all

time = os.date("*t") -- put the time/date table in variable time
if (time.hour==7 or time.hour==19) and time.min==0 then 



	<your script> 
 
 
 
 end
this way the script runs but the code after "then" will only run your code at 7AM and 7PM
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
mdo82
Posts: 9
Joined: Tuesday 17 November 2015 21:26
Target OS: -
Domoticz version:
Location: The Netherlands
Contact:

Re: Script runs every 5 seconds instead of once a day

Post by mdo82 »

In this topic: http://www.domoticz.com/forum/viewtopic.php?t=5156
I reading the following code:

Code: Select all

time = os.date("*t")
commandArray = {}
if (timeofday['Sunrise']) then
        commandArray['Variable:Time-Variable']='Morning'
        print("Time set to Morning")
end
if (time.hour >= 12) then
        commandArray['Variable:Time-Variable']='Afternoon'
        print("Time set to Afternoon")
end
if (timeofday['Sunset']) then
        commandArray['Variable:Time-Variable']='Evening'
        print("Time set to Evening")
end
if (time.hour >= 22) then
        commandArray['Variable:Time-Variable']='Night'
        print("Time set to Night")
end
return commandArray
However, it is split into multiple options.
Now I tried this in my code, but then get error messages.
How do I incorporate this in my code?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest