Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Web Tag IsRaining in HTML

From Cumulus MX version 3 build 3044 the development baton passed to Mark Crossley. Mark has been responsible for all the Builds since, and has recently released Cumulus MX version 4. He has made the code available on GitHub. It is Mark's hope that others will join in this development, but at the very least he welcomes your ideas for future developments (see Cumulus MX Development suggestions).

Moderator: mcrossley

Post Reply
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Web Tag IsRaining in HTML

Post by Ken22 »

IsRaining returns either a 0 or 1.

Is it possible on my index.htm to convert this to either a "Yes" or "No"?

I know just enough about HTML to get myself in trouble.
freddie
Posts: 2870
Joined: Wed 08 Jun 2011 11:19 am
Weather Station: Davis Vantage Pro 2 + Ecowitt
Operating System: GNU/Linux Ubuntu 24.04 LXC
Location: Alcaston, Shropshire, UK
Contact:

Re: Web Tag IsRaining in HTML

Post by freddie »

You'll need some javascript.
Freddie
Image
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

freddie wrote: Sun 24 Nov 2024 8:19 pm You'll need some javascript.
I don't know how to do that.
User avatar
De Hout
Posts: 92
Joined: Thu 09 Oct 2014 5:40 pm
Weather Station: Davis Vantage Pro2+ FARS
Operating System: Windows 11 | CU v1.9.4 (10992)
Location: Alkmaar, The Netherlands
Contact:

Re: Web Tag IsRaining in HTML

Post by De Hout »

Something like this will do.

Replace the #IsRaining webtag in your index.htm with the code below.

Code: Select all

<div id="RainStatus"></div>
<script>
	let rain = '#IsRaining';

	if (rain === '0') {
		rain = 'No';
	} else {
		rain = 'Yes';
	}

	document.getElementById("RainStatus").innerText = rain;
</script>
Derk

Image
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

De Hout wrote: Mon 25 Nov 2024 7:23 pm Replace the #IsRaining webtag in your index.htm with the code below.
I seem to be missing something here. Here is what I have tried:

Code: Select all

<span data-cmxdata="IsRaining"></span>
ZZZ
<div id="RainStatus"></div>
<script>
	let rain = '#IsRaining';
	rain = '0';
	if (rain === '0') {
		rain = 'No';
	} else if (rain === '1') {
		rain = 'Yes';
	} else {
		rain = 'Error'
	}
	document.getElementById("RainStatus").innerText = rain;
</script>

*** This produces:
0 ZZZ
No

---------------------------------
<span data-cmxdata="IsRaining"></span>
ZZZ
<div id="RainStatus"></div>
<script>
	let rain = '#IsRaining';
	if (rain === '0') {
		rain = 'No';
	} else if (rain === '1') {
		rain = 'Yes';
	} else {
		rain = 'Error'
	}
	document.getElementById("RainStatus").innerText = rain;
</script>

***  This produces:
0 ZZZ
Error

-----------------------------------------------
<span data-cmxdata="IsRaining"></span>
ZZZ
<div id="RainStatus"></div>
<script>
	let rain = <span data-cmxdata="IsRaining"></span>;
	if (rain === '0') {
		rain = 'No';
	} else if (rain === '1') {
		rain = 'Yes';
	} else {
		rain = 'Error'
	}
	document.getElementById("RainStatus").innerText = rain;
</script>

***  This produces:
0 ZZZ
---------------------------------------------
<span data-cmxdata="IsRaining"></span>
ZZZ
<div id="RainStatus"></div>
<script>
	let rain = data-cmxdata="IsRaining";
	if (rain === '0') {
		rain = 'No';
	} else if (rain === '1') {
		rain = 'Yes';
	} else {
		rain = 'Error'
	}
	document.getElementById("RainStatus").innerText = rain;
</script>

***  This produces:
0 ZZZ
There must be something I'm missing here. To access WebTags in my HTML file I need to use the data-cmxdata="WebTag" construct. The #WebTag doesn't seem to work on my system.

Any clarification would be appreciated.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Web Tag IsRaining in HTML

Post by mcrossley »

You cannot use #IsRaining in a JavaScript, the old way of doing it would be to use the web tag <#IsRaining>.

The new web site loads all the data into an object called "cmx_data".

To access IsRaining you would use

Code: Select all

let rain = cmx_data.IsRaining;
Or just use cmx_data.IsRaining rather than assigning it to the variable "rain" then using that.
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

mcrossley wrote: Fri 29 Nov 2024 4:27 pm The new web site loads all the data into an object called "cmx_data".
To access IsRaining you would use

Code: Select all

let rain = cmx_data.IsRaining;
Still not working:

Code: Select all

<span data-cmxdata="IsRaining"></span>
ZZZ
<div id="RainStatus"></div>
<script>
	let rain = cmx_data.IsRaining;
	if (rain === '0') {
		rain = 'No';
	} else if (rain === '1') {
		rain = 'Yes';
	} else {
		rain = 'Error'
	}
	document.getElementById("RainStatus").innerText = rain;
</script>
XXX
Produces the following output:

0 ZZZ
XXX
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Web Tag IsRaining in HTML

Post by mcrossley »

We need to see a link to the test page please.
User avatar
De Hout
Posts: 92
Joined: Thu 09 Oct 2014 5:40 pm
Weather Station: Davis Vantage Pro2+ FARS
Operating System: Windows 11 | CU v1.9.4 (10992)
Location: Alkmaar, The Netherlands
Contact:

Re: Web Tag IsRaining in HTML

Post by De Hout »

My initial code contains an error. The webtag should be <#IsRaining>

Code: Select all

<div id="RainStatus"></div>
<script>
	rain = '<#IsRaining>';

	if (rain === '0') {
		rain = 'No';
	} else {
		rain = 'Yes';
	}

	document.getElementById("RainStatus").innerText = rain;
</script>
This script works on my webserver, although I have tested it with <#IsSunUp> instead of <#IsRaining> which is not a valid webtag for Cumulus 1.
Or do webtags work differently with CMX?
Derk

Image
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Web Tag IsRaining in HTML

Post by mcrossley »

De Hout wrote: Fri 29 Nov 2024 6:34 pm Or do webtags work differently with CMX?
The web tags work the same, but the pages are constructed differently - they are no longer all processed and uploaded like C1.
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

mcrossley wrote: Fri 29 Nov 2024 5:47 pm We need to see a link to the test page please.
https://www.klevitt.us/Cumulus/
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

Starting at line 113.
User avatar
mcrossley
Posts: 14384
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Web Tag IsRaining in HTML

Post by mcrossley »

Ah, your script will execute immediately.

You need the script to wait until the cmx_data object has been populated with the data.

The data load is encapsulated in a promise, so something like this (untested) should work

Code: Select all

$(document).ready(function() {
	dataLoadedPromise.then(function() {
		let rain = cmx_data.IsRaining === '0' ? 'No' : 'Yes' ;
		document.getElementById("RainStatus").innerText = rain;
	});
});
Ken22
Posts: 97
Joined: Tue 14 Jan 2014 3:08 pm
Weather Station: Ecowitt WS90/HP2560,GW1200,WN32
Operating System: Windows 10 Pro
Location: Massachusetts, USA
Contact:

Re: Web Tag IsRaining in HTML

Post by Ken22 »

mcrossley wrote: Sat 30 Nov 2024 10:20 am so something like this (untested) should work
Yes, it works perfectly.

Your help is greatly appreciated.

My page is now perfect until I think of some new way to make it better.
Post Reply