Quick help for short code line

hello to everyone here,

i would like to automatically switch off the wifi after a certain time at night if no user is connected anymore.
I inserted the following code (which btw I found in this forum) in the “on event” field of a schedule task but it’s not working:

if ( ([/interface wireless monitor wlan1 as-value once]->“connected-clients”)=0 ) do={/interface wireless disable wlan1}

I also tried with “authenticated-clients” and “registered-clients” but no one is doing the job. I guess I have an error in the code , so I would be very thankful if someone who is familiar with the script language could give a look!

(btw: the task to switch on the wifi in the morning is working fine which the following line: /interface wireless enable wlan1)

:if ( [/interface wireless registration-table print as-value count-only]=0 ) do={/interface wireless disable wlan1} else={}

unfortunately it’s simply not working

I even tried with =1 (while I was the only connected) but no reaction

strangely (as it worked before!) this morning even the activation of the wifi did not work… morning for testing purpose then I set the interval to 1 minute and it worked. for my activation once a day I set the time to 09:00 and the interval to 00:00:00 as it is the 24 hours interval right?)

interval should be “1d 00:00:00” to work properly

Thanks for the hint with the 1d … it works!!

Regarding the other code line there is something fundamentally wrong or at least strange!

It’s only doing it’s job if I put a ! in front of the =0, so !=0 (or whatever other number), for example:

if ( [(/interface wireless registration-table print as-value count-only)] !=0 ) do={/interface wireless disable wlan1} else={}
this disables the wifi whenever I’m connected or not!

if ( [(/interface wireless registration-table print as-value count-only)] !=1 ) do={/interface wireless disable wlan1} else={}
so with value 1 while I’m connected alone on the wifi it should not disable right? but it does so…

did you make tests on your own? maybe a bug in the software somehow?

thanks again a lot for your time!

=0 : mean false or wireless registration table is empty
both are same
other solutions
<=0 : mean less or equal zero
!=0 : mean any number except zero
!=1 : mean any number except one

0 : mean greater than zero.
etc.

yes I know but thank you!

how come it’s not working with =0 then??

can you test it please on your own mikrotik for a second?

yes
problem fixed by remove ( ) from script
f.png

sorry I don get it…

a parte the additional code added there, the basic line is just the same… and ( ) still there…?!

Anyone else could give me a short help?

This script does work fin on my hap lite

:if ([/interface get  wlan1 disabled ]=false && [/interface wireless registration-table print as-value count-only]=0) do={
	:log info message="No more clients, shutting down interface"
	/interface wireless disable wlan1}

Schedule it to run every 5m and it should shutdown the interface after max 5 min of last client leaving.

PS I did add a test to see if interface was enabled. No need to shutdown it more than once.

great it works perfectly, thank you so much!!