hardware:controllers:youless
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
youless [2014/05/29 14:03] – wf_bitplan.com | hardware:controllers:youless [2018/01/25 16:22] (aktuell) – code jau | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
- | ==== You less device ==== | + | ===== Youless |
- | Postfossil BV from the Netherlands: | + | Postfossil BV from the Netherlands: |
- | * http:// | + | |
- | offers a meter reading device at: | + | offers a meter reading device at: http:// |
- | * http:// | + | |
- | In germany the device is available via: | + | In germany the device is available via: http:// |
- | * http:// | + | |
- | and can be ordered via Amazon | + | English manual |
- | * 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. | 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:// | ||
- | ==== You less software ==== | ||
This is a screen shot of the web interface offered: | This is a screen shot of the web interface offered: | ||
- | {{: | + | {{: |
- | ==== Connection to volkszaehler ==== | + | ===== Connection to volkszaehler ===== |
- | 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:// | + | |
- | has information on how to access the device | + | |
- | === php code for posting to middleware | + | === Data format |
- | The following code is a first attempt | + | Information on how to access |
- | You might want to modify: | + | |
- | * $url - the url to read the youless from | + | |
- | * $vzurl | + | |
- | * $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 1000000? | + | |
- | * $delay - how long to wait between posts default: 5 secs / 12 readings per minute | + | |
- | + | === Example === | |
- | To use code copy it to a file "yl.php" and then start with | + | In my environment the youless device has the ip address 192.168.0.12 |
+ | Using the url http:// | ||
+ | the json response is: | ||
< | < | ||
- | php -f yl.php | + | {" |
</ | </ | ||
+ | The json encoded information has the current meter count / kWh in " | ||
+ | This information needs to be converted to volkszaehler format and posted to the middleware - this is what the code below does. | ||
- | the output should look like: | + | === PHP-Code for posting to middleware === |
- | <code> | + | The following |
- | 2014-05-28 21: | + | |
- | 2014-05-28 21: | + | |
- | 2014-05-28 21: | + | |
- | </code> | + | |
+ | 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 code. UUIDs of your VZ-Channels an the IP adress of your youless device) | ||
- | For any feedback please contact me at wf (at) bitplan.com. Enjoy ... | + | === 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 php|yl.php> | + | < |
+ | the file "yl.php" in the folder " | ||
+ | <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/ | + | * $Header: /etc/yl.php,v 1.14 2014/06/01 10:40:37 wf Exp wf $ |
*/ | */ | ||
- | | + | |
+ | // common code for reading and posting | ||
+ | require __DIR__.'/ | ||
+ | |||
+ | | ||
+ | * read the meter | ||
+ | */ | ||
+ | | ||
+ | $json=readUrl($url); | ||
+ | |||
+ | // get the meter reading | ||
+ | $meter=json_decode($json, | ||
+ | // Will dump a beauty json :3 | ||
+ | // comment out next line if you'd like to debug the json message | ||
+ | // var_dump($meter); | ||
+ | return $meter; | ||
+ | } | ||
+ | |||
+ | /** | ||
+ | * transfer youless reading to vz middleware | ||
+ | * param 1: url to read from youless | ||
+ | * param 2: vzurl - middleware url of volkszaehler | ||
+ | * param 3: channel uuid for power reading in Watt | ||
+ | * param 4: channel uuid for energy reading in kWh | ||
+ | * param 5: shall we post the cnt reading? | ||
+ | */ | ||
+ | | ||
+ | // read data from youless | ||
+ | | ||
+ | // get values | ||
+ | | ||
+ | | ||
+ | // the level is not interesting for digital meters | ||
+ | // if you have an analog meter you might want to use and show this | ||
+ | // $lvl=$meter[" | ||
+ | |||
+ | // convert to php compatible value | ||
+ | | ||
+ | // calculate Wh from kWh | ||
+ | | ||
+ | |||
+ | // get human readable time stamp | ||
+ | | ||
+ | |||
+ | // display progress (comment if you use this in cron job) | ||
+ | | ||
+ | |||
+ | // post data to middleware according to: | ||
+ | // http:// | ||
+ | |||
+ | # first post the power reading in Watt | ||
+ | | ||
+ | |||
+ | # then the energy reading in Wh | ||
+ | if ($post_cnt) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | $loop=0; | ||
+ | // possible command line options | ||
+ | // --loop --url= --vzurl= --cuuid_pwr= --cuuid_cnt= --delay= --cnt_modulo= | ||
+ | $longopts=array(" | ||
+ | $shortopts=""; | ||
+ | $options=getopt($shortopts, | ||
+ | // the url to read the youless device from (json option) | ||
+ | $url=checkoption(" | ||
+ | // the volkszaehler middleware url | ||
+ | $vzurl=checkoption(" | ||
+ | // channel uuids | ||
+ | // power (watts) | ||
+ | $cuuid_pwr=checkoption(" | ||
+ | // energy (kWh) | ||
+ | $cuuid_cnt=checkoption(" | ||
+ | |||
+ | // loop option - if no set just one shot (e.g. in cron) | ||
+ | $doloop=array_key_exists(" | ||
+ | if ($doloop) { | ||
+ | // how often to post to middleware | ||
+ | // delay in seconds between posts | ||
+ | $delay=intval(checkoption(" | ||
+ | // how many delays for posting a kwH reading | ||
+ | $cnt_modulo=intval(checkoption(" | ||
+ | $maxloop=2147483647; | ||
+ | } else { | ||
+ | $maxloop=1; | ||
+ | $cnt_modulo=1; | ||
+ | } | ||
+ | |||
+ | // run once or in a loop | ||
+ | while ($loop< | ||
+ | youless2vz($url, | ||
+ | if ($doloop) { | ||
+ | sleep($delay); | ||
+ | } | ||
+ | $loop++; | ||
+ | } | ||
+ | |||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | now do the same for the second file, the vzapihelper.php. Type the following in your console: | ||
+ | < | ||
+ | Insert the following code and press " | ||
+ | <code php vzapihelper.php> | ||
+ | <?php | ||
+ | /** | ||
+ | * vzapi helper functions | ||
+ | * $Header: / | ||
+ | */ | ||
+ | |||
/** | /** | ||
* get a curl channel | * get a curl channel | ||
Zeile 70: | Zeile 172: | ||
// Set the url | // Set the url | ||
curl_setopt($ch, | curl_setopt($ch, | ||
+ | |||
return $ch; | return $ch; | ||
} | } | ||
- | | + | |
/** | /** | ||
* read the given url | * read the given url | ||
Zeile 80: | 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 97: | Zeile 199: | ||
} | } | ||
rtrim($fields_string, | rtrim($fields_string, | ||
- | curl_setopt($ch, | + | |
curl_setopt($ch, | curl_setopt($ch, | ||
- | $result=curl_exec($ch); | + | |
return $result; | return $result; | ||
} | } | ||
- | + | ||
/** | /** | ||
- | * read the meter | + | * post data to vz middleware |
+ | * param 1: vzurl - middleware url of volkszaehler | ||
+ | * param 2: channel uuid | ||
+ | * param 3: value to post | ||
*/ | */ | ||
- | | + | |
- | $json=readUrl($url); | + | // post data to middleware according to: |
- | + | // http:// | |
- | // get the meter reading | + | |
- | $meter=json_decode($json, true); | + | // adapt timestamp to volkszaehler conventions |
- | // Will dump a beauty json :3 | + | $timestamp=time()*1000; |
- | // comment out next line if you'd like to debug the json message | + | |
- | // var_dump($meter); | + | # first |
- | | + | |
+ | | ||
+ | $presult=postUrl($posturl, | ||
+ | | ||
+ | echo $presult; | ||
+ | } | ||
} | } | ||
- | + | ||
- | | + | /** |
- | * transfer youless reading to vz middleware | + | |
- | | + | |
- | | + | */ |
- | | + | function |
- | * param 4: channel uuid for energy reading in kWh | + | |
- | | + | |
- | | + | |
- | // read data from youless | + | die(" |
- | | + | } |
- | // get values | + | |
- | $pwr=$meter[" | + | ?> |
- | | + | </code> |
- | // the level is not interesting for digital meters | + | |
- | // if you have an analog meter you might want to use and show this | + | |
- | | + | |
- | // convert to php compatible value | + | The last file ist the yl.sh. The script automatically will be started |
- | | + | |
- | // calculate Wh from kWh | + | |
- | | + | |
- | + | ||
- | // get human readable time stamp | + | |
- | | + | |
- | // display progress (comment if you use this in cron job) | + | Type the following in your console: |
- | echo "$now $cnt kWh $pwr Watt\n"; | + | < |
- | + | Insert the following code and press "STRG" | |
- | | + | <code bash yl.sh> |
- | | + | #!/bin/bash |
+ | while true | ||
+ | do | ||
+ | php /etc/yl.php \ | ||
+ | --url=" | ||
+ | --vzurl=" | ||
+ | --cuuid_pwr=" | ||
+ | --cuuid_cnt=" | ||
+ | --delay=15 \ | ||
+ | --cnt_modulo=12 \ | ||
+ | --loop | ||
+ | done | ||
+ | exit 0 | ||
+ | </ | ||
- | # first post the power reading in Watt | + | Here is a statement of the parameter |
- | | + | * $url - the url to read the youless from |
- | | + | * $vzurl |
- | | + | * $cuuid_pwr |
+ | | ||
+ | * $delay - how long to wait between posts default: 5 secs / 12 readings per minute | ||
+ | | ||
- | # then the energy reading in Wh | + | To make the sh-file executable for crontab (Taskmgr) you have to give the rights. Type the following into your console: |
- | $posturl=$vzurl." | + | < |
- | $fields=array(" | + | sudo chmod +x /etc/yl.sh |
- | | + | </code> |
- | // uncomment to debug | + | To edit the crontab type |
- | | + | < |
- | } | + | sudo nano /etc/rc.local |
+ | </code> | ||
+ | and add the following line on the bottom of the file, before the line "exit 0": | ||
+ | < | ||
+ | bash /etc/ | ||
+ | </ | ||
- | // modify the follwing parts to your needs | + | So that's it. now it should work. |
- | // the url to read from | + | |
- | $url=" | + | |
- | $vzurl=" | + | |
- | + | ||
- | // channel uuids | + | |
- | // power (watts) | + | |
- | $cuuid_pwr=" | + | |
- | // energy (kWh) | + | |
- | $cuuid_cnt=" | + | |
- | + | ||
- | // how often to post to middlewhere | + | |
- | $delay=5; // delay in seconds between posts | + | |
- | while (true) { | + | |
- | youless2vz($url, | + | |
- | sleep($delay); | + | |
- | } | + | |
- | + | ||
- | ?> | + | |
+ | |||
+ | You also can test your configuration if you enter the following code in your console: | ||
+ | < | ||
+ | php /etc/yl.php \ | ||
+ | --url=" | ||
+ | --vzurl=" | ||
+ | --cuuid_pwr=" | ||
+ | --cuuid_cnt=" | ||
+ | --delay=15 \ | ||
+ | --cnt_modulo=12 \ | ||
+ | --loop | ||
+ | done | ||
+ | exit 0 | ||
</ | </ | ||
+ | |||
+ | the output should look like: | ||
+ | < | ||
+ | 2017-04-29 10:59:00 YL: 640 Watt | ||
+ | 2017-04-29 10:59:05 YL: 639 Watt | ||
+ | 2017-04-29 10:59:10 YL: 639 Watt | ||
+ | </ | ||
+ | |||
+ | |||
+ | For any feedback please contact wf (at) bitplan.com or tiedi (at) web.de. Enjoy ... | ||
+ | |||
+ | |||
+ | [[https:// | ||
+ | |||
+ | |||
hardware/controllers/youless.1401364992.txt.gz · Zuletzt geändert: 2014/05/29 14:03 von wf_bitplan.com