Nodered Simple conditional with aqara and 2 kasa switches

Hi there,

I wanted to switch all my HA automation to nodered but im having trouble with a conditional. I have 2 lights. one of them turns on automatically in the morning (roomplug). I want the other light (desklight) to turn on only if the first light is on.

Using the setup i made, once the condition is made on the button press, it just keeps triggering the light to toggle even if the conditions are false.

Is there some sort of timing issue that i’m missing. ?

[
    {
        "id": "c2b1904b3b1b9d6d",
        "type": "api-call-service",
        "z": "acc47017a1dba1ec",
        "name": "DeskLightToggle",
        "server": "0b271414fe13557f",
        "version": 5,
        "debugenabled": false,
        "domain": "switch",
        "service": "toggle",
        "areaId": [],
        "deviceId": [
            "5facf789a17433046fc25378a163a9c5"
        ],
        "entityId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1290,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "0f9fd7ce21a51f44",
        "type": "api-current-state",
        "z": "acc47017a1dba1ec",
        "name": "",
        "server": "0b271414fe13557f",
        "version": 3,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "switch.roomplug",
        "state_type": "str",
        "blockInputOverrides": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "roomplugon",
                "valueType": "str"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "roomplug",
                "valueType": "str"
            }
        ],
        "for": "0.1",
        "forType": "num",
        "forUnits": "seconds",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 750,
        "y": 560,
        "wires": [
            [
                "154d0293b64e4e11"
            ],
            []
        ]
    },
    {
        "id": "6c03a624ec7755d3",
        "type": "api-current-state",
        "z": "acc47017a1dba1ec",
        "name": "",
        "server": "0b271414fe13557f",
        "version": 3,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "switch.bedroom_desk_light",
        "state_type": "str",
        "blockInputOverrides": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "desklightoff",
                "valueType": "str"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "desklight",
                "valueType": "str"
            }
        ],
        "for": "0.1",
        "forType": "num",
        "forUnits": "seconds",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 780,
        "y": 660,
        "wires": [
            [
                "154d0293b64e4e11"
            ],
            [
                "0ea1313fd2cc5e52"
            ]
        ]
    },
    {
        "id": "0ea1313fd2cc5e52",
        "type": "debug",
        "z": "acc47017a1dba1ec",
        "name": "false",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1070,
        "y": 740,
        "wires": []
    },
    {
        "id": "1133269ec86c5a7d",
        "type": "debug",
        "z": "acc47017a1dba1ec",
        "name": "debugtrigger",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 690,
        "y": 740,
        "wires": []
    },
    {
        "id": "154d0293b64e4e11",
        "type": "and-gate",
        "z": "acc47017a1dba1ec",
        "name": "",
        "rules": [
            {
                "t": "eq",
                "v": "roomplugon",
                "vt": "str",
                "propertyType": "msg",
                "property": "payload",
                "topic": "roomplug"
            },
            {
                "t": "eq",
                "v": "desklightoff",
                "vt": "str",
                "propertyType": "msg",
                "property": "payload",
                "topic": "desklight"
            }
        ],
        "outputTopic": "andcheck1",
        "gateType": "and",
        "emitOnlyIfTrue": true,
        "x": 1080,
        "y": 580,
        "wires": [
            [
                "c2b1904b3b1b9d6d",
                "96cf9c319c0ae242"
            ]
        ]
    },
    {
        "id": "96cf9c319c0ae242",
        "type": "debug",
        "z": "acc47017a1dba1ec",
        "name": "debug 3",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1260,
        "y": 640,
        "wires": []
    },
    {
        "id": "7835beb9628d7b65",
        "type": "ha-device",
        "z": "acc47017a1dba1ec",
        "name": "",
        "server": "0b271414fe13557f",
        "version": 1,
        "exposeAsEntityConfig": "",
        "inputs": 0,
        "deviceType": "trigger",
        "device": "0895dc5ee3910896ba0d25f9662f6e4b",
        "event": {
            "device_id": "0895dc5ee3910896ba0d25f9662f6e4b",
            "domain": "zha",
            "platform": "device",
            "type": "remote_button_long_press",
            "subtype": "remote_button_long_press",
            "metadata": {}
        },
        "capabilities": [],
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 370,
        "y": 620,
        "wires": [
            [
                "0f9fd7ce21a51f44",
                "6c03a624ec7755d3",
                "1133269ec86c5a7d"
            ]
        ]
    },
    {
        "id": "0b271414fe13557f",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": false
    }
]

Sorry I see it’s a physical button. Current state is your conditional node. It will only pass through the top out put if the condition is met.

So it’s a little more complicated that wont let the light shut off if the other is off. You need one to toggle if the light is on. The other to shut off only if the other switch is off.

[{"id":"30d5c45e03d2638f","type":"ha-device","z":"60f2d2277843c698","name":"","server":"","version":1,"exposeAsEntityConfig":"","inputs":0,"deviceType":"trigger","device":"","capabilities":[],"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":570,"y":240,"wires":[["cf989105fd31be28"]]},{"id":"cf989105fd31be28","type":"api-current-state","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light that must be on","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":840,"y":240,"wires":[["b73fdf38e78e6a58"],["40a186dc83bd95c2"]]},{"id":"b73fdf38e78e6a58","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"switch","service":"toggle","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1170,"y":200,"wires":[[]]},{"id":"40a186dc83bd95c2","type":"api-call-service","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1180,"y":280,"wires":[[]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

That worked ! thanks so much!