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

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
majsoft
Posts: 5
Joined: Tuesday 22 October 2024 20:54
Target OS: Linux
Domoticz version: 2024.7
Location: Česko
Contact:

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

Post 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
Attachments
Snímek2.jpg
Snímek2.jpg (319.2 KiB) Viewed 1021 times
MagicMirror2 + Domoticz + Ubuntu 24 04 1 LTS + HP prodesk 400 g3 mini
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
majsoft
Posts: 5
Joined: Tuesday 22 October 2024 20:54
Target OS: Linux
Domoticz version: 2024.7
Location: Česko
Contact:

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

Post 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
Attachments
snimek3.jpg
snimek3.jpg (57.98 KiB) Viewed 1011 times
MagicMirror2 + Domoticz + Ubuntu 24 04 1 LTS + HP prodesk 400 g3 mini
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
majsoft
Posts: 5
Joined: Tuesday 22 October 2024 20:54
Target OS: Linux
Domoticz version: 2024.7
Location: Česko
Contact:

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

Post 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.
MagicMirror2 + Domoticz + Ubuntu 24 04 1 LTS + HP prodesk 400 g3 mini
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5397
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
majsoft
Posts: 5
Joined: Tuesday 22 October 2024 20:54
Target OS: Linux
Domoticz version: 2024.7
Location: Česko
Contact:

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

Post 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.
MagicMirror2 + Domoticz + Ubuntu 24 04 1 LTS + HP prodesk 400 g3 mini
majsoft
Posts: 5
Joined: Tuesday 22 October 2024 20:54
Target OS: Linux
Domoticz version: 2024.7
Location: Česko
Contact:

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

Post 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
MagicMirror2 + Domoticz + Ubuntu 24 04 1 LTS + HP prodesk 400 g3 mini
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests