<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[BeeClear Forums - Application Programming Interface (API)]]></title>
		<link>https://forum.beeclear.nl/</link>
		<description><![CDATA[BeeClear Forums - https://forum.beeclear.nl]]></description>
		<pubDate>Fri, 17 Apr 2026 10:45:21 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[Domoticz voorbeeld II (puur python)]]></title>
			<link>https://forum.beeclear.nl/showthread.php?tid=63</link>
			<pubDate>Sun, 03 Mar 2019 08:32:18 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.beeclear.nl/member.php?action=profile&uid=1">forumadmin</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.beeclear.nl/showthread.php?tid=63</guid>
			<description><![CDATA[Hieronder een 2e voorbeeld van een Python script voor Domoticz. <br />
Als extra zal er nog een cron job moeten worden aangemaakt.<br />
Met als regel:<br />
<br />
*/5  * * * * python /home/pi/domoticz/scripts/beeclear.py<br />
<br />
Sneller laten updaten naar domoticz heeft voor de logging geen zin, omdat dit niet wordt opgeslagen door Domoticz. <br />
<br />
<br />
//////////////////Begin script//////////////////////////////////////////////////////<br />
<br />
#! /usr/bin/python<br />
# --------------------------------------------------<br />
# PREPARATION &amp; SETTINGS<br />
# --------------------------------------------------<br />
import urllib2<br />
import urllib<br />
import base64<br />
import subprocess<br />
<br />
domoticz_P1 = "44"    # IDX for virtual P1-meter<br />
domoticz_GAS = "43"    # IDX for virtual GAS-meter<br />
<br />
# --------------------------------------------------<br />
# READING BEECLEAR<br />
# --------------------------------------------------<br />
<br />
host = '192.168.xxx.xxx'<br />
username = 'beeclear'<br />
password = 'energie'<br />
<br />
class beeclear:<br />
   def __init__( self, hostname, user, passwd ):<br />
   self.hostname = hostname<br />
   self.user = user<br />
   self.passwd = passwd<br />
   self.cookie = None;<br />
   def connect( self ):<br />
   post_args = urllib.urlencode( { 'username':  base64.b64encode(self.user), 'password': base64.b64encode(self.passwd) } )<br />
   url = 'http://' + self.hostname + '/bc_login?' + post_args;<br />
   req1 = urllib2.Request(url)<br />
   response = urllib2.urlopen(req1)<br />
   self.cookie = response.headers.get('Set-Cookie')<br />
   def send( self, command ):<br />
   url = 'http://' + self.hostname + '/' + command<br />
   req = urllib2.Request(url)<br />
   req.add_header('cookie', self.cookie)<br />
   f = urllib2.urlopen(req)<br />
   data = f.read()<br />
   f.close<br />
   return data<br />
<br />
<br />
a = beeclear( host, username, password )<br />
a.connect()<br />
<br />
<br />
Str_beeclear = a.send ( 'bc_current' )<br />
Str_beeclear = str(Str_beeclear)<br />
<br />
<br />
# "d":1429103361, // d: date unix time (time of most recent meter telegram data)<br />
# "ul":1061049, // ul: used low (KWH * 1000) (meter total used low)<br />
# "uh":883337, // uh: used high (KWH * 1000) (meter total used high)<br />
# "gl":123574, // gl: generated low (KWH * 1000) (meter total generated low)<br />
# "gh":334551, // gh: generated high (KWH * 1000) (meter total generated high)<br />
# "u":0.000, // u: current usage in KW (current active electricity usage)<br />
# "g":1.934, // g: current generating in KW (current active electricity generating)<br />
# "gas":1142889 } //gas: gas usage in cubicle meters m3 * 1000 (meter total used gas)<br />
<br />
ul= Str_beeclear[Str_beeclear.find("ul")+4:Str_beeclear.find("uh")-2]<br />
uh= Str_beeclear[Str_beeclear.find("uh")+4:Str_beeclear.find("gl")-2]<br />
gl= Str_beeclear[Str_beeclear.find("gl")+4:Str_beeclear.find("gh")-2]<br />
gh= Str_beeclear[Str_beeclear.find("gh")+4:Str_beeclear.find('"u"')-1]<br />
u= Str_beeclear[Str_beeclear.find('"u"')+4:Str_beeclear.find('"g"')-1]<br />
g= Str_beeclear[Str_beeclear.find('"g"')+4:Str_beeclear.find('"gas"')-1]<br />
gas= Str_beeclear[Str_beeclear.find("gas")+22:Str_beeclear.find("time")-2]<br />
<br />
# --------------------------------------------------<br />
# CHANGE VARIABLES NAMES INTO DOMOTICZ LANGUAGE<br />
# --------------------------------------------------<br />
<br />
USAGE1 = ul<br />
USAGE2 = uh<br />
RETURN1 = gl<br />
RETURN2 = gh<br />
CONS = u<br />
PROD = g<br />
USAGE = gas <br />
<br />
# --------------------------------------------------<br />
# START OF UPLOAD TO DOMOTICZ<br />
# --------------------------------------------------<br />
<br />
#update P1 in Domoticz<br />
httpresponse = urllib.urlopen("http://localhost:8080/json.htm?type=command&amp;param=udevice&amp;idx=" + str(domoticz_P1) + "&amp;nvalue=0&amp;svalue=" + str(USAGE1) + ";" + str(USAGE2) + ";" + str(RETURN1) + ";" + str(RETURN2) + ";" + str(CONS) + ";" + str(PROD) )<br />
<br />
#update Gas in Domoticz<br />
httpresponse = urllib.urlopen("http://localhost:8080/json.htm?type=command&amp;param=udevice&amp;idx=" + str(domoticz_GAS) + "&amp;nvalue=0&amp;svalue=" + str(USAGE) )<br />
<br />
<br />
//////////////////Einde script//////////////////////////////////////////////////////]]></description>
			<content:encoded><![CDATA[Hieronder een 2e voorbeeld van een Python script voor Domoticz. <br />
Als extra zal er nog een cron job moeten worden aangemaakt.<br />
Met als regel:<br />
<br />
*/5  * * * * python /home/pi/domoticz/scripts/beeclear.py<br />
<br />
Sneller laten updaten naar domoticz heeft voor de logging geen zin, omdat dit niet wordt opgeslagen door Domoticz. <br />
<br />
<br />
//////////////////Begin script//////////////////////////////////////////////////////<br />
<br />
#! /usr/bin/python<br />
# --------------------------------------------------<br />
# PREPARATION &amp; SETTINGS<br />
# --------------------------------------------------<br />
import urllib2<br />
import urllib<br />
import base64<br />
import subprocess<br />
<br />
domoticz_P1 = "44"    # IDX for virtual P1-meter<br />
domoticz_GAS = "43"    # IDX for virtual GAS-meter<br />
<br />
# --------------------------------------------------<br />
# READING BEECLEAR<br />
# --------------------------------------------------<br />
<br />
host = '192.168.xxx.xxx'<br />
username = 'beeclear'<br />
password = 'energie'<br />
<br />
class beeclear:<br />
   def __init__( self, hostname, user, passwd ):<br />
   self.hostname = hostname<br />
   self.user = user<br />
   self.passwd = passwd<br />
   self.cookie = None;<br />
   def connect( self ):<br />
   post_args = urllib.urlencode( { 'username':  base64.b64encode(self.user), 'password': base64.b64encode(self.passwd) } )<br />
   url = 'http://' + self.hostname + '/bc_login?' + post_args;<br />
   req1 = urllib2.Request(url)<br />
   response = urllib2.urlopen(req1)<br />
   self.cookie = response.headers.get('Set-Cookie')<br />
   def send( self, command ):<br />
   url = 'http://' + self.hostname + '/' + command<br />
   req = urllib2.Request(url)<br />
   req.add_header('cookie', self.cookie)<br />
   f = urllib2.urlopen(req)<br />
   data = f.read()<br />
   f.close<br />
   return data<br />
<br />
<br />
a = beeclear( host, username, password )<br />
a.connect()<br />
<br />
<br />
Str_beeclear = a.send ( 'bc_current' )<br />
Str_beeclear = str(Str_beeclear)<br />
<br />
<br />
# "d":1429103361, // d: date unix time (time of most recent meter telegram data)<br />
# "ul":1061049, // ul: used low (KWH * 1000) (meter total used low)<br />
# "uh":883337, // uh: used high (KWH * 1000) (meter total used high)<br />
# "gl":123574, // gl: generated low (KWH * 1000) (meter total generated low)<br />
# "gh":334551, // gh: generated high (KWH * 1000) (meter total generated high)<br />
# "u":0.000, // u: current usage in KW (current active electricity usage)<br />
# "g":1.934, // g: current generating in KW (current active electricity generating)<br />
# "gas":1142889 } //gas: gas usage in cubicle meters m3 * 1000 (meter total used gas)<br />
<br />
ul= Str_beeclear[Str_beeclear.find("ul")+4:Str_beeclear.find("uh")-2]<br />
uh= Str_beeclear[Str_beeclear.find("uh")+4:Str_beeclear.find("gl")-2]<br />
gl= Str_beeclear[Str_beeclear.find("gl")+4:Str_beeclear.find("gh")-2]<br />
gh= Str_beeclear[Str_beeclear.find("gh")+4:Str_beeclear.find('"u"')-1]<br />
u= Str_beeclear[Str_beeclear.find('"u"')+4:Str_beeclear.find('"g"')-1]<br />
g= Str_beeclear[Str_beeclear.find('"g"')+4:Str_beeclear.find('"gas"')-1]<br />
gas= Str_beeclear[Str_beeclear.find("gas")+22:Str_beeclear.find("time")-2]<br />
<br />
# --------------------------------------------------<br />
# CHANGE VARIABLES NAMES INTO DOMOTICZ LANGUAGE<br />
# --------------------------------------------------<br />
<br />
USAGE1 = ul<br />
USAGE2 = uh<br />
RETURN1 = gl<br />
RETURN2 = gh<br />
CONS = u<br />
PROD = g<br />
USAGE = gas <br />
<br />
# --------------------------------------------------<br />
# START OF UPLOAD TO DOMOTICZ<br />
# --------------------------------------------------<br />
<br />
#update P1 in Domoticz<br />
httpresponse = urllib.urlopen("http://localhost:8080/json.htm?type=command&amp;param=udevice&amp;idx=" + str(domoticz_P1) + "&amp;nvalue=0&amp;svalue=" + str(USAGE1) + ";" + str(USAGE2) + ";" + str(RETURN1) + ";" + str(RETURN2) + ";" + str(CONS) + ";" + str(PROD) )<br />
<br />
#update Gas in Domoticz<br />
httpresponse = urllib.urlopen("http://localhost:8080/json.htm?type=command&amp;param=udevice&amp;idx=" + str(domoticz_GAS) + "&amp;nvalue=0&amp;svalue=" + str(USAGE) )<br />
<br />
<br />
//////////////////Einde script//////////////////////////////////////////////////////]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Voorbeeld API gebruik en Raspberry Pi]]></title>
			<link>https://forum.beeclear.nl/showthread.php?tid=51</link>
			<pubDate>Fri, 21 Dec 2018 12:32:26 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.beeclear.nl/member.php?action=profile&uid=52">max</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.beeclear.nl/showthread.php?tid=51</guid>
			<description><![CDATA[<span style="font-family: Arial;" class="mycode_font">Hierbij een voorbeeld van het gebruik van de BeeClear API op een Raspberry Pi (maar werkt natuurlijk op elke web browser).</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font"><a href="http://mxx.ovh/dAjsrAc1gn/IMG_2278.jpg" target="_blank" rel="noopener" class="mycode_url">http://mxx.ovh/dAjsrAc1gn/IMG_2278.jpg</a></span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">De temperatuur komt via een api van mijn Netatmo en de energie metrics komen van BeeClear. Dit alles op een eenvoudige webbrowser (Epiphany) omdat ik het scherm op de Raspberry Pi niet werkend krijg in combinatie met Chromium.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Dit alles is gemaakt met PHP een klein beetje Java-script. Ik kan het volledige script hier wel plaatsen maar dat werkt alleen als je ook een Netatmo hebt (voor de temperatuur).</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Het gedeelte waarmee ik via PHP de data ophaal staat hieronder.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Deze php files worden included in de hoofdpagina en vanuit de hoofdpagina kunnen de variabelen dan gebruikt worden.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Bijvoorbeeld, &#36;data_bc_current laat dus het huidige verbruik zien en &#36;data_bc_getval_elek_today laat het totaal verbruik van vandaag tot en met nu zien.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">De grafiekjes zijn wat lastiger en worden vanuit de hoofdpagina als volgt aangeroepen:</span><br />
<span style="font-family: Arial;" class="mycode_font">&lt;?php echo "&lt;img src=\"graph.php?".&#36;get_elek_graph."\" alt=\"\" /&gt;"; ?&gt;</span><br />
<span style="font-family: Arial;" class="mycode_font">&lt;?php echo "&lt;img src=\"graph.php?".&#36;get_gas_graph."\" alt=\"\" /&gt;"; ?&gt;</span><br />
<br />
De parameters (&#36;get_elek_graph en &#36;get_gas_graph, die de inhoud van de grafiek bepalen) worden met de getoonde PHP scripts gegenereerd.<br />
<br />
<span style="font-family: Arial;" class="mycode_font">Het graph.php script staat hieronder ook weergegeven (3de script), overigens heb ik dit ergens van internet 'geleend' en iets aangepast.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Dat is zo'n beetje de opzet. Mocht je de scripts willen hebben dan kan ik die met alle plezier opsturen maar dan moet je zelf de Netatmo zooi er uit slopen (of je moet ook toevallig een Netatmo hebben).</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Script 1, haal het huidige verbruik op.</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php</span><br />
<span style="font-family: Courier New;" class="mycode_font">        date_default_timezone_set ("Europe/Amsterdam");</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;url = 'http://beeclear.local/bc_current';</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_current = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Scripts 2, haal het gebruik van vandaag per uur en het totaal op.</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php<br />
</span><br />
<span style="font-family: Courier New;" class="mycode_font">    date_default_timezone_set ("Europe/Amsterdam");</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;epoch=time();</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;epoch=&#36;epoch- (&#36;epoch % 86400) - 3600;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;url = "http://beeclear.local/bc_getVal?type=gas&amp;date=&#36;epoch&amp;duration=day&amp;period=hour";</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_getval = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gas_total=0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_gas_graph="";</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1; &#36;i&lt;24; &#36;i++) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_gas_graph.=&#36;i."h=".&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['g']."&amp;";</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gas_total+=&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['g'];</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;data_bc_getval_gas_today = sprintf('%0.3f', &#36;gas_total/1000);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;url = "http://beeclear.local/bc_getVal?type=elek&amp;date=&#36;epoch&amp;duration=day&amp;period=hour";</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_getval = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;elek_total=0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_elek_graph="";</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1; &#36;i&lt;24; &#36;i++) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;this_elek=&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['v']+&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['vl'];</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_elek_graph.=&#36;i."h=".&#36;this_elek."&amp;";</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;elek_total+=&#36;this_elek;</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;data_bc_getval_elek_today = sprintf('%0.3f', &#36;elek_total/1000);</span><br />
<span style="font-family: Courier New;" class="mycode_font">#echo &#36;data_bc_getval_elek_today;</span><br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Script 3, grafiekjes maken</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php<br />
</span><br />
<span style="font-family: Courier New;" class="mycode_font"># ------- The graph values in the form of associative array</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># values array is filles from other function</span><br />
<span style="font-family: Courier New;" class="mycode_font">#&#36;values= array( "1" =&gt; 100, "2" =&gt; 250, "3" =&gt; 300 );</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;values = &#36;_GET;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img_width=220;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img_height=120; </span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;margins=20;</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ---- Find the size of graph by substracting the size of borders</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;graph_width=&#36;img_width - &#36;margins * 2;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;graph_height=&#36;img_height - &#36;margins * 2; </span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img=imagecreate(&#36;img_width,&#36;img_height);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;bar_width=5;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;total_bars=count(&#36;values);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gap= (&#36;graph_width- &#36;total_bars * &#36;bar_width ) / (&#36;total_bars +1);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># -------  Define Colors ----------------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;bar_color=imagecolorallocate(&#36;img,40,255,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;xvalues_color=imagecolorallocate(&#36;img,255,255,255);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;background_color=imagecolorallocate(&#36;img,0,0,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;border_color=imagecolorallocate(&#36;img,0,0,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;line_color=imagecolorallocate(&#36;img,220,220,220);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ------ Create the border around the graph ------</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">#imagefilledrectangle(&#36;img,1,1,&#36;img_width-2,&#36;img_height-2,&#36;border_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagefilledrectangle(&#36;img,0,0,&#36;img_width,&#36;img_height,&#36;border_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagefilledrectangle(&#36;img,&#36;margins,&#36;margins,&#36;img_width-1-&#36;margins,&#36;img_height-1-&#36;margins,&#36;background_color);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ------- Max value is required to adjust the scale -------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;max_value=(intval(max(&#36;values)/500)+1)*500;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;ratio= &#36;graph_height/&#36;max_value;</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># -------- Create scale and draw horizontal lines  --------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;horizontal_lines=4;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;horizontal_gap=&#36;graph_height/&#36;horizontal_lines;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1;&#36;i&lt;=&#36;horizontal_lines;&#36;i++){</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y=&#36;img_height - &#36;margins - &#36;horizontal_gap * &#36;i ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imageline(&#36;img,&#36;margins,&#36;y,&#36;img_width-&#36;margins,&#36;y,&#36;line_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;v=intval(&#36;horizontal_gap * &#36;i /&#36;ratio);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagestring(&#36;img,0,0,&#36;y-5,&#36;v,&#36;xvalues_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ----------- Draw the bars here ------</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=0;&#36;i&lt; &#36;total_bars; &#36;i++){ </span><br />
<span style="font-family: Courier New;" class="mycode_font">    # ------ Extract key and value pair from the current pointer position</span><br />
<span style="font-family: Courier New;" class="mycode_font">    list(&#36;key,&#36;value)=each(&#36;values); </span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;x1= &#36;margins + &#36;gap + &#36;i * (&#36;gap+&#36;bar_width) ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;x2= &#36;x1 + &#36;bar_width; </span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y1=&#36;margins +&#36;graph_height- intval(&#36;value * &#36;ratio) ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y2=&#36;img_height-&#36;margins;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    #imagestring(&#36;img,0,&#36;x1+3,&#36;y1-10,&#36;value,&#36;bar_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    if ( &#36;i % 4 == 0 ) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagestring(&#36;img,0,&#36;x1+3,&#36;img_height-15,&#36;key,&#36;xvalues_color); </span><br />
<span style="font-family: Courier New;" class="mycode_font">    }</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagefilledrectangle(&#36;img,&#36;x1,&#36;y1,&#36;x2,&#36;y2,&#36;bar_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">header("Content-type:image/png");</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagepng(&#36;img);</span><br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span>]]></description>
			<content:encoded><![CDATA[<span style="font-family: Arial;" class="mycode_font">Hierbij een voorbeeld van het gebruik van de BeeClear API op een Raspberry Pi (maar werkt natuurlijk op elke web browser).</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font"><a href="http://mxx.ovh/dAjsrAc1gn/IMG_2278.jpg" target="_blank" rel="noopener" class="mycode_url">http://mxx.ovh/dAjsrAc1gn/IMG_2278.jpg</a></span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">De temperatuur komt via een api van mijn Netatmo en de energie metrics komen van BeeClear. Dit alles op een eenvoudige webbrowser (Epiphany) omdat ik het scherm op de Raspberry Pi niet werkend krijg in combinatie met Chromium.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Dit alles is gemaakt met PHP een klein beetje Java-script. Ik kan het volledige script hier wel plaatsen maar dat werkt alleen als je ook een Netatmo hebt (voor de temperatuur).</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Het gedeelte waarmee ik via PHP de data ophaal staat hieronder.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Deze php files worden included in de hoofdpagina en vanuit de hoofdpagina kunnen de variabelen dan gebruikt worden.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Bijvoorbeeld, &#36;data_bc_current laat dus het huidige verbruik zien en &#36;data_bc_getval_elek_today laat het totaal verbruik van vandaag tot en met nu zien.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">De grafiekjes zijn wat lastiger en worden vanuit de hoofdpagina als volgt aangeroepen:</span><br />
<span style="font-family: Arial;" class="mycode_font">&lt;?php echo "&lt;img src=\"graph.php?".&#36;get_elek_graph."\" alt=\"\" /&gt;"; ?&gt;</span><br />
<span style="font-family: Arial;" class="mycode_font">&lt;?php echo "&lt;img src=\"graph.php?".&#36;get_gas_graph."\" alt=\"\" /&gt;"; ?&gt;</span><br />
<br />
De parameters (&#36;get_elek_graph en &#36;get_gas_graph, die de inhoud van de grafiek bepalen) worden met de getoonde PHP scripts gegenereerd.<br />
<br />
<span style="font-family: Arial;" class="mycode_font">Het graph.php script staat hieronder ook weergegeven (3de script), overigens heb ik dit ergens van internet 'geleend' en iets aangepast.</span><br />
<br />
<span style="font-family: Arial;" class="mycode_font">Dat is zo'n beetje de opzet. Mocht je de scripts willen hebben dan kan ik die met alle plezier opsturen maar dan moet je zelf de Netatmo zooi er uit slopen (of je moet ook toevallig een Netatmo hebben).</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Script 1, haal het huidige verbruik op.</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php</span><br />
<span style="font-family: Courier New;" class="mycode_font">        date_default_timezone_set ("Europe/Amsterdam");</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;url = 'http://beeclear.local/bc_current';</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_current = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Scripts 2, haal het gebruik van vandaag per uur en het totaal op.</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php<br />
</span><br />
<span style="font-family: Courier New;" class="mycode_font">    date_default_timezone_set ("Europe/Amsterdam");</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;epoch=time();</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;epoch=&#36;epoch- (&#36;epoch % 86400) - 3600;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;url = "http://beeclear.local/bc_getVal?type=gas&amp;date=&#36;epoch&amp;duration=day&amp;period=hour";</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_getval = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gas_total=0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_gas_graph="";</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1; &#36;i&lt;24; &#36;i++) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_gas_graph.=&#36;i."h=".&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['g']."&amp;";</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gas_total+=&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['g'];</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;data_bc_getval_gas_today = sprintf('%0.3f', &#36;gas_total/1000);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;url = "http://beeclear.local/bc_getVal?type=elek&amp;date=&#36;epoch&amp;duration=day&amp;period=hour";</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;curl = curl_init();</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_URL, &#36;url);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        curl_setopt(&#36;curl, CURLOPT_RETURNTRANSFER, 1);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;json = curl_exec(&#36;curl);</span><br />
<span style="font-family: Courier New;" class="mycode_font">        &#36;data_bc_getval = json_decode(&#36;json, TRUE);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;elek_total=0;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_elek_graph="";</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1; &#36;i&lt;24; &#36;i++) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;this_elek=&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['v']+&#36;data_bc_getval['meetwaarden'][0]['val'][&#36;i]['vl'];</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;get_elek_graph.=&#36;i."h=".&#36;this_elek."&amp;";</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;elek_total+=&#36;this_elek;</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;data_bc_getval_elek_today = sprintf('%0.3f', &#36;elek_total/1000);</span><br />
<span style="font-family: Courier New;" class="mycode_font">#echo &#36;data_bc_getval_elek_today;</span><br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span><br />
<br />
<span style="font-weight: bold;" class="mycode_b">Script 3, grafiekjes maken</span><br />
<span style="font-family: Courier New;" class="mycode_font">&lt;?php<br />
</span><br />
<span style="font-family: Courier New;" class="mycode_font"># ------- The graph values in the form of associative array</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># values array is filles from other function</span><br />
<span style="font-family: Courier New;" class="mycode_font">#&#36;values= array( "1" =&gt; 100, "2" =&gt; 250, "3" =&gt; 300 );</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;values = &#36;_GET;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img_width=220;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img_height=120; </span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;margins=20;</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ---- Find the size of graph by substracting the size of borders</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;graph_width=&#36;img_width - &#36;margins * 2;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;graph_height=&#36;img_height - &#36;margins * 2; </span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;img=imagecreate(&#36;img_width,&#36;img_height);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font">&#36;bar_width=5;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;total_bars=count(&#36;values);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;gap= (&#36;graph_width- &#36;total_bars * &#36;bar_width ) / (&#36;total_bars +1);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># -------  Define Colors ----------------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;bar_color=imagecolorallocate(&#36;img,40,255,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;xvalues_color=imagecolorallocate(&#36;img,255,255,255);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;background_color=imagecolorallocate(&#36;img,0,0,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;border_color=imagecolorallocate(&#36;img,0,0,0);</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;line_color=imagecolorallocate(&#36;img,220,220,220);</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ------ Create the border around the graph ------</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">#imagefilledrectangle(&#36;img,1,1,&#36;img_width-2,&#36;img_height-2,&#36;border_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagefilledrectangle(&#36;img,0,0,&#36;img_width,&#36;img_height,&#36;border_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagefilledrectangle(&#36;img,&#36;margins,&#36;margins,&#36;img_width-1-&#36;margins,&#36;img_height-1-&#36;margins,&#36;background_color);</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ------- Max value is required to adjust the scale -------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;max_value=(intval(max(&#36;values)/500)+1)*500;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;ratio= &#36;graph_height/&#36;max_value;</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># -------- Create scale and draw horizontal lines  --------</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;horizontal_lines=4;</span><br />
<span style="font-family: Courier New;" class="mycode_font">&#36;horizontal_gap=&#36;graph_height/&#36;horizontal_lines;</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=1;&#36;i&lt;=&#36;horizontal_lines;&#36;i++){</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y=&#36;img_height - &#36;margins - &#36;horizontal_gap * &#36;i ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imageline(&#36;img,&#36;margins,&#36;y,&#36;img_width-&#36;margins,&#36;y,&#36;line_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;v=intval(&#36;horizontal_gap * &#36;i /&#36;ratio);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagestring(&#36;img,0,0,&#36;y-5,&#36;v,&#36;xvalues_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<br />
<span style="font-family: Courier New;" class="mycode_font"># ----------- Draw the bars here ------</span><br />
<span style="font-family: Courier New;" class="mycode_font">for(&#36;i=0;&#36;i&lt; &#36;total_bars; &#36;i++){ </span><br />
<span style="font-family: Courier New;" class="mycode_font">    # ------ Extract key and value pair from the current pointer position</span><br />
<span style="font-family: Courier New;" class="mycode_font">    list(&#36;key,&#36;value)=each(&#36;values); </span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;x1= &#36;margins + &#36;gap + &#36;i * (&#36;gap+&#36;bar_width) ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;x2= &#36;x1 + &#36;bar_width; </span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y1=&#36;margins +&#36;graph_height- intval(&#36;value * &#36;ratio) ;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    &#36;y2=&#36;img_height-&#36;margins;</span><br />
<span style="font-family: Courier New;" class="mycode_font">    #imagestring(&#36;img,0,&#36;x1+3,&#36;y1-10,&#36;value,&#36;bar_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">    if ( &#36;i % 4 == 0 ) {</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagestring(&#36;img,0,&#36;x1+3,&#36;img_height-15,&#36;key,&#36;xvalues_color); </span><br />
<span style="font-family: Courier New;" class="mycode_font">    }</span><br />
<span style="font-family: Courier New;" class="mycode_font">    imagefilledrectangle(&#36;img,&#36;x1,&#36;y1,&#36;x2,&#36;y2,&#36;bar_color);</span><br />
<span style="font-family: Courier New;" class="mycode_font">}</span><br />
<br />
<span style="font-family: Courier New;" class="mycode_font">header("Content-type:image/png");</span><br />
<span style="font-family: Courier New;" class="mycode_font">imagepng(&#36;img);</span><br />
<span style="font-family: Courier New;" class="mycode_font">?&gt;</span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Domoticz voorbeeld]]></title>
			<link>https://forum.beeclear.nl/showthread.php?tid=13</link>
			<pubDate>Tue, 05 Jun 2018 17:44:25 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.beeclear.nl/member.php?action=profile&uid=1">forumadmin</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.beeclear.nl/showthread.php?tid=13</guid>
			<description><![CDATA[Beste BeeClear bezitter,<br />
<br />
Hieronder een voorbeeld in python van een Domoticz gebruiker (Erik). Het mooiste is het als de code in <br />
een versie managementsysteem geplaatst wordt zoals "git".  Dan kunnen we naar de source verwijzen met een link. <br />
<br />
<br />
////////////////////////////////////////////////begin script///////////////////////////////////////////////////////////////////////////<br />
<br />
<br />
<span style="color: #000000;" class="mycode_color">#! /usr/bin/python<br />
import urllib2<br />
import urllib<br />
import base64<br />
import subprocess<br />
<br />
host = '192.168.0.20'<br />
username = 'beeclear'<br />
password = 'wachtwoord'<br />
<br />
class beeclear:<br />
        def __init__( self, hostname, user, passwd ):<br />
                self.hostname = hostname<br />
                self.user = user<br />
                self.passwd = passwd<br />
                self.cookie = None;<br />
        def connect( self ):<br />
                post_args = urllib.urlencode( { 'username':  base64.b64encode(self.user), 'password': base64.b64encode(self.passwd) } )<br />
                url = 'http://' + self.hostname + '/bc_login?' + post_args;<br />
                req1 = urllib2.Request(url)<br />
                response = urllib2.urlopen(req1)<br />
                self.cookie = response.headers.get('Set-Cookie')<br />
        def send( self, command ):<br />
                url = 'http://' + self.hostname + '/' + command<br />
                req = urllib2.Request(url)<br />
                req.add_header('cookie', self.cookie)<br />
                f = urllib2.urlopen(req)<br />
                data = f.read()<br />
                f.close<br />
                return data<br />
<br />
<br />
a = beeclear( host, username, password )<br />
a.connect()<br />
<br />
<br />
Str_beeclear = a.send ( 'bc_current' )<br />
Str_beeclear = str(Str_beeclear)<br />
<br />
ul= Str_beeclear[Str_beeclear.find("ul")+4:Str_beeclear.find("uh")-2]<br />
uh= Str_beeclear[Str_beeclear.find("uh")+4:Str_beeclear.find("gl")-2]<br />
gl= Str_beeclear[Str_beeclear.find("gl")+4:Str_beeclear.find("gh")-2]<br />
gh= Str_beeclear[Str_beeclear.find("gh")+4:Str_beeclear.find('"u"')-1]<br />
gas= Str_beeclear[Str_beeclear.find("gas")+5:Str_beeclear.find("gd")-2]<br />
Eu= Str_beeclear[Str_beeclear.find('"u"')+4:Str_beeclear.find('"g"')-1]<br />
Eg= Str_beeclear[Str_beeclear.find('"g"')+4:Str_beeclear.find('"gas"')-1]<br />
<br />
Netto= (int(gl)+int(gh)-int(ul)-int(uh))<br />
str(Netto)<br />
<br />
<br />
#update Netto in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=45&amp;nvalue=0&amp;svalue="'+str(Netto))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
<br />
#update Gas in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=53&amp;nvalue=0&amp;svalue="'+str(gas))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-export in high tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=60&amp;nvalue=0&amp;svalue="'+str(gh))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-import in high tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=61&amp;nvalue=0&amp;svalue="'+str(uh))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-import in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=59&amp;nvalue=0&amp;svalue="'+str(ul))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-export in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=58&amp;nvalue=0&amp;svalue="'+str(gl))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=62&amp;nvalue=0&amp;svalue="'+str(Netto))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=65&amp;nvalue=0&amp;svalue="'+str(Eu))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=66&amp;nvalue=0&amp;svalue="'+str(Eg))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=69&amp;nvalue=0&amp;svalue="'+str(Netto/1000))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
<br />
///////////////////////////////////////////////////////einde script////////////////////////////////////////////////////////////////////<br />
</span>]]></description>
			<content:encoded><![CDATA[Beste BeeClear bezitter,<br />
<br />
Hieronder een voorbeeld in python van een Domoticz gebruiker (Erik). Het mooiste is het als de code in <br />
een versie managementsysteem geplaatst wordt zoals "git".  Dan kunnen we naar de source verwijzen met een link. <br />
<br />
<br />
////////////////////////////////////////////////begin script///////////////////////////////////////////////////////////////////////////<br />
<br />
<br />
<span style="color: #000000;" class="mycode_color">#! /usr/bin/python<br />
import urllib2<br />
import urllib<br />
import base64<br />
import subprocess<br />
<br />
host = '192.168.0.20'<br />
username = 'beeclear'<br />
password = 'wachtwoord'<br />
<br />
class beeclear:<br />
        def __init__( self, hostname, user, passwd ):<br />
                self.hostname = hostname<br />
                self.user = user<br />
                self.passwd = passwd<br />
                self.cookie = None;<br />
        def connect( self ):<br />
                post_args = urllib.urlencode( { 'username':  base64.b64encode(self.user), 'password': base64.b64encode(self.passwd) } )<br />
                url = 'http://' + self.hostname + '/bc_login?' + post_args;<br />
                req1 = urllib2.Request(url)<br />
                response = urllib2.urlopen(req1)<br />
                self.cookie = response.headers.get('Set-Cookie')<br />
        def send( self, command ):<br />
                url = 'http://' + self.hostname + '/' + command<br />
                req = urllib2.Request(url)<br />
                req.add_header('cookie', self.cookie)<br />
                f = urllib2.urlopen(req)<br />
                data = f.read()<br />
                f.close<br />
                return data<br />
<br />
<br />
a = beeclear( host, username, password )<br />
a.connect()<br />
<br />
<br />
Str_beeclear = a.send ( 'bc_current' )<br />
Str_beeclear = str(Str_beeclear)<br />
<br />
ul= Str_beeclear[Str_beeclear.find("ul")+4:Str_beeclear.find("uh")-2]<br />
uh= Str_beeclear[Str_beeclear.find("uh")+4:Str_beeclear.find("gl")-2]<br />
gl= Str_beeclear[Str_beeclear.find("gl")+4:Str_beeclear.find("gh")-2]<br />
gh= Str_beeclear[Str_beeclear.find("gh")+4:Str_beeclear.find('"u"')-1]<br />
gas= Str_beeclear[Str_beeclear.find("gas")+5:Str_beeclear.find("gd")-2]<br />
Eu= Str_beeclear[Str_beeclear.find('"u"')+4:Str_beeclear.find('"g"')-1]<br />
Eg= Str_beeclear[Str_beeclear.find('"g"')+4:Str_beeclear.find('"gas"')-1]<br />
<br />
Netto= (int(gl)+int(gh)-int(ul)-int(uh))<br />
str(Netto)<br />
<br />
<br />
#update Netto in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=45&amp;nvalue=0&amp;svalue="'+str(Netto))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
<br />
#update Gas in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=53&amp;nvalue=0&amp;svalue="'+str(gas))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-export in high tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=60&amp;nvalue=0&amp;svalue="'+str(gh))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-import in high tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=61&amp;nvalue=0&amp;svalue="'+str(uh))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-import in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=59&amp;nvalue=0&amp;svalue="'+str(ul))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-export in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=58&amp;nvalue=0&amp;svalue="'+str(gl))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=62&amp;nvalue=0&amp;svalue="'+str(Netto))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=65&amp;nvalue=0&amp;svalue="'+str(Eu))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
#update E-netto in low tarrif in Domoticz<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=66&amp;nvalue=0&amp;svalue="'+str(Eg))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
command = ('curl -i  "http://Dom_user:wachtwoord@192.168.0.26:8080/json.htm?type=command&amp;param=udevice&amp;idx=69&amp;nvalue=0&amp;svalue="'+str(Netto/1000))<br />
output = subprocess.check_output(['bash','-c', command])<br />
<br />
<br />
///////////////////////////////////////////////////////einde script////////////////////////////////////////////////////////////////////<br />
</span>]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Integratie met domotica (Athom Homey / Domoticz / e.a.)]]></title>
			<link>https://forum.beeclear.nl/showthread.php?tid=12</link>
			<pubDate>Tue, 29 May 2018 15:02:28 +0000</pubDate>
			<dc:creator><![CDATA[<a href="https://forum.beeclear.nl/member.php?action=profile&uid=4">ermep01</a>]]></dc:creator>
			<guid isPermaLink="false">https://forum.beeclear.nl/showthread.php?tid=12</guid>
			<description><![CDATA[Graag aandacht voor integratie van de API voor domotica-gebruikers.<br />
Zie ook <a href="https://forum.athom.com/discussion/3511/beeclear-app-dutch-meter#latest" target="_blank" rel="noopener" class="mycode_url">discussie op Homey forum</a><br />
Met jullie kennis van de API is het wellicht (redelijk) eenvoudig een app te maken die bijvoorbeeld aansluit bij de Athom Homey.<br />
Denk bijvoorbeeld aan een trigger die me meld over allerlei waarden (hoog/laag) welke worden geregistreerd door de Beeclear.<br />
Of een apparaat wordt uit- of juist ingeschakeld bij het bereiken van een bepaalde waarde.]]></description>
			<content:encoded><![CDATA[Graag aandacht voor integratie van de API voor domotica-gebruikers.<br />
Zie ook <a href="https://forum.athom.com/discussion/3511/beeclear-app-dutch-meter#latest" target="_blank" rel="noopener" class="mycode_url">discussie op Homey forum</a><br />
Met jullie kennis van de API is het wellicht (redelijk) eenvoudig een app te maken die bijvoorbeeld aansluit bij de Athom Homey.<br />
Denk bijvoorbeeld aan een trigger die me meld over allerlei waarden (hoog/laag) welke worden geregistreerd door de Beeclear.<br />
Of een apparaat wordt uit- of juist ingeschakeld bij het bereiken van een bepaalde waarde.]]></content:encoded>
		</item>
	</channel>
</rss>