Exporting values to HTML

This might not be specific to WPI-section but figured since this is where I need it I try here.

It’s been decades since I did HTML (in my time static) and nowadays the kids are doing all kinds of magics with PHP, Java, and some I don’t even know the name of…

I need to import the pool temperature value to a .html-file and have it displayed fullscreen on a spare tablet I have no other use for. The html-file will be set to repeatable refresh so the temperature value is read for say once every fifth minute (or thenth for that matter, not important).

Is it possible to do that? And how should a string like that look for HTML? Or is it only possible in Java/other?

Perhaps I will also have the pool pump switch control a box’s color, so when it’s 1 it is green, and when it is 0 it is red.
With Reactor, I’m exporting the heating effect in kW (function of inlet-outlet temperature difference and flow speed) so it could also be cool to see that value on the display.

Hope someone can give me a push in the right direction…

I gotta ask, do you have a pool controller? If you have a Pentair Automation controller like EasyTouch, IntelliTouch, or IntelliCenter this is very trivial with a pi and about 10 lines of javascript. This is my pool dashboard panel.

No, I’m only using a Fibaro universal sensor with 5 temp probes and a on/off switch. Works really good.

Perhaps you can share those lines?
Should be able to pull something from the Fibaro sensor.

What’s your purpose? It’s not difficult to reach what you want, but if you need the page to auto update, this could be tricky.
The starting point is to write an handler like this:

luup.register_handler("lh_TempPage","TempPage")
 
function lh_TempPage (lul_request, lul_parameters, lul_outputformat)
	local value = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 167)
	local html = "<head>" ..
                     "<title>Temp</title>" ..
                     "<style>body{font-size:200px;text-align:center;}</style>" ..
                     "</head>" ..
                     "<body>" ..
                     "<b>Pool Temp: " ..
                     tostring(value) .. 'C</b>' ..
                     "</body></html>"
    
	return html, "text/html"
end

This can be requested here: http://VeraIP/port_3480/data_request?id=lr_TempPage

Change 167 in the code to your device and VeraIP to your IP.

If you want to auto update, look at the meta tag refresh. You can easily compose the layout, HTML is really the easy part here :slight_smile:

2 Likes

Cheers, did’nt figure to use Luup code in Vera.
It works fine with running as test in Vera, then browse to the IP.

gives me

(Sorry for the Swedish localization :))

I was aiming at using a local HTML-page calling for values on a local tablet, but this works fine too.
Should I make the code as startup?

Also, I’d need to input round(x,1) on the C and round(x,2) on kW.
Round can be added in custom variables in Reactor but not on physical devices added to Vera (so it needs to rounded off in this code). Does round() fit anywhere?
There is no need to display more than two decimals anywhere in Vera Secure’s sensors :laughing:

Yes, code must run at startup.

string.format("%.1f", tonumber(value))

should do the trick. use %1.f for 1 digit, %2.f for 2.

2 Likes

Works like a charm :slight_smile:

What would be best practice of adding a hh:mm-clock to the page?

try

os.date('%H:%M')
3 Likes

Many thanks, will check if I can have the webbrowser to reload every fifth minute :slight_smile:

<meta http-equiv="refresh" content="5">

Will do the trick, where 5 is in seconds.

2 Likes

Doesn’t seem to work, it just return “Failed to test code…”
bild

Post your code, not a screenshot.

At first glance.

You will need to escape your quotes around \"refresh\" and \"30\".

3 Likes

Would suggest that you consider using the extended string quote syntax so that you can use quotes and multiple lines:

local html = [[
<head>
<title>Pool Page</title>
<meta http-equiv="refresh" content="30">

... etc...

]]
2 Likes

Yup, didn’t see that :slight_smile:
That works, thanks!