Page 1 of 1
Custom JavaScript
Posted: 23 Jun 2014 22:19
by SolarFlor
Hi,
I have a Photovoltaic system that I'm monitoring with my Raspberry PI.
I'm able to read with an URL the value of the power generated [$kw_prod] with the following script
Code: Select all
$URL_123solar = "http://192.168.1.22/123solar/programs/programmultilive.php";
$json_123solar = file_get_contents($URL_123solar);
$data_123solar = json_decode($json_123solar, true);
if (isset($data_123solar["GPTOT"]))
{
$kw_prod = $data_123solar["GPTOT"];
} else {
$kw_prod = "0";
}
# ----------------------
I would like to display the value of $kw_prod on my UI Automation.
I suppose I should use "Load custom JavaScript code" or "Load custom JavaScript file" module but honestly I don't know where to start from.
Thanks for your help
Re: Custom JavaScript
Posted: 23 Jun 2014 23:57
by n0ahg
You'd be better of using a HTTP Device
Re: Custom JavaScript
Posted: 24 Jun 2014 00:23
by SolarFlor
What does it mean?
please give me some examples to learn about usage of HTTP Device
Re: Custom JavaScript
Posted: 24 Jun 2014 00:41
by SolarFlor
I have filled URL as in the image but I don't know how to provide all the other information
Re: Custom JavaScript
Posted: 24 Jun 2014 02:20
by PoltoS
The scale is just a text, interval - obvious - in seconds, inline parser is just in case your stuff does not return a number
Re: Custom JavaScript
Posted: 24 Jun 2014 13:39
by SolarFlor
when I launch the URL on my browser I can see the following:
{"PROD":3897,"TOT_PROD":"Today (18,0 kWh)","CONS":337,"STATO":"On - Full Power","TOT_CONS":9.5,"NET":3559}
I'm interested to visualise the first value (3897). What I should write on 'inline parser'?
many thanks
Re: Custom JavaScript
Posted: 24 Jun 2014 20:56
by SolarFlor
Found it.
I create a dedicated php that is generate the value of produced power
Code: Select all
<?php
$URL_123solar = "http://192.168.1.22/123solar/programs/programmultilive.php";
$json_123solar = file_get_contents($URL_123solar);
$data_123solar = json_decode($json_123solar, true);
if (isset($data_123solar["GPTOT"]))
{
$kw_prod = $data_123solar["GPTOT"];
} else {
$kw_prod = "0";
}
echo $kw_prod
?>
and I have configured the module as below

- HTTP.jpg (28.8 KiB) Viewed 13990 times
The result is as below (see PV Power)

- HTTP2.jpg (30.39 KiB) Viewed 13990 times
The only thing wrong is that I cannot see the unit of measurement (Watts) I entered in Sensor Scale
Re: Custom JavaScript
Posted: 24 Jun 2014 22:15
by SolarFlor
I'm trying now to control a LAN Relay with HTTP Device SwitchBinary
What should be the return of the "URL to get value" to proper drive the status on/off?
Now the return is 0/1 but it doesn't work
Re: Custom JavaScript
Posted: 25 Jun 2014 00:56
by PoltoS
should be on/off (see the line below the URL getter). And instead of your php nightmare you can use JS Inline code. For your switch use:
%% ? "on" : "off"
for previous meter something like this (not tested):
JSON.parse(%%)["GPTOT"] || 0
Pretty flexible, no?

Re: Custom JavaScript
Posted: 01 Aug 2014 00:55
by isachris83
Hi,
can we have an example of inline Javascript to get the temperature of a web page (from owhttpd) like this ?
"<HTML><HEAD><TITLE>1-Wire Web: 28.3CD884030000/temperature10</TITLE></HEAD>
<BODY BGCOLOR='#BBBBBB'><TABLE WIDTH='100%' BGCOLOR='#DDDDDD' BORDER='1'><TR><TD>OWFS on localhost:4304</TD><TD><A HREF='/'>Bus listing</A></TD><TD><A HREF='http://www.owfs.org'>OWFS homepage</A></TD><TD><A HREF='http://www.maxim-ic.com'>Dallas/Maxim</A></TD><TD>by <A HREF='mailto://
palfille@earthlink.net'>Paul H Alfille</A></TD></TR></TABLE>
<H1>28.3CD884030000/temperature10</H1><HR>
<BR><small><A href='/uncached/28.3CD884030000/temperature10'>uncached version</A></small><TABLE BGCOLOR="#DDDDDD" BORDER=1><TR><TD><A HREF='/28.3CD884030000/'><CODE><B><BIG>up</BIG></B></CODE></A></TD><TD>directory</TD></TR><TR><TD><B>temperature10</B></TD><TD> 24.25</TD></TR>
</TABLE></BODY></HTML>"
I would like to get the "24.25" value.
Thanks PoltoS
Christophe