Need help with a state change in Node Red

So I am new to Node Red and am trying to setup a flow where my lights in the living room change based on if my phone is on the network. I have not been able to get this to fire successfully and am not sure where I am going wrong.

can you paste the flow, or show us the settings inside your state node?
Basically, use developer tools / states in Home Assistant to make a note of the states (case sensitive!) and make sure they are reflected in the output nodes correctly. So the sensor mode should be a bit like this:

Highlight the nodes in the flow then Export it to a text file that you can post here.

What part isn’t working?
Looking again at your flow- it won’t “fire” until there is a state change. Put a few debug nodes in your flow, then turn your phone off then on to force a change. I would be interested in seeing both outputs of the state node.

It looks like it did fire once, but maybe the switch node isnt set correctly? as @stevemann said, add a debug node or two to see whats going on

Thanks for this, I didn’t know you could do this. Does this help?

{

        "id": "19b31a122cbe9ce0",

        "type": "tab",

        "label": "Turn off lights when leaving",

        "disabled": false,

        "info": "",

        "env": []

    },

    {

        "id": "76651ef9986ec75a",

        "type": "api-call-service",

        "z": "19b31a122cbe9ce0",

        "name": "",

        "server": "58789d9e.7d1274",

        "version": 5,

        "debugenabled": false,

        "domain": "light",

        "service": "turn_on",

        "areaId": [

            "living_room"

        ],

        "deviceId": [

            "4623a128d632836e2aab5a950fc32a80"

        ],

        "entityId": [

            "light.living_room"

        ],

        "data": "",

        "dataType": "jsonata",

        "mergeContext": "",

        "mustacheAltTags": false,

        "outputProperties": [],

        "queue": "none",

        "x": 790,

        "y": 420,

        "wires": [

            []

        ]

    },

    {

        "id": "4260e58afe36c90d",

        "type": "api-call-service",

        "z": "19b31a122cbe9ce0",

        "name": "",

        "server": "58789d9e.7d1274",

        "version": 5,

        "debugenabled": false,

        "domain": "light",

        "service": "turn_off",

        "areaId": [

            "living_room"

        ],

        "deviceId": [

            "4623a128d632836e2aab5a950fc32a80"

        ],

        "entityId": [

            "light.living_room"

        ],

        "data": "",

        "dataType": "jsonata",

        "mergeContext": "",

        "mustacheAltTags": false,

        "outputProperties": [],

        "queue": "none",

        "x": 1010,

        "y": 560,

        "wires": [

            []

        ]

    },

    {

        "id": "60e60026ea707dea",

        "type": "time-range-switch",

        "z": "19b31a122cbe9ce0",

        "name": "",

        "lat": "",

        "lon": "",

        "startTime": "08:00",

        "endTime": "17:00",

        "startOffset": 0,

        "endOffset": 0,

        "x": 810,

        "y": 600,

        "wires": [

            [

                "4260e58afe36c90d"

            ],

            [

                "5e2e77ea5df13fbd"

            ]

        ]

    },

    {

        "id": "5e2e77ea5df13fbd",

        "type": "api-call-service",

        "z": "19b31a122cbe9ce0",

        "name": "",

        "server": "58789d9e.7d1274",

        "version": 5,

        "debugenabled": false,

        "domain": "light",

        "service": "turn_on",

        "areaId": [

            "living_room"

        ],

        "deviceId": [

            "4623a128d632836e2aab5a950fc32a80"

        ],

        "entityId": [

            "scene.living_room_scene"

        ],

        "data": "",

        "dataType": "jsonata",

        "mergeContext": "",

        "mustacheAltTags": false,

        "outputProperties": [],

        "queue": "none",

        "x": 1010,

        "y": 620,

        "wires": [

            []

        ]

    },

    {

        "id": "40fd97542a41b1ad",

        "type": "server-state-changed",

        "z": "19b31a122cbe9ce0",

        "name": "",

        "server": "58789d9e.7d1274",

        "version": 5,

        "outputs": 2,

        "exposeAsEntityConfig": "",

        "entityId": "sensor.iphone_126_ssid",

        "entityIdType": "exact",

        "outputInitially": false,

        "stateType": "str",

        "ifState": "HomeBot",

        "ifStateType": "str",

        "ifStateOperator": "is",

        "outputOnlyOnStateChange": true,

        "for": "0",

        "forType": "num",

        "forUnits": "minutes",

        "ignorePrevStateNull": false,

        "ignorePrevStateUnknown": false,

        "ignorePrevStateUnavailable": false,

        "ignoreCurrentStateUnknown": false,

        "ignoreCurrentStateUnavailable": false,

        "outputProperties": [

            {

                "property": "payload",

                "propertyType": "msg",

                "value": "",

                "valueType": "entityState"

            },

            {

                "property": "data",

                "propertyType": "msg",

                "value": "",

                "valueType": "eventData"

            },

            {

                "property": "topic",

                "propertyType": "msg",

                "value": "",

                "valueType": "triggerId"

            }

        ],

        "x": 480,

        "y": 500,

        "wires": [

            [

                "76651ef9986ec75a"

            ],

            [

                "60e60026ea707dea"

            ]

        ]

    },

    {

        "id": "58789d9e.7d1274",

        "type": "server",

        "name": "Home Assistant",

        "addon": true

    }

]

Does this help?

Update: So the issue was that my HA companion app was not refreshing in the background due to it being in low power mode. Once I changed that it is now functioning as intended. Thank you for the responses.

1 Like