The appearance of a switch node can reflect message payloads sent to it.
If the payload is boolean false, the switch appearance will change so it looks off, and the status shown in the dashboard will be "off".
if it's true, the switch will appear to be on.
- This is not the same as clicking on the switch because no message is sent on from the switch (Unless you tick the pass through box on the switch config).
- The same thing happens if you send a payload matching the switch output payload, in this case "ON" or "OFF"
[{"id":"17fc961cb50dfe80","type":"ui-switch","z":"4f13805766521cb5","name":"","label":"Switch 1","group":"a78c26d96284e55f","order":1,"width":"2","height":"1","passthru":false,"decouple":false,"topic":"switch1","topicType":"str","style":"","className":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","x":360,"y":320,"wires":[["ef70457f42b7719a"]]},{"id":"ef70457f42b7719a","type":"ui-text","z":"4f13805766521cb5","group":"a78c26d96284e55f","order":2,"width":"2","height":"1","name":"","label":"Last msg from 1","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":560,"y":320,"wires":[]},{"id":"f32c3f04d030864a","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"ON","order":1,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"ON","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":300,"wires":[["17fc961cb50dfe80"]]},{"id":"2cd03e69b3f143b6","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"OFF","order":2,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"OFF","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":340,"wires":[["17fc961cb50dfe80"]]},{"id":"e577b8e8c2c56ae1","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"true","order":3,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":380,"wires":[["17fc961cb50dfe80"]]},{"id":"bb1054a276b982b0","type":"ui-button","z":"4f13805766521cb5","group":"20d91987fba15c6a","name":"","label":"false","order":4,"width":"2","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"false","payloadType":"bool","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","x":150,"y":420,"wires":[["17fc961cb50dfe80"]]},{"id":"a78c26d96284e55f","type":"ui-group","name":"Group2","page":"a522d4a2f7307c8b","width":"4","height":"1","order":2,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"20d91987fba15c6a","type":"ui-group","name":"Buttons","page":"a522d4a2f7307c8b","width":"2","height":"1","order":1,"showTitle":true,"className":"red","visible":"true","disabled":"false"},{"id":"a522d4a2f7307c8b","type":"ui-page","name":"Demo","ui":"ac5e535515ebb9c6","path":"/demo","icon":"home","layout":"grid","theme":"f36403a3012e6880","order":1,"className":"","visible":"true","disabled":"false"},{"id":"ac5e535515ebb9c6","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"navigationStyle":"default"},{"id":"f36403a3012e6880","type":"ui-theme","name":"Default Theme","colors":{"surface":"#ffffff","primary":"#0094CE","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]
You can use this so that clicking one switch ON will turn another one OFF
- Be careful with this; if you have the pass through ticked you can make an infinite loop!
- If the switches trigger some additional processing, you may need extra code to interrupt it.
- Also take a look at the Button Group node which has this sort of processing built-in