<?php
include("/home/pi/domoticz/scriptsjoost/php/functions.php");
include("/home/pi/domoticz/scriptsjoost/php/settings.php");
$time = date("H:i");
//set the mm of rain you consider it's raining
$rainthreshold_minutes = "0.1" ;
$rainthreshold_hours = "0.5" ;
// according to buienradar there are 5 levels of rain per hour (mm/h)
// 0-2
// 2-5
// 5-10
// 10-100
// 100+
// these are used in the "severity level"
// $lat = "51.43" ;
// $lon = "6.04" ;
$json = file_get_contents("https://gpsgadget.buienradar.nl/data/raintext?lat=".$lat."&lon=".$lon) ;
$json = urlencode($json) ;
$data = explode("%0D%0A",$json) ;
$thishour=$nexthour=$ever = 0;
$rainbyminutes = $bool_rainbyminutes = '' ;
$first_rain = "ik heb geen idee" ;
$rain_stops = "ik heb geen idee" ;
$bool_rainnow = $bool_rainthis_hour = $bool_rainnext_hour = 'false' ;
$rain = array();
$maxP = 0;
$maxDT = '';
for($i=0;$i<(count($data)-1);$i++){
$tmp = urldecode($data[$i]) ;
$tmp2 = explode("|",$tmp) ;
$neerslg = neerslag($tmp2[0]);
$bool_neerslg = "false" ;
//check max rain///
if ($neerslg > $maxP) {
$maxP = $neerslg;
$maxDT = $i*5;
}
// check if it will rain now
if($i==0){
if($neerslg>=$rainthreshold_minutes){
$bool_rainnow = 'true' ;
$bool_neerslg = 'true' ;
$first_rain = 'het regent nu.' ; }
}
else{
if($neerslg>=$rainthreshold_minutes){
$bool_neerslg = 'true' ;
if($first_rain == "ik heb geen idee"){
$first_rain = $i*5;
}
}
}
$rain[] = $neerslg ;
if($i<12){ //add the items 0 to 11 together to calculate the total rain for this hour
$thishour+= ($neerslg*10)/10 ;
$ever += ($neerslg*10)/10 ;}
else{ //same for the rest to calculate next hour
$nexthour+= ($neerslg*10)/10 ;
$ever += ($neerslg*10)/10 ; }
$rainbyminutes .= '"'.($i*5).'" : "'.$neerslg.'",' ;
$bool_rainbyminutes .= '"'.($i*5).'" : '.$bool_neerslg.',' ;
}
$rainbyminutes = rtrim($rainbyminutes, ",") ;
$bool_rainbyminutes = rtrim($bool_rainbyminutes, ",") ;
if($thishour>=$rainthreshold_hours){
$bool_rainthis_hour = 'true' ;
}
if($nexthour>=$rainthreshold_hours){
$bool_rainnext_hour = 'true' ;
}
//find when it will be dry, first find first occurence of rain
$regen_time = '' ;
if($ever>0){
for($i=0;$i<count($rain);$i++){
$regen = $rain[$i];
// if found stop
if($regen>0.0){
$regen_time = $i ;
break; }
}
//now find the first occurence after the above one
for($i=$regen_time;$i<count($rain);$i++){
$regen_stop = $rain[$i];
if($regen_stop==0.0){
$rain_stops = $i*5;
break; }
else{
$rain_stops = "het duurt minimaal ".($i*5)." minuten, maar dit kan veranderen." ;}
}
}
echo '"rainnow" : '.$bool_rainnow.','.PHP_EOL;
echo '"rainthis_hour" : '.$bool_rainthis_hour.','.PHP_EOL;
echo '"rainnext_hour" : '.$bool_rainnext_hour.','.PHP_EOL;
echo '"this_hour" : "'.$thishour.'", '.PHP_EOL;
echo '"next_hour" : "'.$nexthour.'", '.PHP_EOL;
echo '"severitylevel" : { '.PHP_EOL;
echo '"this_hour" : "'.calc_rainlevel($thishour).'", '.PHP_EOL;
echo '"next_hour" : "'.calc_rainlevel($nexthour).'" '.PHP_EOL;
echo '"whenstart" : "'.$first_rain.'", '.PHP_EOL;
echo '"whenstop" : "'.$rain_stops.'" '.PHP_EOL;
function neerslag($input){
$tmp = (($input-109)/32) ;
$tmp = pow(10, $tmp) ;
$tmp = round($tmp,1) ;
if($tmp == "0" ){
return "0.0" ; }
else{
return $tmp;
}
}
function calc_rainlevel($input){
if(($input>=0 && $input< 2 )){
return 0 ; }
elseif(($input>=2 && $input< 5 )) {
return 1 ; }
elseif(($input>=5 && $input< 10 )) {
return 2 ; }
elseif(($input>=10 && $input<= 100 )) {
return 3 ; }
else{
return 4 ; }
}
//ALERT//
//zware buien > 10
//zware neerslag 3-10 mm
//matige neerslag 1-3 mm
//lichte neerslag 0.1-1 mm
//geen neerslag 0 mm
$maxP = round($maxP, 1);
if ($maxP < 0.1) {
$alertLevel = 1;
$alertText = 'Geen neerslag komende 2 uur'; }
elseif ($maxP <= 1) {
$alertLevel = 1;
$alertText = 'Lichte neerslag ('.$maxP.' mm/h @ '.date('h:i', strtotime($time) + ($maxDT * 60)).')';}
elseif ($maxP <= 3) {
$alertLevel = 2;
$alertText = 'Matige neerslag ('.$maxP.' mm/h @ '.date('h:i', strtotime($time) + ($maxDT * 60)).')';}
elseif ($maxP <= 10) {
$alertLevel = 3;
$alertText = 'Zware neerslag ('.$maxP.' mm/h @ '.date('h:i', strtotime($time) + ($maxDT * 60)).')';}
elseif ($maxP > 10) {
$alertLevel = 4;
$alertText = 'Zware buien ('.$maxP.' mm/h @ '.date('h:i', strtotime($time) + ($maxDT * 60)).')';
}
UpdateDevice($idx747, $alertLevel, urlencode($alertText));
//TEXT-DEVICE//
if ($maxP < 0.1) {
$textdevice = $alertText;
Updatedevice($idx748, 0, urlencode($textdevice));}
else { $textdevice = 'Neerslag begint rond '.date('h:i', strtotime($time) + ($first_rain * 60)).' en duurt ongeveer tot '.date('h:i', strtotime($time) + ($rain_stops * 60));
Updatedevice($idx748, 0, urlencode($textdevice));
}
echo $textdevice;
?>
<?php
include("/home/pi/domoticz/scriptsjoost/php/functions.php");
include("/home/pi/domoticz/scriptsjoost/php/settings.php");
// ******* BEGIN SETTINGS *******
$lat = '51.447474'; // eigen locatie (lattitude)
$lon = '5.756383'; // eigen locatie (longitude)
$distMax = '250'; //afstand hemelsbreed in km
$IDX = $idx725; // idx-nummer gedefinieerd in settings.php
$url = $domoticz_url; // domoticz_url gedefinieerd in settings.php
$number = 5; // aantal laatste aardbevingen;
// ******** END SETTINGS ********
$xml = 'https://cdn.knmi.nl/knmi/map/page/seismologie/GQuake_KNMI_RSS.xml';
$xml=simplexml_load_file($xml) or die("Error: Cannot create object");
$text = '';
for ($i = 0; $i <= ($number-1); $i++) {
$dist = round(distance($lat, $lon, $xml->channel->item[$i]->children('geo', true)->lat, $xml->channel->item[$i]->children('geo', true)->lon),0);
if ($dist <= $distMax) {
$description = $xml->channel->item[$i]->description . "<br><br>";
$description = explode(',', $description);
$text = $text.$description[0].' ('.$description[1].') | '.str_replace('Plaats = ','',$description[6]).' | '.$description[4].' | '.$description[5].' | Afstand: '.$dist. ' km'.PHP_EOL.PHP_EOL;
}
}
$data = $url.'json.htm?type=devices&rid='.$IDX;
if (false == ($contents = file_get_contents($data))) {
echo "Kan geen gegevens ophalen van Domoticz";
} else {
$result=json_decode($contents);
$text3=$result->result[0]->Data;
}
if ($text != $text3) {
Updatedevice($IDX,0,urlencode($text)); // regio
Telegram($text,false,1);
}
?>
<?php
include("/home/pi/domoticz/scriptsjoost/php/functions.php");
include("/home/pi/domoticz/scriptsjoost/php/settings.php");
$today = date('w');
$time = date("H:i");
//PHP cURL GET request
$get_data = callAPI('GET', 'http://127.0.0.1/api/4831A9C634/sensors', false);
$response = json_decode($get_data, true);
// melding batterij < 25%
foreach ($response as $device) {
if (isset($device['config']['battery'])) {
if ((($device['type']=='ZHAHumidity')) || (($device['type']=='ZHAPresence')) || (($device['type']=='ZHAOpenClose')) || (($device['type']=='ZHALightLevel'))) {
$level = $device['config']['battery'];
if ($level < 25) {
Telegram('Batterij van ' . $device['name'] . ' is ' . $level . '%. Tijd voor een nieuwe batterij!',false,1);
}
}
}
}
// Op zondag 20:00 uur overzicht van alle batterij-percentages
$text1 = '';
if (($today == 0) && ($time == "20:00")) {
foreach ($response as $device) {
if (isset($device['config']['battery'])) {
if ((($device['type']=='ZHAHumidity')) || (($device['type']=='ZHAPresence')) || (($device['type']=='ZHAOpenClose')) || (($device['type']=='ZHALightLevel'))) {
$level = $device['config']['battery'];
$text1 = $text1.'battery level ' . $device['name'] . ': ' . $level . '%'.PHP_EOL;
//Telegram('battery level ' . $device['name'] . ': ' . $level . '%',false,1);
}
}
}
}
Telegram($text1,false,1);
?>
if val_AlertLevelNow ~= val_AlertLevel_Today then
commandArray['SendNotification'] = "Code "..val_AlertColour_Today.."\n " .."\n"..val_AlertToday
end
commandArray['SendNotification']='subject#body#0'
commandArray['SendNotification'] = "Weeralarm: Code "..val_AlertColour_Today.."#"..val_AlertToday.."#0"
-- Script to check the location of multiple iPhones every X minutes,
-- test if they are "home" and represent this using virtual switches
commandArray = {}
-- polling interval in minutes (1-59), setting this too low may drain the phones' batteries
interval = 5
local m = os.date('%M')
if (m % interval == 0) then
json = require('json')
-- Array of users to be checked
users = {
Name1 = {username = "Name1@gmail.com" ; password = "*********" ; devicename = "iPhone Name1"};
Name2 = {username = "Name2@gmail.com" ; password = "*********" ; devicename = "iPhone Name2"};
}
-- The latitude and longitude of your house (use Google Maps or similar to find this)
homelongitude = *.*****
homelatitude = *.*****
-- Radius (in km) which will be used to determine if a device is at home
radius = 0.5
for user,credentials in pairs(users) do
stage1command = "curl -sk -X POST -D - -o /dev/null -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://fmipmobile.icloud.com/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage1command)
local result = handle:read("*a")
handle:close()
-- stage2server = string.match(result, "X%-Apple%-MMe%-Host%:%s(.*%.icloud%.com)")
stage2server = "p43-fmipmobile.icloud.com"
stage2command = "curl -sk -X POST -L -u '" .. credentials.username .. ":" .. credentials.password .. "' -H 'Content-Type: application/json; charset=utf-8' -H 'X-Apple-Find-Api-Ver: 2.0' -H 'X-Apple-Authscheme: UserIdGuest' -H 'X-Apple-Realm-Support: 1.0' -H 'User-agent: Find iPhone/1.3 MeKit (iPad: iPhone OS/4.2.1)' -H 'X-Client-Name: iPad' -H 'X-Client-UUID: 0cf3dc501ff812adb0b202baed4f37274b210853' -H 'Accept-Language: en-us' -H 'Connection: keep-alive' https://" .. stage2server .. "/fmipservice/device/" .. credentials.username .."/initClient"
local handle = io.popen(stage2command)
local result = handle:read("*a")
handle:close()
output = json:decode(result)
for key,value in pairs(output.content) do
if value.name == credentials.devicename then
lon = value.location.longitude
lat = value.location.latitude
bat = value.batteryLevel * 100 / 1
powerstateval = value.batteryStatus
table.insert(commandArray,{['UpdateDevice'] = otherdevices_idx['Iphone battery ' .. user] .. '|0|' .. bat})
distance = math.sqrt(((lon - homelongitude) * 111.320 * math.cos(math.rad(lat)))^2 + ((lat - homelatitude) * 110.547)^2) -- approximation
table.insert(commandArray,{['UpdateDevice'] = otherdevices_idx['Positie ' .. user] .. '|0|' .. math.floor(distance*100+0.5)/100})
print('iPhone ' .. user .. ': ' .. math.floor(distance*100+0.5)/100 .. ' km from home')
if distance < radius then
if otherdevices['Iphone ' .. user] == 'Off' then
commandArray['Iphone ' .. user] = 'On'
-- table.insert(commandArray, {['SendNotification'] = 'Presence update#' .. user .. ' komt thuis'})
end
else
if otherdevices['Iphone ' .. user] == 'On' then
commandArray['Iphone ' .. user] = 'Off'
-- table.insert(commandArray, {['SendNotification'] = 'Presence update#' .. user .. ' gaat van huis'})
end
end
end
end
end
end
return commandArray
[/font][/size]
<?php
include("/home/pi/domoticz/scripts/php/functions.php");
include("/home/pi/domoticz/scripts/php/settings.php");
// Saturday this month
$thisMonthStart = mktime(0,0,0,date('m')+0,0,date('Y'));
$saturday = date("d.m.Y",strtotime("first saturday", $thisMonthStart ));
//Saturday next month
$nextMonthStart = mktime(0,0,0,date('m')+1,1,date('Y'));
$first_saturday = date("d.m.Y",strtotime("first saturday", $nextMonthStart));
$tomorrow = date("d.m.Y",strtotime("+1 day"));
if (($tomorrow == $saturday) || ($tomorrow == $first_saturday)) {
Telegram("Papier wordt morgenochtend opgehaald!",false,1);
}
?>