Unexpected behavior of the event state node

Hello everyone,
I am trying to use an event state node to turn my AC after I have been away from home for 24h. I have been running some test with simple input boolean.
The behavior that I am after is:

  1. A switch is flipped when I leave home (off)
  2. Once I have been away for 24h (off for some delay)
  3. AC is turned off

I have done test with the delay set to 0 and I observe the expected behavior.
If I put in any sorts of delay though the “AC” never gets turned off.

[
    {
        "id": "0fd59973909db25d",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "cf2bc67d62f4f03b",
        "type": "server-state-changed",
        "z": "0fd59973909db25d",
        "name": "Home",
        "server": "27913f6aeb54c2be",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.test",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": 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": 270,
        "y": 140,
        "wires": [
            [
                "92822f545ba92080"
            ],
            []
        ]
    },
    {
        "id": "92822f545ba92080",
        "type": "api-current-state",
        "z": "0fd59973909db25d",
        "name": "Gone for 24h?",
        "server": "27913f6aeb54c2be",
        "version": 3,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "input_boolean.test",
        "state_type": "habool",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "for": "1",
        "forType": "num",
        "forUnits": "seconds",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 540,
        "y": 120,
        "wires": [
            [
                "86f4709d0fa85d4e"
            ],
            []
        ]
    },
    {
        "id": "86f4709d0fa85d4e",
        "type": "api-call-service",
        "z": "0fd59973909db25d",
        "name": "AC Off",
        "server": "27913f6aeb54c2be",
        "version": 5,
        "debugenabled": true,
        "domain": "input_boolean",
        "service": "turn_off",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "input_boolean.delay"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 790,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "27913f6aeb54c2be",
        "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
    }
]

Thank you
M.

You don’t need two nodes. The first node is firing when state changes to off, and the get-state node will immediately fail because the state just went off, not a minute (or a day) ago. The message doesn’t wait there for the period to elapse - it’s an immediate test. You could just put the time on the trigger node.

However, this won’t work if the state is off when you deploy, as in the case the state does not change from something to off. If you’re not deploying while you’re away from home, this might not be a problem for you though.

But still, to make it more robust I would use a timer helper and start the timer for 24h when you leave, and cancel the timer when you arrive. Then if and when the timer finishes, turn the AC off. You can configure the timer to survive HA restarts. This also has the benefit that you can see if the timer is running, and when it will finish.

1 Like

That is exactly the answer I was looking for.
Because I do most of my automation through NodeRED I did not even think of using a timer helper.
Thank you very much