Synchronizing dashboard switch

Hi all, I have been struggling for a while now with the dashboard switch node.
Several forum topics seem to address similar issues, but I couldn't find a solution to my problem.
I have a continuously adjustable duct fan in my office. I use this fan to keep the CO2 concentration below certain levels, using a CO2 sensor and a PID control loop.
I also want this fan to start on its minimum rpm setting if I switch the lights on in this room, and be able to switch it using the NR dashboard. For this I added a Shelly i3 control linked to the light switch which communicates through MQTT, and a switch node on my dashboard.
Everything works, except for one small but very annoying detail:
The switch node only shows the true status if I start or stop the fan using this node.

I tried several settings for 'Pass through' and 'Indicator', But I can't get it to work.
If I set it to 'Switch icon shows state of the output', the flow even switches the fan back on if it has been switched off by other means! I can't wrap my head around this one.

The switch node has both an active and a passive role, so I think I should check the 'Pass through' checkbox, but that also doesn't seem to work. I'm aware of potential loopback issues; added a few RBE filters for this purpose, but still no result.

Set the dashboard switch to show the state of the input, so it always shows the real world. Set it to not pass through. Then when you click the dashboard switch it sends the command off, and when the hardware changes state the switch display will follow it.

Thank you! I had same question as the OP but never asked it. My solution was MUCH more complicated.

Sorry, I already tried this, doesn't seem to work for me.
I made a little test program to get to the essence of the problem:

These switches represent the possible settings.
All variants show some behaviour I cannot explain.
The 'input' variant can't be manipulated from the switch node on the dashboard.
The 'output' variant doesn't update the LED if the switch action is external.
'Passthrough' only works on the dashboard on which a change is made. If there is a second device showing the same dashboard it shows different LED colours.

This should be easy, but unfortunately I don't see it.

