Benutzer-Werkzeuge

Webseiten-Werkzeuge


hardware:controllers:youless

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
youless [2014/06/01 12:47] – improved scripts with command line options wf_bitplan.comhardware:controllers:youless [2018/01/25 16:22] (aktuell) – code jau
Zeile 1: Zeile 1:
-==== You less device ==== +===== Youless device ===== 
-Postfossil BV from the Netherlands: +Postfossil BV from the Netherlands: http://www.postfossil.nl/
-  * http://www.postfossil.nl/ +
-offers a meter reading device at:  +
-  * http://www.youless.net/home.html +
-In germany the device is available via:  +
-  * http://www.bg-etech.de/ +
-and can be ordered via Amazon at  +
-  * http://www.amazon.de/dp/B00EMBM920 +
-although the device is offered much cheaper via the vendor in the netherlands. +
-The device has a lan interface and can be used with analog ferraris meters as well as digital S0 input. +
-=== manual === +
-an english manual can be found at: +
-    * http://www.bg-etech.de/images/YouLess/Youless-manual-1.3C_EN.pdf+
  
-==== You less software ==== +offers meter reading device athttp://www.youless.net/home.html
-This is screen shot of the web interface offered:+
  
-{{:playground:youlessscreenshot.png?400|}}+In germany the device is available viahttp://www.bg-etech.de/
  
-==== Connection to volkszaehler ==== +English manual can be found athttp://www.bg-etech.de/images/YouLess/Youless-manual-1.3C_EN.pdf
-I (Wolfgang - wf (at) bitplan.com) am currently trying it out and intending to connect it to the volkszaehler solution. I'll post any news here. +
-=== data format === +
-  * http://wiki.td-er.nl/index.php?title=YouLess  +
-has information on how to access the device+
  
-=== php code for posting to middleware === +The device has a lan interface and can be used with analog ferraris meters as well as digital S0 input.
-The following code is an attempt to read data from the youless logger  +
-and post it to the volkszaehler middlware. As of version 1.14 it's working in my (Wolfgang's) environment.+
  
-You might want to set: +This is a screen shot of the web interface offered:
-  * $url        - the url to read the youless from +
-  * $vzurl      - the url your middleware runs at +
-  * $cuuid_pwr  - the channel id to post the power reading in Watt to +
-  * $cuuid_cnt  - the channel id to post the power reading in Wh to (resolution 1000)  +
-  * $delay      - how long to wait between posts default: 5 secs / 12 readings per minute +
-  * $cnt_modulo - how often to send the kwH reading defaulton every 12th reading / once per minute+
  
 +{{:playground:youlessscreenshot.png?300|}}
  
-To use code copy the two script parts to a "vzapihelper.php" and "yl.php" and then start with e.g. +===== Connection to volkszaehler =====
-<code bash|example loop call> +
-php yl.php \ +
-  --url="http://2.0.0.94/a?f=j" \ +
-  --vzurl="http://capri/vz/middleware.php/data"+
-  --cuuid_pwr="0cca0870-e695-11e3-8c38-xxxx"+
-  --cuuid_cnt="b8192a00-e71e-11e3-be31xxxx"+
-  --delay=5 \ +
-  --cnt_modulo=12 \ +
-  --loop +
-</code>+
  
-<code base|example call from cron> +=== Data format === 
-cd /home/wf/youless +Information on how to access the device: http://wiki.td-er.nl/index.php?title=YouLess 
-php yl.php \ +
-  --url="http://2.0.0.94/a?f=j"+
-  --vzurl="http://capri/vz/middleware.php/data" \ +
-  --cuuid_pwr="0cca0870-e695-11e3-8c38-xxxx"+
-  --cuuid_cnt="b8192a00-e71e-11e3-be31-xxxx" >> /var/log/energymeter.log +
-</code>+
  
-the output should look like:+=== Example === 
 +In my environment the youless device has the ip address 192.168.0.12  
 +Using the url http://192.168.0.12/a?f=j 
 +the json response is:
 <code> <code>
-2014-05-28 21:05:07   1,518 kWh 1304 Watt +{"cnt":"22018,290","pwr":3789,"lvl":0,"dev":"","det":"","con":"*","sts":"","raw":1}
-2014-05-28 21:05:12   1,520 kWh 1338 Watt +
-2014-05-28 21:05:17   1,522 kWh 1318 Watt+
 </code> </code>
 +The json encoded information has the current meter count / kWh in "cnt" and the current power level in Watts in "pwr".
 +This information needs to be converted to volkszaehler format and posted to the middleware - this is what the code below does.
  
 +=== PHP-Code for posting to middleware ===
 +The following code is an attempt to read data from the youless logger and post it to the volkszaehler middleware. As of version (2017/06 June) it's working in my environment.
  
-For any feedback please contact me at wf (at) bitplan.com. Enjoy ...+There are three files used: 
 +  * php file: vzapihelper.php 
 +  * php file: yl.php 
 +  * sh  file: yl.sh  (the only file you have to enter individual codeUUIDs of your VZ-Channels an the IP adress of your youless device)
  
