Custom JavaScript

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Custom JavaScript

Post 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
n0ahg
Posts: 87
Joined: 08 May 2013 23:41

Re: Custom JavaScript

Post by n0ahg »

You'd be better of using a HTTP Device
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Re: Custom JavaScript

Post by SolarFlor »

What does it mean?
please give me some examples to learn about usage of HTTP Device
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Re: Custom JavaScript

Post by SolarFlor »

I have filled URL as in the image but I don't know how to provide all the other information
Attachments
HTTP.jpg
HTTP.jpg (26.47 KiB) Viewed 14074 times
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: Custom JavaScript

Post 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
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Re: Custom JavaScript

Post 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
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Re: Custom JavaScript

Post 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
HTTP.jpg (28.8 KiB) Viewed 13978 times
The result is as below (see PV Power)
HTTP2.jpg
HTTP2.jpg (30.39 KiB) Viewed 13978 times
The only thing wrong is that I cannot see the unit of measurement (Watts) I entered in Sensor Scale
SolarFlor
Posts: 261
Joined: 22 Mar 2014 15:23

Re: Custom JavaScript

Post 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
Attachments
HTTP3.jpg
HTTP3.jpg (29.39 KiB) Viewed 13974 times
User avatar
PoltoS
Posts: 7649
Joined: 26 Jan 2011 19:36

Re: Custom JavaScript

Post 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? ;)
isachris83
Posts: 9
Joined: 01 Jun 2013 18:12

Re: Custom JavaScript

Post 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
Post Reply