Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
Très bizarre en effet,
Essayes avec ca en changeant mon ip par celle que tu veux pinger et celle de Domoticz aussi à changer
C'est le même script qui fonctionne chez moi et que je te remets ici pour que tu fasse un copier /coller
#!/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 = "192.168.1.81: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=(86=>'192.168.1.66'); # Ip 3
my $debug=1;
# 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
foreach my $k (keys %IP) {
my $ip=$IP{$k};
my $res=system("sudo ping $ip -w 3 2>&1 > /dev/null");
#print $k." ".$res."\n";
if (($res==0)&&($tab[$k] eq 'Off')) {
#If device answered to ping and device status is Off, turn it On in Domoticz
if ($debug) {print "$k is On\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=On"`;
} elsif (($res!=0)&&($tab[$k] eq 'On')) {
#If device did NOT answer to ping and device status is On, turn it Off in Domoticz
if ($debug) {print "$k is Off\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=Off"`;
} else {
if ($debug) {print "do nothing: $k is ".$tab[$k]."\n";}
}
}
Raspberry pi 3, Dongle RfxCom et Zigate +, plugin de pipiche, Volets Roulants profalux, contrôle d'éclairage, détecteurs de présence, alarme incendie, pilotage livebox ...
Objectif : WAF > 1
die "Could not get $domo_cmd!" unless defined $json;
Rpi B avec Domoticz + RFXcom 433.92Mhz + Carte 8 relais sur Gpio
+ 9 Module 1000W DI.O+ 1 Multi modules DI.O + 2 Détecteur de fumée sans fil FA20RF
Rpi B avec squeezlite + Webcam sous Motion
Rpi B avec squeezlite
Rpi B avec Raspbmc + Squeelite pour xbmc
j'ai désinstallé et reinstallé libjson-perl mais toujour la même erreur ligne 19.....
et pas de message d'erreur. désolé
Rpi B avec Domoticz + RFXcom 433.92Mhz + Carte 8 relais sur Gpio
+ 9 Module 1000W DI.O+ 1 Multi modules DI.O + 2 Détecteur de fumée sans fil FA20RF
Rpi B avec squeezlite + Webcam sous Motion
Rpi B avec squeezlite
Rpi B avec Raspbmc + Squeelite pour xbmc
#!/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 = "192.168.5.72: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=(41=>'192.168.5.19', # Ip 1
44=>'192.168.5.21', # Ip 2
681=>'192.168.5.24'); # Ip 3
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
foreach my $k (keys %IP) {
my $ip=$IP{$k};
my $res=system("sudo ping $ip -w 3 2>&1 > /dev/null");
#print $k." ".$res."\n";
if (($res==0)&&($tab[$k] eq 'Off')) {
#If device answered to ping and device status is Off, turn it On in Domoticz
if ($debug) {print "$k is On\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=On"`;
} elsif (($res!=0)&&($tab[$k] eq 'On')) {
#If device did NOT answer to ping and device status is On, turn it Off in Domoticz
if ($debug) {print "$k is Off\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=Off"`;
} else {
if ($debug) {print "do nothing: $k is ".$tab[$k]."\n";}
}
}
donc un sudo chmod 777
dans cd /home/pi/domoticz/scripts
Rpi B avec Domoticz + RFXcom 433.92Mhz + Carte 8 relais sur Gpio
+ 9 Module 1000W DI.O+ 1 Multi modules DI.O + 2 Détecteur de fumée sans fil FA20RF
Rpi B avec squeezlite + Webcam sous Motion
Rpi B avec squeezlite
Rpi B avec Raspbmc + Squeelite pour xbmc
J'utilise un script lua, comme décrit sur le Wiki, mais un peu adapté pour les différents téléphones/machines du réseau.
Il faut un périphérique virtuel pour chacun, et connaître leur adresse IP, par configuration du routeur.