Page 1 of 1

wbtag <#IsRaining>, where can I change the output value ?

Posted: Sun 09 Aug 2015 2:26 pm
by wetterfrosch1971
Hi,

webtag "<#IsRaining>"
is it possible to change the output value "1" into the word "it´s raining" and the output value "0" into the word "it´s dry" ?

when it is possible, where I can find the values ?

Thank you for help.
Frank

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 2:37 pm
by mcrossley
You could do it JavaScript in the client browser, or in PHP if you use that server side.

Code: Select all

<script>document.write(<#IsRaining>==0 ? "it's dry" : "it's raining");</script>
pecked out on my phone!

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 3:16 pm
by wetterfrosch1971
I want post on my Homepage:

"it´s raining" or "it´s dry"

or can I use the rain-rate webtag?

for post:

"no rain"
"little rain"
"strong rain"
"very stron rain"
etc...

I can not php or Java, becaus I´m only a user.

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 3:32 pm
by steve
Note that the <#IsRaining> web tag only works if you have an RG11 rain sensor (as mentioned in the wiki) and it is set to 'it's raining' mode (apologies if you knew this and do have an RG-11). Otherwise, you will need to use the rain rate, as you suggest. So, for a simple yes/no, you could use:

Code: Select all

<script>document.write(<#rrate>==0 ? "it's dry" : "it's raining");</script>
For a more complicated version with several outcomes, you would need to use an if/else if/... construct.

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 5:56 pm
by wetterfrosch1971

Code: Select all

<script>document.write(<#rrate>==0 ? "it's dry" : "it's raining");</script>
it don´t work, because if no rain, rrate are 0,0

I tried to change the script into

Code: Select all

<script>document.write(<#rrate>==0,0 ? "it's dry" : "it's raining");</script>
but it doesen´t work ;-(

what must I do?

Thank you for help.
Frank

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 6:06 pm
by steve
Ah, yes, good point. Javascript comparisons baffle me at times, and Javascript doesn't understand decimal commas. We really need Mark to give us the definitive answer, but this might work:

Code: Select all

<script>document.write('<#rrate>'==='0,0' ? "it's dry" : "it's raining");</script>

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 6:37 pm
by wetterfrosch1971
yes, it works.

thank you.

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 6:57 pm
by wetterfrosch1971
another question:

how must I write the script if I want only print "it´s raining" without "it´s dry"?

Thank you

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 6:59 pm
by mcrossley
steve wrote:Ah, yes, good point. Javascript comparisons baffle me at times, and Javascript doesn't understand decimal commas. We really need Mark to give us the definitive answer, but this might work:

Code: Select all

<script>document.write('<#rrate>'==='0,0' ? "it's dry" : "it's raining");</script>
Yes, that will be OK in this case.

If you want a more general solution that will work with either dot or comma decimals I would use...

Code: Select all

<script>document.write('<#rrate>'.replace(',','.')==='0.0' ? "it's dry" : "it's raining");</script>
or even more generally (in case the decimal is dropped, or more decimal places are added, or IsRaining produces an unexpected string )...

Code: Select all

<script>document.write(parseFloat('0<#rrate>'.replace(',','.'))===0 ? "it's dry" : "it's raining");</script>

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 7:03 pm
by mcrossley
wetterfrosch1971 wrote:another question:

how must I write the script if I want only print "it´s raining" without "it´s dry"?

Thank you
Try...

Code: Select all

if (parseFloat('0<#rrate>'.replace(',','.')) > 0) {document.write("it's raining");}

Re: wbtag <#IsRaining>, where can I change the output value

Posted: Sun 09 Aug 2015 8:05 pm
by wetterfrosch1971

Code: Select all

<script>document.write('<#rrate>'==='0,0' ? "it's dry" : "it's raining");</script>
a last question:

I will post a Image instead of the words "it´s raining" and "it´s dry"
the Images are on my webspace (for example http://www.webspaceXYZ.de/image-dry.jpg" and http://www.webspaceXYZ.de/image-rain.jpg").

how do I change the code?

many thanks for help

EDIT:
question has been done