Node-Red action on toggle of door sensor

Hello, I’m newbie and have started to learn about Node-RED.
I would like to ask you for advice.
In my scenario are used door sensors. Problem is, not all time is same conditions. Door can be opened or closed. In this case scenario needs to start from different sensor states. How to start scenario after switch state toggles? I found some kind of solution, but it’s not best solution.
Thanks you for your advises.

That image doesn’t say much.
But why do you have an inject as the start?
Why not events state and set the “if state” as on or off.
It has two outputs, one for when if state is true and one for when it’s false.
So one for door open and one for door closed.

Hi, let’s I will try to explain.

First block is for time. @6:00 it turns light in bath room, then I can have some light in my room, to do not wake up my wife turning on light in our bad room.

Then 6 blocks to check state of bath door sensor state and as result to dimm brightens from 100% to 40%(then light do not blind me from morning) when door is toggled.

Then it turns on Light in Living room as well,

Then 6 blocks again looking for door state change and turns it off.

At the end, it’s turns of light in living room when I left house.

Probably I think there is some more better solution to replace 6 blocks for light dimming/turning off with 2 blocks.
1 looks if door sensor are toggled, then change state of light.

Thanks you.

Hi, found how to get code out.

[
    {
        "id": "a2b166a975cf364d",
        "type": "inject",
        "z": "7e113732a5adef9b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "00 06 * * 1,2,3,4,5",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 110,
        "y": 460,
        "wires": [
            [
                "f026abc420ff424b"
            ]
        ]
    },
    {
        "id": "f026abc420ff424b",
        "type": "api-call-service",
        "z": "7e113732a5adef9b",
        "name": "Bath on",
        "server": "319813c2.b572dc",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.bath_light",
        "data": "{\"entity_id\": \"light.bath_light\", \"brightness_pct\": 100 }",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 280,
        "y": 460,
        "wires": [
            [
                "6a775095c06cb8e9",
                "9006f8a6f5af0d0a"
            ]
        ]
    },
    {
        "id": "6a775095c06cb8e9",
        "type": "api-current-state",
        "z": "7e113732a5adef9b",
        "name": "Door O",
        "server": "319813c2.b572dc",
        "version": 2,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "binary_sensor.bath_door_contact",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 300,
        "y": 380,
        "wires": [
            [
                "df6eed156a35e1c8"
            ],
            []
        ]
    },
    {
        "id": "df6eed156a35e1c8",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.bath_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "off",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 460,
        "y": 380,
        "wires": [
            [
                "41cafa8baf34b578"
            ]
        ]
    },
    {
        "id": "9006f8a6f5af0d0a",
        "type": "api-current-state",
        "z": "7e113732a5adef9b",
        "name": "Door С",
        "server": "319813c2.b572dc",
        "version": 2,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "binary_sensor.bath_door_contact",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 300,
        "y": 540,
        "wires": [
            [
                "b0842db02093aa90"
            ],
            []
        ]
    },
    {
        "id": "b0842db02093aa90",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.bath_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "on",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 460,
        "y": 540,
        "wires": [
            [
                "41cafa8baf34b578"
            ]
        ]
    },
    {
        "id": "41cafa8baf34b578",
        "type": "api-call-service",
        "z": "7e113732a5adef9b",
        "name": "Bath on",
        "server": "319813c2.b572dc",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.bath_light",
        "data": "{\"entity_id\": \"light.bath_light\", \"brightness_pct\": 30 }",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 480,
        "y": 460,
        "wires": [
            [
                "cbd52677320c1af2"
            ]
        ]
    },
    {
        "id": "cbd52677320c1af2",
        "type": "api-call-service",
        "z": "7e113732a5adef9b",
        "name": "Living Room",
        "server": "319813c2.b572dc",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.curtain_rgb_cct, light.shelf_rgb_cct, light.zal_svet_na_kukhniu",
        "data": "{\t   \"brightness_pct\": 100 \t}",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 630,
        "y": 460,
        "wires": [
            [
                "30495567590d972a"
            ]
        ]
    },
    {
        "id": "8815366f2202236e",
        "type": "delay",
        "z": "7e113732a5adef9b",
        "name": "",
        "pauseType": "delay",
        "timeout": "2",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "x": 1450,
        "y": 460,
        "wires": [
            [
                "836b49e3eed6fb57"
            ]
        ]
    },
    {
        "id": "836b49e3eed6fb57",
        "type": "api-call-service",
        "z": "7e113732a5adef9b",
        "name": "Living Room",
        "server": "319813c2.b572dc",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.curtain_rgb_cct, light.shelf_rgb_cct, light.zal_svet_na_kukhniu",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1610,
        "y": 460,
        "wires": [
            []
        ]
    },
    {
        "id": "d28f60df538f3660",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.bath_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "off",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 1010,
        "y": 460,
        "wires": [
            [
                "c47a06c110ee221e"
            ]
        ]
    },
    {
        "id": "c47a06c110ee221e",
        "type": "api-call-service",
        "z": "7e113732a5adef9b",
        "name": "Bath off",
        "server": "319813c2.b572dc",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.bath_light",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1150,
        "y": 460,
        "wires": [
            [
                "c43943da9c8dc20d"
            ]
        ]
    },
    {
        "id": "c43943da9c8dc20d",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.entrance_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "on",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 1290,
        "y": 460,
        "wires": [
            [
                "8815366f2202236e"
            ]
        ]
    },
    {
        "id": "30495567590d972a",
        "type": "delay",
        "z": "7e113732a5adef9b",
        "name": "",
        "pauseType": "delay",
        "timeout": "8",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "x": 790,
        "y": 460,
        "wires": [
            [
                "62b29f465d7cf811",
                "487aad4f1647ed64"
            ]
        ]
    },
    {
        "id": "487aad4f1647ed64",
        "type": "api-current-state",
        "z": "7e113732a5adef9b",
        "name": "Door O",
        "server": "319813c2.b572dc",
        "version": 2,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "binary_sensor.bath_door_contact",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 840,
        "y": 380,
        "wires": [
            [
                "91607b07147ae13e"
            ],
            []
        ]
    },
    {
        "id": "91607b07147ae13e",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.bath_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "off",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 980,
        "y": 380,
        "wires": [
            [
                "d28f60df538f3660"
            ]
        ]
    },
    {
        "id": "62b29f465d7cf811",
        "type": "api-current-state",
        "z": "7e113732a5adef9b",
        "name": "Door С",
        "server": "319813c2.b572dc",
        "version": 2,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "binary_sensor.bath_door_contact",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 840,
        "y": 540,
        "wires": [
            [
                "71b26154eebdbea3"
            ],
            []
        ]
    },
    {
        "id": "71b26154eebdbea3",
        "type": "ha-wait-until",
        "z": "7e113732a5adef9b",
        "name": "",
        "server": "319813c2.b572dc",
        "version": 0,
        "outputs": 1,
        "entityId": "binary_sensor.bath_door_contact",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "on",
        "valueType": "str",
        "timeout": 0,
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 980,
        "y": 540,
        "wires": [
            [
                "d28f60df538f3660"
            ]
        ]
    },
    {
        "id": "319813c2.b572dc",
        "type": "server",
        "name": "Home Assistant",
        "version": 1,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    }
]