Pass2PHP

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

Re: Pass2PHP

Postby ropske » Monday 27 February 2017 21:16

Yes, completely migrated into php and working :D

sincze wrote:
ropske wrote:

Code: Select all

#region Wasmachine Script
   $wasmachine_status_var = cget('swasmachine_status_var');
   $wasmachine_counter_var = cget('swasmachine_counter_var');
   $wasmachine_manuallyEnd_var = cget('swasmachine_manuallyEnd_uservar');
   $wasmachine_energy_consumption = cget('sVerbruik_Wasmachine');
   $idle_minutes = 5;
   $consumption_upper = 20;
   $consumption_lower = 3;
   $consumption_standby = 1;
   $wasmachinecurrentPowerUsage = cget('sVerbruik_Wasmachine');
   
   //Virtual switch is off, but consumption is higher than configured level, so washing has started
   if(($wasmachinecurrentPowerUsage>$consumption_upper)&&($wasmachine_status_var==0)){
      cset('swasmachine_status_var',1);
      cset('twasmachine_status_var',time);
      cset('swasmachine_manuallyEnd_uservar',0);
      lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is boven ingestelde waarde ('.$consumption_upper.'W), dus wasmachine is gestart!');
      cset('swasmachine_counter_var',$idle_minutes);
      sw(cget('iStatus_Wasmachine'),'Set%20Level&level=10','Set Status wasmachine on Werkend');
   }
   //Washing machine is not using a lot of energy, check the counter
   if(($wasmachinecurrentPowerUsage<$consumption_lower)&&($wasmachine_status_var==1)){
      cset('swasmachine_counter_var',$wasmachine_counter_var-1);
      $wasmachine_counter_var = cget('swasmachine_counter_var');
      lg('Huidig verbruik wasmachine ('.$wasmachinecurrentPowerUsage.'W) is lager dan idle waarde ('.$consumption_lower.'W), wasmachine is klaar of bijna klaar');
      lg('Herbereken teller, oude waarde: '.$wasmachine_counter_var.' minuten');
   }
   else{
      if(($wasmachine_counter_var!=$idle_minutes)&&$wasmachine_status_var==1){
         cset('swasmachine_counter_var',$idle_minutes);
         lg('Resetting wasmachine timer');
      }
   }
   //Washingmachine is done
   if($wasmachine_status_var==1&&$wasmachine_counter_var==0){
      //lg('wasmachine is klaar');
      //lg('Huidig verbruik wasmachine '.$wasmachine_energy_consumption.'W');
      $wasmachine_tijdsduur=(time-cget('twasmachine_status_var'));
      lg('Wasmachine is klaar, gelieve deze te ledigen!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten');
      cset('swasmachine_status_var',0);
      sw(cget('iStatus_Wasmachine'),'Set%20Level&level=20','Set Status wasmachine on klaar');
      $msg='Wasmachine is klaar met werken!  Tijdsduur bedraagt: '.($wasmachine_tijdsduur/60).' minuten';
      telegram($msg,true);
   }
   //wasmachine is switched off (manually)
   if(($wasmachinecurrentPowerUsage<$consumption_standby)&&($wasmachine_status_var==0)&&($wasmachine_manuallyEnd_var==0)){
      sw(cget('iStatus_Wasmachine'),'Set%20Level&level=0','Set Status wasmachine on Off');
      cset('swasmachine_manuallyEnd_uservar',1);
   }
   
   #end


@sincze: here's an example for my 'wasmachine' :p
got the same running for droogkast and vaatwas :p


Tnx @Robske ;-) really appreciated. Completely migrated to pass2php ??? :D Once it is running it keeps on going.

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: Pass2PHP

Postby sincze » Saturday 04 March 2017 12:40

Egregius wrote:About influxdb: can't you do anything with the MySQL examples? If a http poller can do it, it must be possible.


I created the following:

Code: Select all


function influxdb
($device,$value)
{
// FAMOUS STRING REPLACEMENT UTILITY
    if (strpos($device, " ") !== false) { $device=str_replace(" ","_",$device); }
// ENDOF FAMOUS STRING REPLACEMENT UTILITY

    $postdata = ("device_$device value=$value ".system('date +%s%N'));
    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-Type:application/octet-stream',
            'content' => $postdata
            
)
    );

    $context  = stream_context_create($opts);
    $result = file_get_contents(influxmachine.'/write?db=domoticz', false, $context);
    lg('InluxDB Notification'.$result);
}


I can now add the following line to a device.php file, for example the boiler.

Code: Select all

