trying to find a solution, energy saving idea

Begonnen von claudio, 21 November 2018, 23:11:58

Vorheriges Thema - Nächstes Thema

claudio

Hello

I'm looking for a solution to this problem :

I'm trying to launch an fhem command that put my router and modem to sleep when there is no more computers powered on in my lan. The typical use case is to save energy at night. The sleep should be triggered only between a time window, for example only between 01h00 and 08h00, when there is no more computers connected.

the part where I execute the sleep is already done and works with this command :
set router_api suspend

I use the WOL module to know if a machine is ON or OFF

I've already tried some ideas with notify or polling but it's more challenging that I though and I don't really understand perl, so it doesn't help. Also, the fact that most of the usefull information about fhem is not in english make it even harder to understand.

If I could "count" the WOL entries in "on"  state, that would take me a little further

May anyone could help me ?


MadMax-FHEM

#1
Hi,

I'm not sure what exactly the question is ;)

As I understood you are / would be able to shutdown/sleep your server!?

But you are having problems finding out about if there still are machines running that could use the server, right?!

There are several possibilities with fhem (and sure many more ;)  ):

you could use the presence device of fhem (for each Client Machine of interest) and put them together in a structure so you should be able to easily find out if all machines are up or down...

Another thing would be the nMap Module of fhem, there also should be seen which machines are online or off...

Sorry for the German links but you should also find most of it in the English commandref:

https://wiki.fhem.de/wiki/PRESENCE

https://wiki.fhem.de/wiki/Structure

https://forum.fhem.de/index.php?topic=57804.0



Just as another idea: I'm doing the same but I let my server decide by itself. So I have a freeNAS running on a HP Miniserver (40Watts) thats too much for let it run all the time and I don't really need it all the time (but I wanted to have a "real Server" ;)  with "lightsout etc.). So on the server a script is triggered by cron and checks for Clients (connected via samba or via Web or via ssh or ...) and if not so for three times in a row the server shuts down itself ;)


If that was not the question/problem: explain more precise or hopefully another guy is understanding better than me ;)


Regards, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)

claudio

It's not easy to clearly explain because english is not my native language  ;)

I run fhem on a intel nuc which is running 24h/24h. I don't want to put this nuc in sleep mode, it consume just about 5-6 watts @idle

I want to put to sleep another computer on my lan which is running as a router and my fiber modem. I have created a command in fhem that just do that nicely.

But I have difficulties to find out with fhem if there are clients (computers) in my lan which are online (which mean they need the router and modem to be available to access the internet).

I dont use the presence module, but WOL module. there is a state reading which I could use in order to know if a client is online or not. If there is none and the current time is between 01h00 and 08h00, execute the sleep command. The problem is I don't know how to program this.

Like you, right now, I have a script on my router that do this check and put it to sleep when needed but it's becoming harder to maintain with router's updates, so I want to put all the logic on fhem.


tomster

#3
Hi Claudio,

as Joachim said, your posting is not that precise...
Assuming you are having numerous PC's, smart-phones and even your FHEM-server running within you LAN/WiFi pretty much all around the clock, the shut-down of a router or modem (in case it is not a 40W-PC itself) won't save any considerable amout of energy at all. If it does: use a Raspberry Pi instead ;-)

If I did catch your drift correctly, what you are looking for is some kind of script that will not only put the router at rest for night-time but pretty much all of your machines not being used at that time of the day. Is this correct? Or is it the router only?

--edit--
Too slow ;-)

But again, if there are any computers on your network using/needing an connection to the internet at your (night-) time-window, your script won't be able to shut-down the router. Thus no ernergy saving.  ANY device is sending "another byte or two" (and if this is just a simple NTP-request) once in a while, so checking active connections is not the way to go; especially in a ~7 hour time-frame.

claudio

thanks for your quick response.

my router is a pc running opnsense with 3 network cards, so it can't be swapped with a raspi... and it consume much energy for nothing, that why I already made a bash script to put it in sleep mode at night.

I haven't any computer that need internet access at night, it's mostly for me, I regularly go to bed between 01h00 and 03h00 so I don't want the router going to sleep before I do... ??? just after I switch off my main computer.

MadMax-FHEM

#5
Ok.

I don't know the WOL Module but if you have some Reading there or some mechanism to find out that all the "clients" are "gone" then you could use DOIF for that.

But to be honest I'm not using DOIF myself.
I do most of the things using notify and at... ;)

But here is a link to the English version of the commandref and DOIF there:

https://www.fhem.de/commandref.html#DOIF

DOIF is a powerful fhem module that is also able to be "time controlled".
There should be some examples for that in the commandref (or Wiki https://wiki.fhem.de/wiki/DOIF / but is in German).

In principle it should be something like:


define doifShutdownRouterPC DOIF ([?01:00-08:00] and [WOL-Module:Clients] eq "allOff") (set router_api suspend)
attr doifShutdownRouterPC do always


As already told I don't use DOIF by myself AND you have to exchange the <[WOL-Module:Clients] eq "allOff"> by the condition that is the WOL-Module telling you that all the clients are "off"...

Another way (my way ;)  ) would be to trigger on "allOff" (so a notify "for" that) and then call a myUtils Sub (https://wiki.fhem.de/wiki/99_myUtils_anlegen).
There check for the time (and other things) and then shutdown the RouterPC.

You see there are many different ways to do ;)

And if your WOL-Module is not telling you "all clients off" then maybe have a look at nMap or Presence or you have to find another way to find out...
...or you already do have a clear condition that it is a good idea to shutdown the "RouterPC".

And then you might need some mechanism to wake up your "RouterPC" again... ;)

Good luck, Joachim
FHEM PI3B+ Bullseye: HM-CFG-USB, 40x HM, ZWave-USB, 13x ZWave, EnOcean-PI, 15x EnOcean, HUE/deCONZ, CO2, ESP-Multisensor, Shelly, alexa-fhem, ...
FHEM PI2 Buster: HM-CFG-USB, 25x HM, ZWave-USB, 4x ZWave, EnOcean-PI, 3x EnOcean, Shelly, ha-bridge, ...
FHEM PI3 Buster (Test)