# How to test is msg.payload is a number or not?

**URL:** <https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741>\
**Category:** General\
**Tags:** function-node\
**Created:** [16 November 2022 21:31 UTC](https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741 "2022-11-16T21:31:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [16 November 2022 21:31 UTC](https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741/1 "2022-11-16T21:31:40Z")

</div>

I have a flow that reads a temperature sensor in Home Assistant and puts the numeric value in a flow variable. Works fine. However, if something happens to the sensor, the reading becomes "unavailable".

How can I detect that? Basically, if msg.payload is "unavailable", I want to stop the flow.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 November 2022 21:56 UTC](https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741/2 "2022-11-16T21:56:46Z")

</div>

You can use a Switch node to only pass messages of type Number

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c94bf1f34d9380fab1d4408f4797496570e6deb.png)

If, however, even when it contains a number it is actually a string containing a number then you could configure the node to send messages with payload containing unavailable to one output and otherwise to the second output, and only use the messages on second output.

---

<div class="post-metadata">

**Author:** ![SteveMann](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stevemann/32/3810_2.png) [@SteveMann](https://discourse.nodered.org/u/SteveMann)\
**Post date:** [17 November 2022 05:14 UTC](https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741/3 "2022-11-17T05:14:48Z")

</div>

Thanks. That fixed it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 December 2022 05:15 UTC](https://discourse.nodered.org/t/how-to-test-is-msg-payload-is-a-number-or-not/70741/4 "2022-12-01T05:15:25Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
