Page 1 of 1

domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Tuesday 22 October 2024 22:21
by majsoft
Hello everyone, can I ask for help? I'm sorry, I'm using a translator, I can't speak English.
I am using the new Ubuntu, where I have Domoticz server and MagicMirror running.
after 15 minutes the PC goes to sleep and then wakes up with PIR (ESP8266).

After waking up, it takes a long time for the domoticz server to start working and sending Information to MagicMirror. I don't want to solve it with service monitor.

I would like to set up a script:

before putting the PC to sleep run "sudo service domoticz.sh stop"
after waking up the PC run "sudo service domoticz.sh start"
it works reliably in the command line, it just needs a password that I enter and it's ok.

I saw somewhere that something like this can be used, but I don't know exactly where to write, save and that it doesn't ask for a password. Would someone be willing to write the exact procedure where to write what and save? I found a lot of versions and maybe I got it wrong or the instructions are for older Ubuntu

First of all thank you very much for the joy and newbie to ubuntu.

Code: Select all

#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "$1" in
    pre)
            #code execution BEFORE sleeping/hibernating/suspending
    ;;
    post)
            #code execution AFTER resuming
    ;;
esac

exit 0

Image

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Tuesday 22 October 2024 22:33
by waltervl
You should not put Domoticz service to sleep, it should run 24/7. Why do you do that?

Put Domoticz on another system than your magic wand system if you want to switch that off for some reason.

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Tuesday 22 October 2024 22:40
by majsoft
I thought it would be ok, I found it in this script that works. I don't want to have the PC running 24/7, but only when he walks in front of the magic mirror and this script works immediately.

Image

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Tuesday 22 October 2024 22:54
by waltervl
You should have a Domoticz server running in your house all the time on another system (like a Raspberry Pi) and have the magic mirror connect to the Domoticz server when it needs to do that.

But when you only show weather data you don't need Domoticz to show that data....

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Tuesday 22 October 2024 23:13
by majsoft
yes, it would be better on another server, but I don't have this option. I use temperature sensors that are connected to ESP and it wirelessly sends data to domoticz and Magic mirror reads it using MMM-Domoticz-ext
I used it like this on one pc for a few years on a windows build, but I wanted to switch to ubuntu for a long time.

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Wednesday 23 October 2024 7:41
by waltervl
Domoticz needs to be on all day to store the temperature sensor data. And around midnight it needs to be on because then Domoticz executies it's database maintenance and optimization for long term data storage. So you better leave it on.... It is not designed to be switched on/off multiple times during the day.

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Wednesday 23 October 2024 8:21
by waltervl
Additional, most users here use an Raspberry Pi with another type of Linux than Ubuntu. Also we almost never stop our Domoticz application so it will be hard for us to help you.

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Saturday 26 October 2024 22:18
by majsoft
Hi, I've read a lot of scripting tutorials but to no avail. for now i leave it running 24/7 thanks.
I would turn off magicmirror itself, but PM2 does not work correctly on ubuntu.

Re: domoticz server ubuntu - run the script before sleeping and after waking up the PC

Posted: Monday 28 October 2024 11:17
by majsoft
Hi everyone, I'm not going to turn off the domoticz service, but I wanted to test it. If anyone finds it useful for Ubuntu 24.

I will then delete the sleep 60 command and the output to the file, I had time to find out if the necessary services are really turned off.

so my solution was as follows:

file creation

Code: Select all

sudo nano /usr/lib/systemd/system-sleep/wakeup.sh
the contents of the file

Code: Select all

#!/bin/sh

case $1/$2 in
pre/*)
echo "zastavuji domoticz......"
service domoticz.sh stop >> /home/meteo/vystup_off.txt
sleep 60
;;
post/*)
echo "spouštím domoticz......"
service domoticz.sh start >> /home/meteo/vystup_on.txt
sleep 0
;;
esac
permission settings

Code: Select all

sudo chmod a+x /usr/lib/systemd/system-sleep/wakeup.sh