Router or camera restart
Moderator: leecollings
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Router or camera restart
I have a wireless camera that sometimes loses connection to my network. I then want a dzVents script which turns off the camera via a Philips Smart Plug after 5 minutes without response and turns it on again after 1 minute. I use "System Alive Checker (ping)" to see if the camera is alive.
Can anyone help with a dzVents script?
Can anyone help with a dzVents script?
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Sure; what are the deviceNames, types and subtypes of the smart plug and camera (pinger device)?meyland wrote: ↑Thursday 23 July 2020 10:17 I have a wireless camera that sometimes loses connection to my network. I then want a dzVents script which turns off the camera via a Philips Smart Plug after 5 minutes without response and turns it on again after 1 minute. I use "System Alive Checker (ping)" to see if the camera is alive.
Can anyone help with a dzVents script?
Are you still on version 4.9971 as per your profile?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
System Alive Checker (ping) idx:365, type Lighting 2
Hue - Plug 4 - Camera04 idx: 367, type Light/Switch
Sorry, I'm on version 2020.2. Profile updated
Hue - Plug 4 - Camera04 idx: 367, type Light/Switch
Sorry, I'm on version 2020.2. Profile updated
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Script could look like
Code: Select all
scriptVar = 'cameraReset'
return
{
on =
{
devices =
{
365,
},
customEvents =
{
scriptVar,
}
},
data =
{
cameraState =
{
history = true,
maxItems = 1,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = scriptVar,
},
execute = function(dz, item)
local noResponseTimeout = 300
local cameraPower = dz.devices(367)
if item.isDevice then
dz.data.cameraState.add(item.state)
if item.state == 'Off' then
dz.emitEvent(scriptVar).afterSec(noResponseTimeout)
end
elseif item.isCustomEvent and ( dz.data.cameraState.getLatest().time.secondsAgo >= noResponseTimeout ) then
dz.log('Camera did not respond within ' .. noResponseTimeout .. ' seconds to pinger. I will restart it now', dz.LOG_DEBUG )
cameraPower.switchOff()
cameraPower.switchOn().afterSec(60)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
I have now tried the script. When the camera goes offline, then the script is triggered and after 5 minutes the script are triggered again (as expected), but the plug are not turned off. I've checked the device indexes and they are right. I've also updated my domoticz intallation to version 2020.2 (build12230) with dzVents version 3.0.11)
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Can you share what you see in the logfile?meyland wrote: ↑Friday 24 July 2020 20:23 I have now tried the script. When the camera goes offline, then the script is triggered and after 5 minutes the script are triggered again (as expected), but the plug are not turned off. I've checked the device indexes and they are right. I've also updated my domoticz intallation to version 2020.2 (build12230) with dzVents version 3.0.11)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
Of course
The log looks like this, but I can't see any errors:

