Page 30 of 76
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:41
by ropske
Probably a stupid question, but how can i return the floating number?
this is what is in the JSON: [Data] => 36722.658 kWh
What i receive is: 36722658
Code: Select all
<?php
$data=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=devices&rid=304'),true);
$elek = filter_var($data['result']['0']['Data'], FILTER_SANITIZE_NUMBER_FLOAT);
echo $elek ;
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:52
by Egregius
Is it always 3 digits after the comma?
Then do a FILTER_SANITIZE_NUMBER_INT and divide it by 1000.
Code: Select all
$elek = filter_var($data['result']['0']['Data'], FILTER_SANITIZE_NUMBER_INT) / 1000;
Or you could just replace the kWh:
Code: Select all
$elek = str_replace(' kWh','',$data['result']['0']['Data']);
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:53
by ropske
What i did now is:
Code: Select all
<?php
$data=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=devices&rid=304'),true);
$stijn=$data['result']['0']['Data'];
$stijn=str_replace("kWh","",$stijn);
echo $stijn;
now i got the floating point data and i removed the 'kWh'
I don't know if it is the correct way, but it works :p
Re: Pass2PHP
Posted: Sunday 11 February 2018 20:54
by ropske
Egregius wrote: ↑Sunday 11 February 2018 20:52
Is it always 3 digits after the comma?
Then do a FILTER_SANITIZE_NUMBER_INT and divide it by 1000.
Code: Select all
$elek = filter_var($data['result']['0']['Data'], FILTER_SANITIZE_NUMBER_INT) / 1000;
Or you could just replace the kWh:
Code: Select all
$elek = str_replace(' kWh','',$data['result']['0']['Data']);
Hi, i just see your answer,
its not allways 3 digits after comma.
but its max 3 digits
Re: Pass2PHP
Posted: Sunday 11 February 2018 21:33
by sincze
Inspired on the 'Afvalkalender Post'.
http://www.domoticz.com/forum/viewtopic.php?t=17963 I thought maybe this could be a nice pass2php addition
Code: Select all
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTMLFile('http://www.mijnafvalwijzer.nl/nl/'.$zipcode.'/'.$housenumber.'/');
$data = $dom->getElementById("banner");
$result=$data->nodeValue;
This gives me:
Code: Select all
Eerstvolgende ophaalmoment: dinsdag 13 februari Plasticverpakkingen en drankenkartons
Now I need to figure out how to sanitize this in PHP. Just had some 'rough' bash weeks with reading the data from my router so I am a bit PHP rusty.
Any ideas

Re: Pass2PHP
Posted: Sunday 11 February 2018 22:03
by Egregius
Depends on what you want to do with it...
Re: Pass2PHP
Posted: Sunday 11 February 2018 22:10
by sincze
Easiest thing would be to store date and trash type in text sensor. If date is updated I send the house a telegram notice so they can take out the appropriate thrash

Of course I could just strip 'Eerstvolgende ophaalmoment:' and store the result in text sensor.
However I was thinking.. What can I do with the date

or separate date from trash type

Re: Pass2PHP
Posted: Monday 12 February 2018 7:27
by Egregius
This should get you going:
Code: Select all
$result="Eerstvolgende ophaalmoment: dinsdag 13 februari Plasticverpakkingen en drankenkartons";
$result=str_replace('Eerstvolgende ophaalmoment: ','',$result);
$result=explode(' ',$result);
$langedatum=$result[1].' '.$result[2].' '.strftime('%Y',time()).' 8:00:00';
$datum=strtotime($langedatum);
if($datum>apcu_fetch('previousgarbagedate')){
$garbages=array_slice($result,3);
$garbage='';
foreach($garbages as $i)$garbage.=$i.' ';
telegram('Tijd om '.$garbage.'buiten te zetten');
apcu_store('previousgarbagedate',$datum);
}
Re: Pass2PHP
Posted: Friday 16 February 2018 18:04
by sincze
'For Some reason the ' ' dit not deal with the space in the $result correctly.
Had to modify it a bit.
Code: Select all
function afvalkalender()
{
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTMLFile('http://www.mijnafvalwijzer.nl/nl/'.zipcode.'/'.housenumber.'/');
$data = $dom->getElementById("banner");
$result=$data->nodeValue;
$result=preg_split('/\s+/', $result);
$datum =mktime(0,0,0,nlDate($result[5]),$result[4],strftime('%Y',time()));
if($datum>cget('previousgarbagedate'))
{
$garbages=array_slice($result,6);
$garbage='';
foreach($garbages as $i)$garbage.=$i.' ';
telegramnotification('Tijd om '.$garbage.' buiten te zetten, zal op '.date("j F Y",$datum).' worden opgehaald',false,'Bernini');
$text=date("j F Y",$datum).' '.$garbage;
cset('previousgarbagedate',$datum);
}
}
function nlDate($datum)
{
$datum = str_replace("januari", 1, $datum);
$datum = str_replace("februari", 2, $datum);
$datum = str_replace("maart", 3, $datum);
$datum = str_replace("april", 4, $datum);
$datum = str_replace("mei", 5, $datum);
$datum = str_replace("juni", 6, $datum);
$datum = str_replace("juli", 7, $datum);
$datum = str_replace("augustus", 8, $datum);
$datum = str_replace("september", 9, $datum);
$datum = str_replace("oktober", 10, $datum);
$datum = str_replace("november", 11, $datum);
$datum = str_replace("december", 12, $datum);
return $datum;
}
Re: Pass2PHP
Posted: Wednesday 21 February 2018 20:35
by sincze
I was thinking of turning my smarttv to a specific sound level if it recognizes a specic series.

