Pass2PHP

Moderator: leecollings

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

Re: Pass2PHP

Post 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 ;
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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']);
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post 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
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post 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
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post 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 :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:
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Depends on what you want to do with it...
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post 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 :)
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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);
}
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

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

Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

I was thinking of turning my smarttv to a specific sound level if it recognizes a specic series.
Retrieve svalue
Retrieve svalue
svalue.png (4.14 KiB) Viewed 2863 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:
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post 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
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: Pass2PHP

Post by sincze »

Just wondering.

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

just curious. :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Don't know, there are some users from Tweakers.net also, but how many, no clue at all.
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

Yes, you can download a ics calendar file from the mirom site and import that in your calendar program or Google Calendar
ropske
Posts: 483
Joined: Tuesday 12 August 2014 5:37
Target OS: Raspberry Pi / ODroid
Domoticz version: V3_8394
Location: Rumbeke,Belgium
Contact:

Re: Pass2PHP

Post by ropske »

You also have an example of this how you do this? :oops: ;)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Pass2PHP

Post by Egregius »

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

Re: Pass2PHP

Post by ropske »

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