Skip to content

Commit fcc1f99

Browse files
committed
Add irssi script
Join #revspace on libera.chat for a demo :)
1 parent 87c7204 commit fcc1f99

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

irssi-script.pl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
$_{target} =~ '^#revspace|^[^#+&]' or return;
2+
3+
sub sensor {
4+
my ($topic) = @_;
5+
my $pid = open my $pipe, '-|', qw(timeout 1 mqtt-simple -1 -h mosquitto.space.revspace.nl -s), $topic;
6+
return (split " ", readline $pipe)[0] + 0;
7+
}
8+
9+
sub text {
10+
my ($topic) = @_;
11+
my $pid = open my $pipe, '-|', qw(timeout 1 mqtt-simple -1 -h mosquitto.space.revspace.nl -s), $topic;
12+
my $value = readline $pipe;
13+
chomp $value;
14+
return $value;
15+
}
16+
17+
sub tijd {
18+
my ($topic) = @_;
19+
20+
use DateTime::Format::ISO8601;
21+
my $dt = DateTime::Format::ISO8601->parse_datetime(text($topic));
22+
return $dt->strftime("%Y-%m-%d %H:%M");
23+
}
24+
25+
sub station {
26+
my ($id) = @_;
27+
28+
return sprintf "%s: %s °C op 2 meter, %s °C op 10 cm, %s% RH \cC14(gemeten op %s)",
29+
text(sprintf "revspace/sensors/knmi/%s/stationname", $id),
30+
sensor(sprintf "revspace/sensors/knmi/%s/temperature-2m", $id),
31+
sensor(sprintf "revspace/sensors/knmi/%s/temperature-10cm", $id),
32+
sensor(sprintf "revspace/sensors/knmi/%s/humidity", $id),
33+
tijd(sprintf "revspace/sensors/knmi/%s/measured-at", $id);
34+
}
35+
36+
if(index($_{msg}, '-v') != -1) {
37+
reply sprintf "%s", station("6215"), # Voorschoten
38+
reply sprintf "%s", station("6344"), # Rotterdam The Hague Airport
39+
reply sprintf "%s", station("6330"); # Hoek van Holland
40+
} else {
41+
reply sprintf "%s", station("6215"); # Voorschoten
42+
}

0 commit comments

Comments
 (0)