Pass2PHP

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 11 February 2018 21:41

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 ;

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Sunday 11 February 2018 21: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']);

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 11 February 2018 21:53

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

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 11 February 2018 21:54

Egregius wrote:
Sunday 11 February 2018 21: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

User avatar
sincze
Posts: 960
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Sunday 11 February 2018 22:33

Inspired on the 'Afvalkalender Post'. http://www.domoticz.com/forum/viewtopic.php?t=17963 I thought maybe this could be a nice pass2php addition :lol:

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 :lol:
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Sunday 11 February 2018 23:03

Depends on what you want to do with it...

User avatar
sincze
Posts: 960
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Sunday 11 February 2018 23:10

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 :)
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Monday 12 February 2018 8:27

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);
}

User avatar
sincze
Posts: 960
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Friday 16 February 2018 19:04

'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; 
}

Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
sincze
Posts: 960
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Wednesday 21 February 2018 21:35

I was thinking of turning my smarttv to a specific sound level if it recognizes a specic series.
svalue.png
Retrieve svalue
svalue.png (4.14 KiB) Viewed 1450 times
However the value 'Video' is stored in '$status' so that enables me to DIM the lights properly. :D

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? :lol:
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Thursday 22 February 2018 9:34

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.

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Friday 23 February 2018 0:46

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

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Friday 23 February 2018 7:43

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

User avatar
sincze
Posts: 960
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Pass2PHP

Post by sincze » Friday 23 February 2018 21:26

Just wondering.

Any idea how many people are using Pass2PHP ?
- Egregius
- Robske
- Me
- ....

just curious. :D
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Saturday 24 February 2018 11:52

Don't know, there are some users from Tweakers.net also, but how many, no clue at all.

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Saturday 24 February 2018 16:19

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

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Saturday 24 February 2018 16:36

Yes, you can download a ics calendar file from the mirom site and import that in your calendar program or Google Calendar

ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 04 March 2018 16:19

You also have an example of this how you do this? :oops: ;)

User avatar
Egregius
Posts: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius » Sunday 04 March 2018 18:18


ropske
Posts: 313
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske » Sunday 04 March 2018 18:55

I found somewhere your php to handle the google calendar
but i don't find it anymore :oops:

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest