commit - /dev/null
commit + 3baf40e13bf91a7ee8b1257ec20ebec4333a1a6e
blob - /dev/null
blob + c5a7e893fe36952c25c52dee838729307aabe363 (mode 755)
--- /dev/null
+++ tibber.pl
+#!/usr/bin/env perl
+use 5.024;
+use strict;
+use warnings;
+use autodie;
+use Getopt::Long;
+use HTTP::Tiny;
+use JSON::PP;
+use Data::Dumper;
+
+my $TOKEN = "";
+
+my $http = HTTP::Tiny->new;
+my %HEADERS = ("Content-Type" => "application/json", "Authorization" => "Bearer $TOKEN");
+my $uri = "https://api.tibber.com/v1-beta/gql";
+
+my $request = HTTP::Tiny->new('default_headers' => \%HEADERS);
+my $json = JSON::PP->new;
+
+my $body = $json->encode({query => "{viewer{homes{currentSubscription{priceInfo{current{total energy tax startsAt} today{total energy tax startsAt} tomorrow{total energy tax startsAt}}}}}}"});
+#print "$body\n";
+
+my $response = $request->post($uri, {'content' => $body});
+#print "$response->{'status'} $response->{'reason'}\n";
+#print "$response->{'content'}\n";
+my $data = $json->decode($response->{'content'})->{'data'}->{'viewer'}->{'homes'}[0]->{'currentSubscription'};
+
+print "*** priceInfo ***\n";
+print "current: ";
+if (!length $data->{'priceInfo'}->{'current'}) {
+ print "price not set\n";
+} else {
+ print "$data->{'priceInfo'}->{'current'}->{'total'} (Energy: $data->{'priceInfo'}->{'current'}->{'energy'}; Tax: $data->{'priceInfo'}->{'current'}->{'tax'})\n";
+ #print Dumper $data->{'priceInfo'}->{'current'};
+}
+
+print "today: ";
+if (!length $data->{'priceInfo'}->{'today'}[0]) {
+ print "price not set\n";
+} else {
+ print "$data->{'priceInfo'}->{'today'}[0]->{'total'} (Energy: $data->{'priceInfo'}->{'today'}[0]->{'energy'}; Tax: $data->{'priceInfo'}->{'today'}[0]->{'tax'})\n";
+ #print Dumper $data->{'priceInfo'}->{'today'}[0];
+}
+
+print "tomorrow: ";
+if (!length $data->{'priceInfo'}->{'tomorrow'}[0]) {
+ print "price set at 13:00\n";
+} else {
+ print "$data->{'priceInfo'}->{'tomorrow'}[0]->{'total'} (Energy: $data->{'priceInfo'}->{'tomorrow'}[0]->{'energy'}; Tax: $data->{'priceInfo'}->{'tomorrow'}[0]->{'tax'})\n";
+ #print Dumper $data->{'priceInfo'}->{'tomorrow'}[0];
+}