it did not work. but i have a solution.
I’m setting up some variables, dummybuttons, variable devices, a dummyswitch and than i use a external script to update the variables. a simple rule trigger every hour the external script to update prices.
http://fs1.directupload.net/images/150217/zrcm2lkz.jpg
@leader21 said:
cool idea!! ![fuelpump :fuelpump:](../../plugins/nodebb-plugin-emoji-one/static/images/26fd.png)
would be nice if you share your script with us
i post it later when i’m @ home
edit:
my php script (the reason why i’m using the lang is i could be write fast working code - normally is prefer bash)
<?php
error_reporting(E_ALL);
$lat = "48.2665886";
$lon = "11.0035739";
$radius = "5"; // distance km
$sorte = "e5"; // e5, e10, diesel
$apikey = "00000000-0000-0000-0000-000000000000"; // https://creativecommons.tankerkoenig.de/ register is needed to use the service
$temp_file = "benzin.txt";
$PIMATIC_USER="admin";
$PIMATIC_PASS="user";
$PIMATIC="192.168.170.40:80";
$reloadtime = 360; // reload data every 360 seconds otherwise use the cache file
$reload = true;
// array ( 'id' => 'pimatic-variable', 'id' => 'pimatic-variable');
$ids = array( '9692e1a7-bddc-4c76-a434-e01d5059fc5c' => 'benzin-preis-bk-e5',
'70c31b94-7de6-43e3-989f-23dfc4b3fb63' => 'benzin-preis-shell-e5',
'bcdca275-e8e1-474c-a2d1-9e83d6286144' => 'benzin-preis-aral-e5',
'ba54c57b-00a5-4548-9ee1-de6f05bf18af' => 'benzin-preis-vmarkt-e5',
'3798cb9f-f6e4-448f-b3fc-b80388fa11bc' => 'benzin-preis-ran-e5'
);
$debug = false;
if (file_exists($temp_file))
{
$changetime = filemtime("benzin.txt");
$diff = time() - $changetime;
if ($diff <= $reloadtime)
$reload = false;
}
if ($reload)
{
$data = file_get_contents("https://creativecommons.tankerkoenig.de/json/list.php?lat=$lat&lng=$lon&rad=$radius&sort=price&type=$sorte&apikey=$apikey");
file_put_contents($temp_file, $data);
}
$json = json_decode(file_get_contents($temp_file));
if ($debug == true)
print_r($json->{"stations"});
else
{
for ($i = 0; $i < count($json->{"stations"}); $i++)
{
if (array_key_exists($json->{"stations"}[$i]->{"id"}, $ids))
{
$variable = $ids[$json->{"stations"}[$i]->{"id"}];
$data = $json->{"stations"}[$i]->{"price"};
// trim the last digit 1.309 to 1.30
$preis = substr($data, 0, strpos($data, ".")) . "." . substr($data, strpos($data, ".")+1, strpos($data, ".")+1);
update($PIMATIC, $PIMATIC_USER, $PIMATIC_PASS, $variable, $preis);
}
}
}
update($PIMATIC, $PIMATIC_USER, $PIMATIC_PASS, 'benzin-email-already-send', 0);
function update($host, $user, $pass, $variable, $value)
{
shell_exec("curl --insecure -X PATCH --header \"Content-Type:application/json\" --data '{\"type\": \"value\", \"valueOrExpression\": \"$value\"}' --user \"$user:$pass\" http://$host/api/variables/$variable >/dev/null 2>&1");
}
?>
variables
{
"name": "benzin-preis-benachrichtung",
"value": 1.25
},
{
"name": "benzin-preis-bk-e5",
"value": 1.29
},
{
"name": "benzin-preis-shell-e5",
"value": 1.29
},
{
"name": "benzin-preis-vmarkt-e5",
"value": 1.27
},
{
"name": "benzin-preis-ran-e5",
"value": 1.28
},
{
"name": "benzin-preis-aral-e5",
"value": 1.29
},
{
"name": "benzin-email-notify",
"value": 0
},
{
"name": "benzin-email-already-send",
"value": 0
}
the remaining things
{
"id": "benzin-email-notify",
"name": "Benzin Benachrichtung",
"class": "DummySwitch"
},
{
"id": "benzin-email-preis",
"name": "Benachrichtungspreis",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-benachrichtung)",
"type": "number",
"unit": "Euro"
}
]
},
{
"id": "benzin-bk-e5",
"name": "BK E5",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-bk-e5)",
"type": "number",
"unit": "Euro"
}
]
},
{
"id": "benzin-shell-e5",
"name": "Shell E5",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-shell-e5)",
"type": "number",
"unit": "Euro"
}
]
},
{
"id": "benzin-vmarkt-e5",
"name": "V-Markt E5",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-vmarkt-e5)",
"type": "number",
"unit": "Euro"
}
]
},
{
"id": "benzin-ran-e5",
"name": "RAN Kissing E5",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-ran-e5)",
"type": "number",
"unit": "Euro"
}
]
},
{
"id": "benzin-aral-e5",
"name": "Aral E5",
"class": "VariablesDevice",
"variables": [
{
"name": "Preis",
"expression": "($benzin-preis-aral-e5)",
"type": "number",
"unit": "Euro"
}
]
},