- Retrieve svalue
- svalue.png (4.14 KiB) Viewed 2884 times
However the value 'Video' is stored in '
$status' so that enables me to DIM the lights properly.
Code: Select all
if($status=='Video') { lg('Kodi Keuken playing Video'); sl('Lamp (Keukentafel) (RF)',25); rgb('Lamp LED Keukenkast','white',10,001,'Colour White'); }
else { lg('Kodi Keuken not playing Video'); sl('Lamp (Keukentafel) (RF)',35); rgb('Lamp LED Keukenkast','white',25,001,'Colour White'); }
However the name of the series is stored in '
svalue'. Any chance we can retrieve that in an easy way?

Re: Pass2PHP
Posted: Thursday 22 February 2018 8:34
by Egregius
Unfortunately svalue isn't available in the lua table.
A workaround could be to add it in one of the cron files with the /json.htm?type=devices&rid=IDX json call.
Re: Pass2PHP
Posted: Thursday 22 February 2018 23:46
by ropske
Nice work :p
Egregius, you also have a garbage tool in your php for Belgium?
I found this data for my street:
http://www.ophaalkalender.be/api/rides? ... pcode=8800
only the start and title should be extracted from the result, but will try to check this is the weekend

then you can fill up an array with the upcoming garbage dates
Re: Pass2PHP
Posted: Friday 23 February 2018 6:43
by Egregius
Didn't know that one, but since it's a nice json reply it's pretty easy to handle.
I made this of it, in cron28800:
Code: Select all
$data=json_decode(file_get_contents('http://www.ophaalkalender.be/api/rides?id=77009&housenumber=0&zipcode=8800'),true);
$first=true;
foreach($data as $i){
if(strtotime($i['start'])<time+86400){
if($first){
$afval=$i['title'];
$first=false;
}else $afval.=' + '.$i['title'];
}
}
if(isset($afval))apcu_store('afval',$afval);
else apcu_store('afval','');
And then on my floorplan:
Code: Select all
$afval=apcu_fetch('afval');
if(!empty($afval))echo '<div class="fix z0" style="top:370px;left:160px">'.$afval.' buiten zetten</div>';
So, when the collection date is tomorrow it'll be printed on my floorplan what I need to put outside.
Didn't look for that in the past because I always import the ICS into my calendar of
http://mirom.be/ophaalkalender
Re: Pass2PHP
Posted: Friday 23 February 2018 20:26
by sincze
Just wondering.
Any idea how many people are using Pass2PHP ?
- Egregius
- Robske
- Me
- ....
just curious.

Re: Pass2PHP
Posted: Saturday 24 February 2018 10:52
by Egregius
Don't know, there are some users from Tweakers.net also, but how many, no clue at all.
Re: Pass2PHP
Posted: Saturday 24 February 2018 15:19
by ropske
ah, you download it directly to your calendar from Mirom?
That calendar, is it the google calendar ?
Is it also on your github?
Thanks mate
Re: Pass2PHP
Posted: Saturday 24 February 2018 15:36
by Egregius
Yes, you can download a ics calendar file from the mirom site and import that in your calendar program or Google Calendar
Re: Pass2PHP
Posted: Sunday 04 March 2018 15:19
by ropske
You also have an example of this how you do this?

Re: Pass2PHP
Posted: Sunday 04 March 2018 17:18
by Egregius
Re: Pass2PHP
Posted: Sunday 04 March 2018 17:55
by ropske
I found somewhere your php to handle the google calendar
but i don't find it anymore