influxdb($device,$s['Boiler Water Temperature']);


It will show up in a InfluxDB and in Grafana with the correct date/time. Don't know if this is the smartest move adding these lines to all my devices.php however it does work and stores every slight change in the DB. Suggestions??
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

Egregius
Posts: 2079
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Saturday 04 March 2017 13:45

Depends on the database structure and how you want to read it.
I store all temps in one record, one field for every temp sensor. That way I don't need to store idx or name and I only have one timestamp.

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: RE: Re: Pass2PHP

Postby sincze » Saturday 04 March 2017 13:58

Egregius wrote:Depends on the database structure and how you want to read it.
I store all temps in one record, one field for every temp sensor. That way I don't need to store idx or name and I only have one timestamp.

Influx is time based and does not really care about structure :) just dump a value with time stamp and voila. Records are only kept 180 days and auto removed. Not for future reference.

Sent from my SM-G925F using Tapatalk
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

Egregius
Posts: 2079
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Saturday 04 March 2017 17:05

Then I prefer MySQL :P

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: Pass2PHP

Postby sincze » Saturday 04 March 2017 18:53

Egregius wrote:Then I prefer MySQL :P


I can imagine. :D. Call me a die-hard mysql user as well. (Used to have DomotiGa as home domotica controller).

In this case I thought why not use it to create a nice overview of... something as some kind of monitor to display on tablet or so.
Egregius_Grafana.JPG
Egregius_Grafana.JPG (188.29 KiB) Viewed 434 times


I used to have some crashes (too many open files) when I did this in Domoticz directly. You know via More Options -> Data Push.
Now I thought about the power of php.. Let's see what happens..

Thanks again for your help. :D
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

rjblake
Posts: 86
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Pass2PHP

Postby rjblake » Monday 06 March 2017 23:34

I'm trying to use your function RefreshZwave($node) to refresh my Qubino Relay temperature (it only reports on temp changes of 0.1deg and sometimes seems to just plain go to sleep for a long time), but seem to have a problem with a constant 'time'. I'm using php70 and apcu seems to be there, but if I report errors, I always get a "PHP Notice: Use of undefined constant time - assumed 'time' in /volume1/web/domoticzstuff/qubino2.php on line 36". As result, my $last is always less than time-3600. Is this constant defined elsewhere in Pass2PHP?

Function as used called with "php70 -f myphp.php 8"

Code: Select all

<?php
$argument1 = $argv[1];
$refresh = RefreshZwave($argument1);

function RefreshZwave($node){
   $last=apcu_fetch('refresh'.$node);
   apcu_store('refresh'.$node,time);
   if($last<time-3600){
      $devices=json_decode(file_get_contents('http://192.168.1.1:8084/json.htm?type=openzwavenodes&idx=9',false),true);
      foreach($devices['result'] as $devozw)
         if($devozw['NodeID']==$node){
            $device=$devozw['Description'].' '.$devozw['Name'];
            break;
         }
      print strftime("%Y-%m-%d %H:%M:%S",time()).'   => Refreshing node '.$node.' '.$device.PHP_EOL;
      for($k=1;$k<=5;$k++){
         $result=file_get_contents('http://192.168.1.1:8084/ozwcp/refreshpost.html',false,stream_context_create(array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query(array('fun'=>'racp','node'=>$node)),),)));
         if($result==='OK')break;
         sleep(1);
      }
      if(apcu_fetch('timedeadnodes')<time-298){
         apcu_store('timedeadnodes',time);
         foreach($devices as $node=>$data){
            if($node=="result"){
               foreach($data as $index=>$eltsNode){
                  if($eltsNode["State"]=="Dead"&&!in_array($eltsNode['NodeID'],array(57))){
                     telegram('Node '.$eltsNode['NodeID'].' '.$eltsNode['Description'].' ('.$eltsNode['Name'].') marked as dead, reviving '.ZwaveCommand($eltsNode['NodeID'],'HasNodeFailed'));
                     ControllerBusy(10);
                     ZwaveCommand(1,'Cancel');
                  }
               }
            }
         }
      }
   }
}
?>

Egregius
Posts: 2079
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Monday 06 March 2017 23:57

It should be on the first line of pass2php

Code: Select all

define('time',$_SERVER['REQUEST_TIME']);

rjblake
Posts: 86
Joined: Friday 21 October 2016 9:25
Target OS: NAS (Synology & others)
Domoticz version:
Location: Netherlands
Contact:

Re: Pass2PHP

Postby rjblake » Wednesday 08 March 2017 17:34

