# On, Off, Faulty State for a Sensor

**URL:** <https://discourse.nodered.org/t/on-off-faulty-state-for-a-sensor/31951>\
**Category:** General\
**Created:** [24 August 2020 13:24 UTC](https://discourse.nodered.org/t/on-off-faulty-state-for-a-sensor/31951 "2020-08-24T13:24:12Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [24 August 2020 15:38 UTC](https://discourse.nodered.org/t/on-off-faulty-state-for-a-sensor/31951/8 "2020-08-24T15:38:23Z")

</div>

This should do it

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f6c6868e6ace949e686a42cc06e527873ed04be.png)

```auto
[{"id":"b1b9f109.13889","type":"ui_switch","z":"bdd7be38.d3b55","name":"","label":"START/STOP","tooltip":"","group":"af43d6a0.0b4b98","order":7,"width":5,"height":1,"passthru":true,"decouple":"false","topic":"pump_switch","style":"","onvalue":"true","onvalueType":"bool","onicon":"mi-power_settings_new ","oncolor":"yellow","offvalue":"false","offvalueType":"bool","officon":"mi-power_settings_new ","offcolor":"black","x":120,"y":3900,"wires":[["733d70ff.e55a78","510337a4.f9cd58"]]},{"id":"18c4c429.d71154","type":"ui_text","z":"bdd7be38.d3b55","group":"af43d6a0.0b4b98","order":4,"width":3,"height":1,"name":"","label":"Pump","format":"{{msg.payload}}","layout":"row-right","x":770,"y":3900,"wires":[]},{"id":"510337a4.f9cd58","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"ON","op2":"FAULTY","op1type":"str","op2type":"str","duration":"1","extend":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":320,"y":4020,"wires":[["7399d2cc.5bf624"]]},{"id":"7399d2cc.5bf624","type":"change","z":"bdd7be38.d3b55","name":"topic: pump","rules":[{"t":"set","p":"topic","pt":"msg","to":"pump","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":4020,"wires":[["733d70ff.e55a78"]]},{"id":"733d70ff.e55a78","type":"join","z":"bdd7be38.d3b55","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":3900,"wires":[["f2040d66.1f6b58"]]},{"id":"f2040d66.1f6b58","type":"function","z":"bdd7be38.d3b55","name":"","func":"if (msg.payload.pump_switch) {\n // pump should be on\n msg.payload = msg.payload.pump // this will be ON or FAULTY\n} else {\n msg.payload = \"OFF\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":3900,"wires":[["18c4c429.d71154"]]},{"id":"4092d2e6.a156ac","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"false","payloadType":"bool","x":90,"y":3860,"wires":[["b1b9f109.13889"]]},{"id":"582a4c4.bf3a834","type":"comment","z":"bdd7be38.d3b55","name":"Flow pulses go in here ->","info":"","x":120,"y":4020,"wires":[]},{"id":"af43d6a0.0b4b98","type":"ui_group","z":"","name":"logo","tab":"6f169b9f.b92d2c","order":3,"disp":false,"width":8,"collapse":false},{"id":"6f169b9f.b92d2c","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

Note that I have added a topic to the switch node so that the join will work.

---

_[View the full topic](https://discourse.nodered.org/t/on-off-faulty-state-for-a-sensor/31951)._