Code: Select all
2020-07-24 20:37:41.150 (System Alive - Camera04) Lighting 2 (Ping - Camera04)
2020-07-24 20:37:41.180 Status: dzVents: Info: Handling events for: "Ping - Camera04", value: "Off"
2020-07-24 20:37:41.180 Status: dzVents: Info: cameraReset: ------ Start internal script: toggleCamera04: Device: "Ping - Camera04 (System Alive - Camera04)", Index: 370
2020-07-24 20:37:41.181 Status: dzVents: Debug: cameraReset: Processing device-adapter for Hue - Plug 4 - Camera04: Switch device adapter
2020-07-24 20:37:41.181 Status: dzVents: Info: cameraReset: ------ Finished toggleCamera04
2020-07-24 20:37:41.181 Status: EventSystem: Script event triggered: /usr/bin/dzVents/runtime/dzVents.lua
2020-07-24 20:39:41.218 Status: dzVents: Info: Handling Domoticz custom event for: "cameraReset"
2020-07-24 20:39:41.218 Status: dzVents: Info: cameraReset: ------ Start internal script: toggleCamera04: Custom event: "cameraReset"
2020-07-24 20:39:41.222 Status: dzVents: Debug: cameraReset: Processing device-adapter for Hue - Plug 4 - Camera04: Switch device adapter
2020-07-24 20:39:41.223 Status: dzVents: Info: cameraReset: ------ Finished toggleCamera04
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Indeed no errors but I expected another log line. I added some extra debug code. Can you please check and revert with all loglines ?
Code: Select all
scriptVar = 'cameraReset'
return
{
on =
{
devices =
{
365,
},
customEvents =
{
scriptVar,
}
},
data =
{
cameraState =
{
history = true,
maxItems = 1,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = scriptVar,
},
execute = function(dz, item)
local noResponseTimeout = 300
local cameraPower = dz.devices(367)
dz.log('isDevice: ' .. tostring(item.isDevice),dz.LOG_DEBUG)
dz.log('isCustomEvent: ' .. tostring(item.isCustomEvent),dz.LOG_DEBUG)
dz.log('secondsAgo >= ' .. noResponseTimeout .. ': ' .. tostring(dz.data.cameraState.getLatest().time.secondsAgo >= noResponseTimeout ),dz.LOG_DEBUG)
dz.utils.dumpTable(dz.data.cameraState)
if item.isDevice then
dz.data.cameraState.add(item.state)
if item.state == 'Off' then
dz.emitEvent(scriptVar).afterSec(noResponseTimeout)
end
elseif item.isCustomEvent and ( dz.data.cameraState.getLatest().time.secondsAgo >= noResponseTimeout ) then
dz.log('Camera did not respond within ' .. noResponseTimeout .. ' seconds to pinger. I will restart it now', dz.LOG_DEBUG )
cameraPower.switchOff()
cameraPower.switchOn().afterSec(60)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
I have checked and double checked the script and it is just as you wrote it, the only change I have made is the idx. The camera has idx 370 and the plug has idx 369
Code: Select all
scriptVar = 'cameraReset'
return
{
on =
{
devices =
{
370,
},
customEvents =
{
scriptVar,
}
},
data =
{
cameraState =
{
history = true,
maxItems = 1,
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
marker = scriptVar,
},
execute = function(dz, item)
local noResponseTimeout = 120
local cameraPower = dz.devices(369)
if item.isDevice then
dz.data.cameraState.add(item.state)
if item.state == 'Off' then
dz.emitEvent(scriptVar).afterSec(noResponseTimeout)
end
elseif item.isCustomEvent and ( dz.data.cameraState.getLatest().time.secondsAgo >= noResponseTimeout ) then
dz.log('Camera did not respond within ' .. noResponseTimeout .. ' seconds to pinger. I will restart it now', dz.LOG_DEBUG )
cameraPower.switchOff()
cameraPower.switchOn().afterSec(60)
end
end
}
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Maybe you misunderstood. In my last post I added a script with some extra debug code in. Can you try that one and show all resulting loglines?
That will help me to identify the issue.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
Yes, you are right, I misunderstood you, sorry. I have now tried the new script, but it only gave this in the log filen:
Could it be a permissionproblem in the filesystem?
Code: Select all
2020-07-24 21:34:54.185 (System Alive - Camera04) Lighting 2 (Ping - Camera04)
2020-07-24 21:34:54.215 Status: dzVents: Info: Handling events for: "Ping - Camera04", value: "Off"
2020-07-24 21:34:54.215 Status: dzVents: Info: cameraReset: ------ Start internal script: toggleCamera04: Device: "Ping - Camera04 (System Alive - Camera04)", Index: 370
2020-07-24 21:34:54.215 Status: dzVents: Debug: cameraReset: Processing device-adapter for Hue - Plug 4 - Camera04: Switch device adapter
2020-07-24 21:34:54.215 Status: dzVents: Debug: cameraReset: isDevice: true
2020-07-24 21:34:54.215 Status: dzVents: Debug: cameraReset: isCustomEvent: nil
2020-07-24 21:34:54.216 Status: dzVents: Info: cameraReset: ------ Finished toggleCamera04
regards
Peter
Peter
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
Just some extra info. All my existing dzVents scripts are working as expected
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
I guess not because you should then see error messages in the log.
I cannot tell what your issue is based on these loglines but the added debuglines must produce many more lines in the log. I tested it on my system and you should see something like below.
Are you logging to an OS file ?
If not please do so to be able to debug this
The domoticz logfile location and other settings are defined in /etc/init.d/domoticz.sh
the relevant settings are in set to the DAEMON_ARGS var.
with an editor of choice
Code: Select all
DAEMON_ARGS="$DAEMON_ARGS -log /var/log/domoticz.log" # or any other OS file
#DAEMON_ARGS="$DAEMON_ARGS -loglevel normal,status,error, debug" # debug disabled for now
DAEMON_ARGS="$DAEMON_ARGS -loglevel normal,status,error" # these loglevels will make it to the logfile
#DAEMON_ARGS="$DAEMON_ARGS -debuglevel normal,hardware,received,webserver,eventsystem,python,thread_id"
Code: Select all
sudo systemctl daemon-reload
sudo service domoticz stop
sudo service domoticz start
sudo tail -f /var/log/domoticz.log
- Spoiler: show
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
I'm logging to a OS file in /var/log and the logfile does not contain any errors. I think there are som errors in my installation of Domoticz, but I can't find id.
I think the reset script dies at the line where "secondsAgo >= 20: true" should be printed without any error messages.
I think the reset script dies at the line where "secondsAgo >= 20: true" should be printed without any error messages.
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
Strangemeyland wrote: ↑Friday 24 July 2020 22:24 I'm logging to a OS file in /var/log and the logfile does not contain any errors. I think there are som errors in my installation of Domoticz, but I can't find id.
I think the reset script dies at the line where "secondsAgo >= 20: true" should be printed without any error messages.

The first try it passed this and emitted the event.
What happens if you do
Code: Select all
cd <domoticz dir>
sudo ./updatebeta
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 35
- Joined: Wednesday 03 January 2018 16:39
- Target OS: Linux
- Domoticz version: 2020.2
- Location: Denmark
- Contact:
Re: Router or camera restart
I dont have a updatebeta in my domoticz folder. I have compiled domoticz today from github, so I think I'm on the latest build 
Could it be something with dz.data or maybe cameraState? Are those datatypes saved ind the database or in th filesystem? I remember that I have some problems with the file scripts/dzVents/domoticzData.lua, because it not was owned by domoticz

Could it be something with dz.data or maybe cameraState? Are those datatypes saved ind the database or in th filesystem? I remember that I have some problems with the file scripts/dzVents/domoticzData.lua, because it not was owned by domoticz
regards
Peter
Peter
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Router or camera restart
If you compile locally you will find the updatebeta script in the git source directory.meyland wrote: ↑Friday 24 July 2020 23:03 I dont have a updatebeta in my domoticz folder. I have compiled domoticz today from github, so I think I'm on the latest build
Could it be something with dz.data or maybe cameraState? Are those datatypes saved ind the database or in th filesystem? I remember that I have some problems with the file scripts/dzVents/domoticzData.lua, because it not was owned by domoticz
Just copy it to your domoticz folder, copy your current domoticz binary to domoticz.local, execute sudo ./updatebeta and copy domoticz.local back to domoticz.
This will ensure you have all the supporting files and directories versions aligned with your domoticz binary version.
I use below script to stay aligned
Code: Select all
#!/bin/bash
basedir="/usr/local/domotica/git/"
if [ $# -eq 0 ] ; then
clear
echo "No arguments supplied"
echo
echo default base directory is /usr/local/domotica/git
echo
echo Usage:
echo
echo ${0##*/} beta .................. get all from "$HOSTNAME:$basedir"beta
echo ${0##*/} development ........... get all from "$HOSTNAME:$basedir"development
echo ${0##*/} beta DEV ............. get all from "DEV:$basedir"beta
echo
exit 1
fi
from=${1:-"beta"}
sourceSystem=${2:-"$HOSTNAME"}
target=${3:-"/opt/domoticz"}
source=${4:-"$sourceSystem:$basedir$from"}
skip=${5:-"noskip"}
currentDir=$PWD
#
# Root required
#
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
while true; do
read -p "Do you want to copy from $source to $target? (yn) " yn
case $yn in
[JjYy]* ) echo OK
break;;
[Nn]* ) exit;;
* ) echo "No valid input. Please try again";;
esac
done
cd $target
echo Stop domoticz
service domoticz stop
cd $target
echo Create tar with executable database etc.
tar cazf domoticz.tar.gz $(readlink -e domoticz *.txt *.sh *.pem *.log update* dzVents/* scripts/*) 2>/dev/null
echo $(tar -tzf domoticz.tar.gz | wc -l) files archived
echo rsync $source/domoticz domoticz
rsync -I $source/domoticz $target/domoticz
if test $skip = 'skip' ; then
echo skipping the rsync steps
else
echo rsync $source/www/* to $target/www
rsync -rI $source/www/ $target/www
echo rsync $source/dzVents/* to $target/dzVents
rsync -rI $source/dzVents/ $target/dzVents
echo rsync $source/Config/* to $target/Config
rsync -rI $source/Config/ $target/Config
echo rsync $source/scripts/lua to $target/scripts/lua
rsync -rI $source/scripts/lua/ $target/scripts/lua
rsync -rI $source/scripts/lua/xmlhandler/ $target/scripts/lua/xmlHandler
fi
echo start domoticz
service domoticz start
$target/domoticz --help | grep Giz
cd $currentDir
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 46
- Joined: Friday 12 February 2016 20:58
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.4834
- Contact:
Re: Router or camera restart
I have the same problem with a Foscam camera, so this is a solution, thanks for that.
But on the website https://www.domoticz.com/wiki/System_Al ... ker_(Ping) at the bottom is the following text
"When running Domoticz without root (recommended), you need to add the correct socket capabilities for this to function properly (otherwise it will fail silently!): "
I don't understand, who can explain this to me ??
Or what is the correct rule for this?
$ sudo setcap cap_net_raw = + eip path_to_domoticz_executable
Thanks for the help.
Cobra045
But on the website https://www.domoticz.com/wiki/System_Al ... ker_(Ping) at the bottom is the following text
"When running Domoticz without root (recommended), you need to add the correct socket capabilities for this to function properly (otherwise it will fail silently!): "
I don't understand, who can explain this to me ??
Or what is the correct rule for this?
$ sudo setcap cap_net_raw = + eip path_to_domoticz_executable
Thanks for the help.
Cobra045
Who is online
Users browsing this forum: No registered users and 0 guests