I am sure it´s an "boy, tt´s so damn easy" question but i can´t see it anyway. I am getting a msg.payload value of 41.1 but my function still returns false:
Sorry..... I am still not with the language structure.
I believe you can append commands/qualifiers to things and get stuff to happen that way.
So I thought msg.payload.value (particularly when value is bold) was one of these qualifiers and so made msg.payload into a value rather than a string.
works at least as expected. Is this still not the correct way of parsing it despite the fact that it´s working fine?
And one last thing to this: I am sending boolean true if watt > 20. How does the else statement needs to change to simply send nothing? I only want to send something if it´s really above 20 and not send anything at all if its below 20...
Since the payload is already a number, not a string, you don't need the `parseInt()'. In fact that may (but not sure) convert it to 41.0 since it tells it to make it an int.
else
{
msg = null;
}
returning null means don't send any message.
[Edit] I prefer setting msg to null rather than immediately returning null as in a more complex function it is easy to forget later on in the function that you have already returned.
sloppy type conversion may be a source of trouble in JS. ("23"<21+1) is false, but (23<"21"+"1") is true, as JS makes a string addition "21"+"1" = "211". Usually the use of Number() is the best solution to ensure numerical values regardless of the source.
I'm trying to do something very similar. Would you be able to explain why I'm still seeing a reference error:
Inbound payload:
Current function:
What I'm trying to do is trigger a true boolean in order to incorporate an IF statement looking at the illuminance levels. I plan to continue a flow if the light levels are below a certain level. Thanks in advance...