To check if anybody is Home or not make a Dummy Switch an look at the IDX Number
now login to SSH an add a Script.
cd /home/pi/domoticz/scripts
sudo nano ping_by_ip.pl
now past the follow script at the file an change the IP and IDX Number
# Array of (device idx, IP)
my %IP=(24=>'192.168.178.23', # TV
23=>'192.168.178.32', # Me
25=>'192.168.178.30'); # Tablet
Code: Select all
#!/usr/bin/perl
use v5.14;
use LWP::Simple; # From CPAN
use JSON qw( decode_json ); # From CPAN
use Data::Dumper; # Perl core module
use strict; # Good practice
use warnings; # Good practice
use utf8;
use feature qw< unicode_strings >;
# Configuration section, please update to your values
my $domoticz = "127.0.0.1:8080"; # ip and port of your Domoticz server
my $domo_cmd = "http://$domoticz/json.htm?type=devices&filter=all&used=true&order=Name";
# Array of (device idx, IP)
my %IP=(24=>'192.168.178.23', # TV
23=>'192.168.178.32', # Me
25=>'192.168.178.30'); # Tablet
my $debug=0;
# Get the JSON url
my $json = get( $domo_cmd );
die "Could not get $domo_cmd!" unless defined $json;
# Decode the entire JSON
my $decoded = JSON->new->utf8(0)->decode( $json );
my @results = @{ $decoded->{'result'} };
#Put JSON switch and status in a Table
my @tab;
foreach my $f ( @results ) {
if ($f->{"SwitchType"}) {
$tab[$f->{"idx"}]=$f->{"Status"};
}
}
# Now we go all over the IP to check if they are alive
HINT: STRG is the german Layout for US it is CTRL
now add a crontab with
crontab -e
add in the last line
*/1 * * * * /home/pi/domoticz/scripts/ping_by_ip.pl 2>&1 >> /dev/null
and save with STRG + O and Exit with STRG + X
Now you can using the switch at Domoticz for Programming Actions...