Aarg! My bad - missed that. Need more coffee or more sleep, or both :)

BarryT
Posts: 173
Joined: Tuesday 31 March 2015 22:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: east netherlands
Contact:

Re: Pass2PHP

Postby BarryT » Sunday 16 April 2017 15:55

Egregius, is it so simple as install the scripts, and it works, or does i need to edit the files to all devices/switches?
I see names like:

Code: Select all

if($action=='On'){
      $items=array('eettafel','zithoek','kamer','tobi');
      foreach($items as $item)if($s[$item]!='On')sl($i[$item],100,$item);
      $items=array('bureel','tvled','kristal','wasbak','keuken','kookplaat','werkblad','inkom','hall','lichtbadkamer1');
      foreach($items as $item)if($s[$item]!='On')sw($i[$item],'On',$item);


I have 100+ devices/switches, wich works perfectly atm, but the on/off times are sometimes over 3 or more secs..
Also 7 pir sensors and 16 dimmers..
I was finding a way to make it all working a bit faster, as it looks like it should do with what you made, but i dont have the time to "edit" all devices/names/etc :(

Thanks
6x Raspberry 3B
A lot of scripts, switches and sensors :)

Egregius
Posts: 2079
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Sunday 16 April 2017 19:04

You don't need to change your devices, only the script.

BarryT
Posts: 173
Joined: Tuesday 31 March 2015 22:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: east netherlands
Contact:

Re: Pass2PHP

Postby BarryT » Sunday 16 April 2017 19:08

Egregius wrote:You don't need to change your devices, only the script.

Yeah, i meant in your script ofc..
That would be a lot of work then!
6x Raspberry 3B
A lot of scripts, switches and sensors :)

Egregius
Posts: 2079
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Beitem, BE
Contact:

Re: Pass2PHP

Postby Egregius » Sunday 16 April 2017 20:01

Start with one pir, feel the difference and then add the rest one by one.
If you don't want to spent some time in then don't bother starting with this.

BarryT
Posts: 173
Joined: Tuesday 31 March 2015 22:06
Target OS: Raspberry Pi
Domoticz version: beta
Location: east netherlands
Contact:

Re: Pass2PHP

Postby BarryT » Sunday 16 April 2017 20:36

Egregius wrote:Start with one pir, feel the difference and then add the rest one by one.
If you don't want to spent some time in then don't bother starting with this.

I will do that for sure, thanks :)
Ofcourse i will spend many time in it but not for now.

Good job!
6x Raspberry 3B
A lot of scripts, switches and sensors :)

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: Pass2PHP

Postby sincze » Monday 17 April 2017 13:28

Egregius wrote:Start with one pir, feel the difference and then add the rest one by one.
If you don't want to spent some time in then don't bother starting with this.


It is worth it :D .
Took me my full christmas holiday :shock: :shock:

But now it responds like crazy. Still have to add my Zwave stuff (bought after christmas) and network related things.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

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

Re: Pass2PHP

Postby ropske » Monday 17 April 2017 13:29

sincze: you still havent added your zwave?
shame!
:lol:

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: Pass2PHP

Postby sincze » Monday 17 April 2017 15:20

ropske wrote:sincze: you still havent added your zwave?
shame!
:lol:


Whoeps.
Oh no I was wrong... I use them alright but I don't use the functions RefreshZwave e.g.
Motion detection with a zwave sensor is really really fast.

It was YOU :lol: that got me into the z-wave mess :D when your wasmachine monitoring flashed by :D
I even wrote a function to put the received data directly into my influxDB :shock:
yeah who would guess that i was able to do so.

Now I still need to add 'ping' devices as this is still done by domoticz.
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.

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

Re: Pass2PHP

Postby ropske » Monday 17 April 2017 16:16

:lol: good

you have some new 'functions' added?
i'm just curious :p
maybe some things i can use too :D

User avatar
sincze
Posts: 627
Joined: Monday 02 June 2014 22:46
Target OS: Linux
Domoticz version: 3.6833
Location: Netherlands
Contact:

Re: Pass2PHP

Postby sincze » Monday 17 April 2017 21:02

ropske wrote::lol: good

you have some new 'functions' added?
i'm just curious :p
maybe some things i can use too :D


I posted the on the forum some time ago.
Like this one: https://www.domoticz.com/forum/viewtopic.php?f=64&t=12343&start=380#p122311
Running Domoticz since 2013 with Cubietruck
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266
Sensors: You name it I probably got 1.


Return to “PHP and all others”

Who is online

Users browsing this forum: No registered users and 1 guest