[
    {
        "id": "08c1fdc1e1aa5be4",
        "type": "ui_switch",
        "z": "87dcd56d38ba0dca",
        "name": "",
        "label": "input",
        "tooltip": "",
        "group": "9a4bcb15796d2b4c",
        "order": 1,
        "width": 4,
        "height": 1,
        "passthru": false,
        "decouple": "true",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 410,
        "y": 620,
        "wires": [
            [
                "d83c03c946dfd7d7"
            ]
        ]
    },
    {
        "id": "d83c03c946dfd7d7",
        "type": "ui_led",
        "z": "87dcd56d38ba0dca",
        "order": 2,
        "group": "9a4bcb15796d2b4c",
        "width": 2,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "bool"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "input",
        "x": 650,
        "y": 620,
        "wires": []
    },
    {
        "id": "90e39737d0b50bd9",
        "type": "ui_switch",
        "z": "87dcd56d38ba0dca",
        "name": "",
        "label": "output",
        "tooltip": "",
        "group": "9a4bcb15796d2b4c",
        "order": 4,
        "width": 4,
        "height": 1,
        "passthru": false,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 410,
        "y": 700,
        "wires": [
            [
                "01bdf37897897aa2"
            ]
        ]
    },
    {
        "id": "01bdf37897897aa2",
        "type": "ui_led",
        "z": "87dcd56d38ba0dca",
        "order": 5,
        "group": "9a4bcb15796d2b4c",
        "width": 2,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "bool"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "output",
        "x": 650,
        "y": 700,
        "wires": []
    },
    {
        "id": "0476a8bb25421be2",
        "type": "ui_switch",
        "z": "87dcd56d38ba0dca",
        "name": "",
        "label": "passthrough",
        "tooltip": "",
        "group": "9a4bcb15796d2b4c",
        "order": 7,
        "width": 4,
        "height": 1,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "true",
        "onvalueType": "bool",
        "onicon": "",
        "oncolor": "",
        "offvalue": "false",
        "offvalueType": "bool",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 430,
        "y": 780,
        "wires": [
            [
                "27cae1cf631293f5"
            ]
        ]
    },
    {
        "id": "27cae1cf631293f5",
        "type": "ui_led",
        "z": "87dcd56d38ba0dca",
        "order": 8,
        "group": "9a4bcb15796d2b4c",
        "width": 2,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "bool"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "passthrough",
        "x": 670,
        "y": 780,
        "wires": []
    },
    {
        "id": "51a75753ef990ea8",
        "type": "ui_button",
        "z": "87dcd56d38ba0dca",
        "name": "",
        "group": "9a4bcb15796d2b4c",
        "order": 10,
        "width": 4,
        "height": 1,
        "passthru": false,
        "label": "External 'on'",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "true",
        "payloadType": "bool",
        "topic": "topic",
        "topicType": "msg",
        "x": 190,
        "y": 620,
        "wires": [
            [
                "08c1fdc1e1aa5be4",
                "90e39737d0b50bd9",
                "0476a8bb25421be2"
            ]
        ]
    },
    {
        "id": "7ef97b68fb53b90f",
        "type": "ui_button",
        "z": "87dcd56d38ba0dca",
        "name": "",
        "group": "9a4bcb15796d2b4c",
        "order": 11,
        "width": 4,
        "height": 1,
        "passthru": false,
        "label": "external 'off'",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "false",
        "payloadType": "bool",
        "topic": "topic",
        "topicType": "msg",
        "x": 190,
        "y": 700,
        "wires": [
            [
                "08c1fdc1e1aa5be4",
                "90e39737d0b50bd9",
                "0476a8bb25421be2"
            ]
        ]
    },
    {
        "id": "9a4bcb15796d2b4c",
        "type": "ui_group",
        "name": "Default",
        "tab": "8cf419bfa3bb0c6c",
        "order": 1,
        "disp": true,
        "width": 8,
        "collapse": false,
        "className": ""
    },
    {
        "id": "8cf419bfa3bb0c6c",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

You want to pass msg if payload matches valid state
Here is an example of setting a ui-switch. one switch is set on/off with short and long press. The other example switch is set on/off with just a short press toggle.
e.g.

[{"id":"5f7026fc9858803a","type":"group","z":"65617ffeb779f51c","name":"simulate short and long press on i3 channel 0","style":{"label":true,"color":"#000000"},"nodes":["1122b2f9fb54dbc2","5058ff5e2e6e7ffc","fd1bb44399d97fc3","e6dc0c1d6b81bad2","c3f7d4242c4d0405","c6da279ffb9f23e3"],"x":294,"y":2519,"w":892,"h":122},{"id":"1122b2f9fb54dbc2","type":"mqtt out","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"","topic":"shellies/shellyix3-123/input_event/0","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"e8ba3ef5.22f4a8","x":1010,"y":2600,"wires":[]},{"id":"5058ff5e2e6e7ffc","type":"inject","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"shortpush","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":2560,"wires":[["fd1bb44399d97fc3"]]},{"id":"fd1bb44399d97fc3","type":"ui_button","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"","group":"99a91e75281341f5","order":6,"width":0,"height":0,"passthru":true,"label":"shortpush","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"Shortpush","payloadType":"str","topic":"topic","topicType":"msg","x":540,"y":2560,"wires":[["e6dc0c1d6b81bad2"]]},{"id":"e6dc0c1d6b81bad2","type":"change","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"","rules":[{"t":"set","p":"event_cnt","pt":"flow","to":"$sum([$flowContext(\"event_cnt\")]) + 1","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"{\"event\":$$.payload,\"event_cnt\": $flowContext(\"event_cnt\")}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":2560,"wires":[["1122b2f9fb54dbc2"]]},{"id":"c3f7d4242c4d0405","type":"inject","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"longpush","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":2600,"wires":[["c6da279ffb9f23e3"]]},{"id":"c6da279ffb9f23e3","type":"ui_button","z":"65617ffeb779f51c","g":"5f7026fc9858803a","name":"","group":"99a91e75281341f5","order":7,"width":0,"height":0,"passthru":true,"label":"Longpush","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"Longpush","payloadType":"str","topic":"topic","topicType":"msg","x":540,"y":2600,"wires":[["e6dc0c1d6b81bad2"]]},{"id":"e8ba3ef5.22f4a8","type":"mqtt-broker","name":"testb","broker":"192.168.1.25","port":"1883","clientid":"node-red-test","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"99a91e75281341f5","type":"ui_group","name":"Default","tab":"8cf419bfa3bb0c6c","order":1,"disp":true,"width":8,"collapse":false,"className":""},{"id":"8cf419bfa3bb0c6c","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"6cb591661703fea6","type":"group","z":"65617ffeb779f51c","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["2024a3ba142464b0","c2791862dcd04abc","03b13b16fd280246","4ecfb6cf8347717e","a51318ea5486bc01","43ef3c3a32a0b448","9b57d3b28506f8c1","a04b853dc47232ad","8cea4afcb192a274","28096b2abd1a5945","0772f169b5ccba23","65e1167954596393","c048ed6637afb65f","9511c562dd45545e"],"x":334,"y":2679,"w":772,"h":242},{"id":"2024a3ba142464b0","type":"ui_led","z":"65617ffeb779f51c","g":"6cb591661703fea6","order":3,"group":"99a91e75281341f5","width":2,"height":1,"label":"short long","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"short long","x":980,"y":2780,"wires":[]},{"id":"c2791862dcd04abc","type":"ui_switch","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","label":"short long","tooltip":"","group":"99a91e75281341f5","order":5,"width":4,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":820,"y":2780,"wires":[["2024a3ba142464b0"]]},{"id":"03b13b16fd280246","type":"mqtt in","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","topic":"shellies/shellyix3-123/input_event/0","qos":"2","datatype":"auto-detect","broker":"e8ba3ef5.22f4a8","nl":false,"rap":true,"rh":0,"inputs":0,"x":500,"y":2720,"wires":[["43ef3c3a32a0b448"]]},{"id":"4ecfb6cf8347717e","type":"switch","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"Shortpush","vt":"str"},{"t":"eq","v":"Longpush","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":490,"y":2780,"wires":[["a51318ea5486bc01"],["9b57d3b28506f8c1"]]},{"id":"a51318ea5486bc01","type":"change","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":2780,"wires":[["c2791862dcd04abc"]]},{"id":"43ef3c3a32a0b448","type":"rbe","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload.event_cnt","topi":"topic","x":710,"y":2720,"wires":[["4ecfb6cf8347717e","a04b853dc47232ad"]]},{"id":"9b57d3b28506f8c1","type":"change","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":2820,"wires":[["c2791862dcd04abc"]]},{"id":"a04b853dc47232ad","type":"switch","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","property":"payload.event","propertyType":"msg","rules":[{"t":"eq","v":"Shortpush","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":2880,"wires":[["8cea4afcb192a274"]]},{"id":"8cea4afcb192a274","type":"change","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"short\") = true ? false : true","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2880,"wires":[["0772f169b5ccba23"]]},{"id":"28096b2abd1a5945","type":"change","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","rules":[{"t":"set","p":"short","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":2880,"wires":[["65e1167954596393"]]},{"id":"0772f169b5ccba23","type":"ui_switch","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"","label":"short","tooltip":"","group":"99a91e75281341f5","order":4,"width":4,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":710,"y":2880,"wires":[["28096b2abd1a5945"]]},{"id":"65e1167954596393","type":"ui_led","z":"65617ffeb779f51c","g":"6cb591661703fea6","order":1,"group":"99a91e75281341f5","width":2,"height":1,"label":"short","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"short","x":1030,"y":2880,"wires":[]},{"id":"c048ed6637afb65f","type":"comment","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"short on long off","info":"","x":920,"y":2740,"wires":[]},{"id":"9511c562dd45545e","type":"comment","z":"65617ffeb779f51c","g":"6cb591661703fea6","name":"short on short off","info":"","x":920,"y":2840,"wires":[]}]

The one labelled Input is working correctly. When you click it On it sends a true message. That will change the real world state, which has to be fed back into the dashboard switch, so to simulate that you have to click the External On button, and then the dashboard switch changes state. The reverse happens when you switch it off, you have to click the External Off button to simulate the real world state change. If there is a problem with the real world which prevents the action from happening then the dashboard switch will not change state, so you know that there is a problem.

For the external switch, don't feed the switch into the dashboard, but feed the actual state of the hardware. You can have as many ways of switching the hardware as you like, any one of them will change the switch on the dashboard.

Here is a better flow to demonstrate how it should work.

When the dashboard button is clicked the instruction is sent via MQTT to the Shelly, which switches the fan on. Since the dashboard switch is configured to show the state of the input, the switch does not immediately change state. However, the Shelly then publishes the new state via MQTT, which is picked up in node-red and passed to the dashboard switch so that it follow the state of the Shelly. If the Shelly is switched by any other means, by another MQTT client or via the button on the Shelly (if it has one) then again it will send the new state back to node red via MQTT and the dashboard switch will follow it.

[{"id":"4f8b5889f22667c1","type":"link out","z":"bdd7be38.d3b55","name":"link out 25","mode":"link","links":["cc28d13063a6dad7"],"x":785,"y":1840,"wires":[]},{"id":"cc28d13063a6dad7","type":"link in","z":"bdd7be38.d3b55","name":"link in 10","links":["4f8b5889f22667c1"],"x":85,"y":1640,"wires":[["f49c8bb30f20ec74"]]},{"id":"33752b3c3f85529b","type":"group","z":"bdd7be38.d3b55","name":"Node red","style":{"label":true,"label-position":"n","color":"#ff3f3f"},"nodes":["f49c8bb30f20ec74"],"x":134,"y":1599,"w":152,"h":82},{"id":"f49c8bb30f20ec74","type":"ui_switch","z":"bdd7be38.d3b55","g":"33752b3c3f85529b","name":"","label":"input","tooltip":"","group":"9a4bcb15796d2b4c","order":1,"width":4,"height":1,"passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":210,"y":1640,"wires":[["a1c6c27c855f3cf5"]]},{"id":"9a4bcb15796d2b4c","type":"ui_group","name":"Default","tab":"8cf419bfa3bb0c6c","order":1,"disp":true,"width":8,"collapse":false,"className":""},{"id":"8cf419bfa3bb0c6c","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"79cded26e21d207c","type":"group","z":"bdd7be38.d3b55","name":"The real world","style":{"label":true,"label-position":"n","color":"#ffdf7f"},"nodes":["b0c63ded88b97d0a","bd077e06e97c93db","4740b2c5bcaf611a","a1c6c27c855f3cf5"],"x":194,"y":1759,"w":552,"h":182},{"id":"b0c63ded88b97d0a","type":"ui_led","z":"bdd7be38.d3b55","g":"79cded26e21d207c","order":2,"group":"9a4bcb15796d2b4c","width":2,"height":1,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":670,"y":1800,"wires":[]},{"id":"bd077e06e97c93db","type":"ui_button","z":"bdd7be38.d3b55","g":"79cded26e21d207c","name":"","group":"9a4bcb15796d2b4c","order":10,"width":4,"height":1,"passthru":false,"label":"External 'on'","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":290,"y":1840,"wires":[["a1c6c27c855f3cf5"]]},{"id":"4740b2c5bcaf611a","type":"ui_button","z":"bdd7be38.d3b55","g":"79cded26e21d207c","name":"","group":"9a4bcb15796d2b4c","order":11,"width":4,"height":1,"passthru":false,"label":"external 'off'","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"false","payloadType":"bool","topic":"topic","topicType":"msg","x":290,"y":1900,"wires":[["a1c6c27c855f3cf5"]]},{"id":"a1c6c27c855f3cf5","type":"function","z":"bdd7be38.d3b55","g":"79cded26e21d207c","name":"Shelly","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":1820,"wires":[["b0c63ded88b97d0a","4f8b5889f22667c1"]]}]
1 Like

Thanks, that works better. My own code still doesn't work, but now I have something to compare it to. It shouldn't be too easy :thinking:

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