-<code php|yl.php>+=== creating the 3 used files === 
 +to edit or create a file type the following in your console of your volkszaehler raspberry or what else: 
 +<code>sudo nano /etc/yl.php</code> 
 +the file "yl.php" in the folder "etc" doesn't exist before, so you now have created. Insert the following code and press "STRG" +"X" to save an exit the file: 
 +<code php yl.php>
 <?php <?php
   /**   /**
    * read meter data from youless device    * read meter data from youless device
    * and post it to volkszaehler    * and post it to volkszaehler
-   * $Header: /home/wf/youless/RCS/yl.php,v 1.14 2014/06/01 10:40:37 wf Exp wf $+   * $Header: /etc/yl.php,v 1.14 2014/06/01 10:40:37 wf Exp wf $
    */    */
 + 
 // common code for reading and posting // common code for reading and posting
 require __DIR__.'/vzapihelper.php'; require __DIR__.'/vzapihelper.php';
-   + 
    /**    /**
     * read the meter     * read the meter
Zeile 85: Zeile 57:
    function readyouless($url) {    function readyouless($url) {
     $json=readUrl($url);     $json=readUrl($url);
 + 
     // get the meter reading     // get the meter reading
     $meter=json_decode($json, true);     $meter=json_decode($json, true);
Zeile 93: Zeile 65:
     return $meter;     return $meter;
    }    }
-   + 
    /**    /**
     * transfer youless reading to vz middleware     * transfer youless reading to vz middleware
Zeile 111: Zeile 83:
      // if you have an analog meter you might want to use and show this      // if you have an analog meter you might want to use and show this
      // $lvl=$meter["lvl"];      // $lvl=$meter["lvl"];
 + 
      // convert to php compatible value      // convert to php compatible value
      $cnt=str_replace(",",".",$cnt);      $cnt=str_replace(",",".",$cnt);
      // calculate Wh from kWh      // calculate Wh from kWh
      $cnt1000=$cnt*1000.0;      $cnt1000=$cnt*1000.0;
-    + 
      // get human readable time stamp       // get human readable time stamp 
      $now=date("Y-m-d H:i:s");      $now=date("Y-m-d H:i:s");
 + 
      // display progress (comment if you use this in cron job)      // display progress (comment if you use this in cron job)
      printf("%s YL: % 5d Watt % 10.3f kwH\n",$now,$pwr,$cnt);      printf("%s YL: % 5d Watt % 10.3f kwH\n",$now,$pwr,$cnt);
Zeile 125: Zeile 97:
      // post data to middleware according to:       // post data to middleware according to: 
      // http://wiki.volkszaehler.org/development/api/reference      // http://wiki.volkszaehler.org/development/api/reference
 + 
      # first post the power reading in Watt      # first post the power reading in Watt
      post2vz($vzurl,$cuuid_pwr,$pwr);      post2vz($vzurl,$cuuid_pwr,$pwr);
 + 
      # then the energy reading in Wh      # then the energy reading in Wh
      if ($post_cnt) {      if ($post_cnt) {
        post2vz($vzurl,$cuuid_cnt,$cnt1000);        post2vz($vzurl,$cuuid_cnt,$cnt1000);
      }      }
 + 
    }    }
 + 
   $loop=0;   $loop=0;
   // possible command line options   // possible command line options
Zeile 151: Zeile 123:
   // energy (kWh)   // energy (kWh)
   $cuuid_cnt=checkoption("cuuid_cnt",$options);   $cuuid_cnt=checkoption("cuuid_cnt",$options);
-  + 
   // loop option - if no set just one shot (e.g. in cron)   // loop option - if no set just one shot (e.g. in cron)
   $doloop=array_key_exists("loop",$options);   $doloop=array_key_exists("loop",$options);
Zeile 165: Zeile 137:
     $cnt_modulo=1;     $cnt_modulo=1;
   }   }
 + 
   // run once or in a loop   // run once or in a loop
   while ($loop<$maxloop) {   while ($loop<$maxloop) {
Zeile 174: Zeile 146:
     $loop++;     $loop++;
   }   }
-  + 
 ?> ?>
- 
 </code> </code>
-== vzapihelper == + 
-helper functions to talk to middleware and evaluate command line options +now do the same for the second file, the vzapihelper.php. Type the following in your console: 
-<code php|vzapihelper.php>+<code>sudo nano /etc/vzapihelper.php</code> 
 +Insert the following code and press "STRG" +"X" to save an exit the file: 
 +<code php vzapihelper.php>
 <?php <?php
   /**   /**
    * vzapi helper functions    * vzapi helper functions
-   * $Header: /home/wf/youless/RCS/vzapihelper.php,v 1.3 2014/05/30 06:57:23 wf Exp $+   * $Header: /etc/vzapihelper.php,v 1.3 2014/05/30 06:57:23 wf Exp $
    */    */
 + 
   /**   /**
    * get a curl channel    * get a curl channel
Zeile 199: Zeile 172:
     // Set the url     // Set the url
     curl_setopt($ch, CURLOPT_URL,$url);     curl_setopt($ch, CURLOPT_URL,$url);
 + 
     return $ch;     return $ch;
   }   }
-  + 
   /**   /**
    * read the given url    * read the given url
Zeile 209: Zeile 182:
   function readUrl($url)  {   function readUrl($url)  {
     $ch=curl($url);     $ch=curl($url);
-    + 
     // Execute     // Execute
     $result=curl_exec($ch);     $result=curl_exec($ch);
     return $result;     return $result;
   }   }
-  + 
   /**   /**
    * post to the given url    * post to the given url
Zeile 231: Zeile 204:
     return $result;     return $result;
    }    }
 + 
    /**    /**
     * post data to vz middleware     * post data to vz middleware
Zeile 241: Zeile 214:
      // post data to middleware according to:       // post data to middleware according to: 
      // http://wiki.volkszaehler.org/development/api/reference      // http://wiki.volkszaehler.org/development/api/reference
 + 
      // adapt timestamp to volkszaehler conventions      // adapt timestamp to volkszaehler conventions
  $timestamp=time()*1000;  $timestamp=time()*1000;
 + 
      # first       # first 
      $posturl=$vzurl."/".$cuuid.".json";      $posturl=$vzurl."/".$cuuid.".json";
Zeile 253: Zeile 226:
      }      }
    }    }
 + 
   /**   /**
    * check that option $opt is available in $options    * check that option $opt is available in $options
Zeile 264: Zeile 237:
       die("option $opt missing!\n");       die("option $opt missing!\n");
   }   }
 + 
 ?> ?>
 +</code>
  
 +The last file ist the yl.sh. The script automatically will be started from the crontab (Taskmgr) of your linux system, so that the youless device is also working after a reboot.
  
 +Type the following in your console:
 +<code>sudo nano /etc/yl.sh</code>
 +Insert the following code and press "STRG" +"X" to save an exit the file:
 +<code bash yl.sh>
 +#!/bin/bash
 +while true
 +do
 +php /etc/yl.php \
 +  --url="http://IP ADRESS OF YOUR YOULESS DEVICE/a?f=j" \
 +  --vzurl="http://localhost/middleware.php/data" \
 +  --cuuid_pwr="ENTER HERE THE UUID OF THE CHANNEL FORM YOUR VOLKSZAEHLER YOU WANT TO POST THE CURRENT POWER TO" \
 +  --cuuid_cnt="ENTER HERE THE UUID OF THE CHANNEL FORM YOUR VOLKSZAEHLER YOU WANT TO POST THE METER READING (Zählerstand) TO" \
 +  --delay=15 \
 +  --cnt_modulo=12 \
 +  --loop
 +done
 +exit 0
 </code> </code>
 +
 +Here is a statement of the parameter
 +  * $url        - the url to read the youless from
 +  * $vzurl      - the url your middleware runs at
 +  * $cuuid_pwr  - the channel id to post the power reading in Watt to
 +  * $cuuid_cnt  - the channel id to post the power reading in Wh to (resolution 1000) 
 +  * $delay      - how long to wait between posts default: 5 secs / 12 readings per minute
 +  * $cnt_modulo - how often to send the kwH reading default: on every 12th reading / once per minute
 +
 +To make the sh-file executable for crontab (Taskmgr) you have to give the rights. Type the following into your console:
 +<code>
 +sudo chmod +x /etc/yl.sh
 +</code>
 +
 +To edit the crontab type
 +<code>
 +sudo nano /etc/rc.local
 +</code>
 +and add the following line on the bottom of the file, before the line "exit 0":
 +<code>
 +bash /etc/yl.sh&
 +</code>
 +
 +So that's it. now it should work.
 +
 +
 +You also can test your configuration if you enter the following code in your console:
 +<code>
 +php /etc/yl.php \
 +  --url="http://IP ADRESS OF YOUR YOULESS DEVICE/a?f=j" \
 +  --vzurl="http://localhost/middleware.php/data" \
 +  --cuuid_pwr="ENTER HERE THE UUID OF THE CHANNEL FORM YOUR VOLKSZAEHLER YOU WANT TO POST THE CURRENT POWER TO" \
 +  --cuuid_cnt="ENTER HERE THE UUID OF THE CHANNEL FORM YOUR VOLKSZAEHLER YOU WANT TO POST THE METER READING (Zählerstand) TO" \
 +  --delay=15 \
 +  --cnt_modulo=12 \
 +  --loop
 +done
 +exit 0
 +</code>
 +
 +the output should look like:
 +<code>
 +2017-04-29 10:59:00 YL:   640 Watt     50.595 kwH
 +2017-04-29 10:59:05 YL:   639 Watt     50.596 kwH
 +2017-04-29 10:59:10 YL:   639 Watt     50.597 kwH
 +</code>
 +
 +
 +For any feedback please contact wf (at) bitplan.com or tiedi (at) web.de. Enjoy ...
 +
 +
 +[[https://wiki.volkszaehler.org/howto/raspberry_pi_image?s[]=raspberry|how to flash a complete volkszahler image on your raspberry]]
 +
 +
 +
hardware/controllers/youless.1401619632.txt.gz · Zuletzt geändert: 2014/06/01 12:47 von wf_bitplan.com