How to periodically check on entity state?

I have come up with this flow to close the garage cover if it has been open for more than 5 or more minutes but it only works when the state changes and not periodically. This means, for example, if the cover is open for 5 minutes or more. I get the iOS alert on my phone, and I press the “Close cover” actionable notification. Still, for some reason, maybe too much light due to the sun messing up with sensors, or something blocking the sensor, or something else, it did not close properly. I won’t know about it because my flow checks only on state change meaning it will trigger only if the cover went from close to open at some point. Can I get some ideas to add a periodic check so I don’t run into issues?

[
    {
        "id": "e13fb6b3d8f1d842",
        "type": "tab",
        "label": "GARAGE_DOOR_ALERT",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e76072dc.71e4f",
        "type": "server-state-changed",
        "z": "e13fb6b3d8f1d842",
        "name": "Is the garage door open?",
        "server": "e593dd3.052432",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.garage_door_myq_gateway",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "open",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": "5",
        "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": 210,
        "y": 140,
        "wires": [
            [
                "784a35516b416c37"
            ],
            []
        ],
        "outputLabels": [
            "\"on\"",
            ""
        ]
    },
    {
        "id": "d31e3a7251a42067",
        "type": "comment",
        "z": "e13fb6b3d8f1d842",
        "name": "Send a notification if the garage door is open for more than 5 minutes",
        "info": "",
        "x": 350,
        "y": 100,
        "wires": []
    },
    {
        "id": "2115fae878e3b2b8",
        "type": "link out",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "mode": "link",
        "links": [
            "b6171fec.b478f"
        ],
        "x": 655,
        "y": 140,
        "wires": []
    },
    {
        "id": "784a35516b416c37",
        "type": "change",
        "z": "e13fb6b3d8f1d842",
        "name": "Set notification attributes",
        "rules": [
            {
                "t": "set",
                "p": "title",
                "pt": "msg",
                "to": "Garage Door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message1",
                "pt": "msg",
                "to": "The garage door has been open for",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message2",
                "pt": "msg",
                "to": "15",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message3",
                "pt": "msg",
                "to": "minutes!",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "critical",
                "pt": "msg",
                "to": "0 or 1",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "sound",
                "pt": "msg",
                "to": "default",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "volume",
                "pt": "msg",
                "to": "1.0",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target",
                "pt": "msg",
                "to": "mobile_app_iphone",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "entity_id",
                "pt": "msg",
                "to": "cover.garage_door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "friendly_name",
                "pt": "msg",
                "to": "Garage Door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "event_action",
                "pt": "msg",
                "to": "CLOSE_GARAGE_DOOR",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "event_action_title",
                "pt": "msg",
                "to": "Close Garage Door",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 470,
        "y": 140,
        "wires": [
            [
                "2115fae878e3b2b8"
            ]
        ]
    },
    {
        "id": "7e7c1b4ffd992a68",
        "type": "server-events",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "eventType": "mobile_app_notification_action",
        "exposeToHomeAssistant": false,
        "eventData": "",
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "waitForRunning": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "event_type",
                "propertyType": "msg",
                "value": "$outputData(\"eventData\").event_type",
                "valueType": "str"
            }
        ],
        "event_type": "",
        "x": 250,
        "y": 280,
        "wires": [
            [
                "89444b2b7c65b773"
            ]
        ]
    },
    {
        "id": "61f18ed657b4d247",
        "type": "comment",
        "z": "e13fb6b3d8f1d842",
        "name": "Allow to close the door by pressing on the actionable iOS notification",
        "info": "",
        "x": 350,
        "y": 240,
        "wires": []
    },
    {
        "id": "89444b2b7c65b773",
        "type": "switch",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "property": "payload.event.action",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "CLOSE_GARAGE_DOOR",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 510,
        "y": 280,
        "wires": [
            [
                "789e8f8a7eb04b52"
            ]
        ]
    },
    {
        "id": "789e8f8a7eb04b52",
        "type": "api-call-service",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 5,
        "debugenabled": false,
        "domain": "cover",
        "service": "close_cover",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "cover.garage_door"
        ],
        "data": "",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 710,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "e593dd3.052432",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

For the notifications I am using this awesome work from some community members: Sharing IOS Notification Template with Example ** Improved **

You could use a wait-until node, after the change node, that is waiting for the garage door state to become closed. If it times out, loop it back to the link out node to send the notification again.

do you mean something like this:

[
    {
        "id": "e13fb6b3d8f1d842",
        "type": "tab",
        "label": "GARAGE_DOOR_ALERT",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "e76072dc.71e4f",
        "type": "server-state-changed",
        "z": "e13fb6b3d8f1d842",
        "name": "Is the garage door open?",
        "server": "e593dd3.052432",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.garage_door_myq_gateway",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "open",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": "5",
        "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": 190,
        "y": 140,
        "wires": [
            [
                "784a35516b416c37",
                "85325ef2801b8631"
            ],
            []
        ],
        "outputLabels": [
            "\"on\"",
            ""
        ]
    },
    {
        "id": "d31e3a7251a42067",
        "type": "comment",
        "z": "e13fb6b3d8f1d842",
        "name": "Send a notification if the garage door is open for more than 5 minutes",
        "info": "",
        "x": 390,
        "y": 80,
        "wires": []
    },
    {
        "id": "2115fae878e3b2b8",
        "type": "link out",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "mode": "link",
        "links": [
            "b6171fec.b478f"
        ],
        "x": 785,
        "y": 140,
        "wires": []
    },
    {
        "id": "784a35516b416c37",
        "type": "change",
        "z": "e13fb6b3d8f1d842",
        "name": "Set notification attributes",
        "rules": [
            {
                "t": "set",
                "p": "title",
                "pt": "msg",
                "to": "Garage Door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message1",
                "pt": "msg",
                "to": "The garage door has been open for",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message2",
                "pt": "msg",
                "to": "15",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "message3",
                "pt": "msg",
                "to": "minutes!",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "critical",
                "pt": "msg",
                "to": "0 or 1",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "sound",
                "pt": "msg",
                "to": "default",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "volume",
                "pt": "msg",
                "to": "1.0",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "target",
                "pt": "msg",
                "to": "mobile_app_iphone",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "entity_id",
                "pt": "msg",
                "to": "cover.garage_door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "friendly_name",
                "pt": "msg",
                "to": "Garage Door",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "event_action",
                "pt": "msg",
                "to": "CLOSE_GARAGE_DOOR",
                "tot": "str"
            },
            {
                "t": "set",
                "p": "event_action_title",
                "pt": "msg",
                "to": "Close Garage Door",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 610,
        "y": 140,
        "wires": [
            [
                "2115fae878e3b2b8"
            ]
        ]
    },
    {
        "id": "7e7c1b4ffd992a68",
        "type": "server-events",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "eventType": "mobile_app_notification_action",
        "exposeToHomeAssistant": false,
        "eventData": "",
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "waitForRunning": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "event_type",
                "propertyType": "msg",
                "value": "$outputData(\"eventData\").event_type",
                "valueType": "str"
            }
        ],
        "event_type": "",
        "x": 250,
        "y": 280,
        "wires": [
            [
                "89444b2b7c65b773"
            ]
        ]
    },
    {
        "id": "61f18ed657b4d247",
        "type": "comment",
        "z": "e13fb6b3d8f1d842",
        "name": "Allow to close the door by pressing on the actionable iOS notification",
        "info": "",
        "x": 350,
        "y": 240,
        "wires": []
    },
    {
        "id": "89444b2b7c65b773",
        "type": "switch",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "property": "payload.event.action",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "CLOSE_GARAGE_DOOR",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 510,
        "y": 280,
        "wires": [
            [
                "789e8f8a7eb04b52"
            ]
        ]
    },
    {
        "id": "789e8f8a7eb04b52",
        "type": "api-call-service",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 5,
        "debugenabled": false,
        "domain": "cover",
        "service": "close_cover",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "cover.garage_door"
        ],
        "data": "",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 710,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "85325ef2801b8631",
        "type": "ha-wait-until",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "outputs": 2,
        "entityId": "cover.garage_door",
        "entityIdFilterType": "exact",
        "property": "",
        "comparator": "is",
        "value": "closed",
        "valueType": "str",
        "timeout": "5",
        "timeoutType": "num",
        "timeoutUnits": "minutes",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "outputProperties": [],
        "entityLocation": "data",
        "entityLocationType": "none",
        "x": 400,
        "y": 180,
        "wires": [
            [
                "784a35516b416c37"
            ],
            []
        ]
    },
    {
        "id": "e593dd3.052432",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

The bottom output of the wait-until node is the timeout. So every 5 mins it will resend the notification until the door is closed.

1 Like

Sorry, the loop was wrong.

1 Like

For some reason, this is not working for me. The garage cover was open the entire night and I never got a notification. @Kermit do you see something off on this flow? Maybe I am missing something, It does work if I change the state in HA but that is not the idea.

You are using the wrong output on the wait until node. The timeout is the bottom output.

1 Like

Oh I did not notice that in both images from @Kermit so I guess the right checking here would be: if the cover still open for X amount of time then resend the message, is that correct?

[
    {
        "id": "85325ef2801b8631",
        "type": "ha-wait-until",
        "z": "e13fb6b3d8f1d842",
        "name": "",
        "server": "e593dd3.052432",
        "version": 2,
        "outputs": 2,
        "entityId": "cover.garage_door",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "open",
        "valueType": "str",
        "timeout": "10",
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "outputProperties": [],
        "entityLocation": "data",
        "entityLocationType": "none",
        "x": 480,
        "y": 200,
        "wires": [
            [],
            [
                "784a35516b416c37"
            ]
        ]
    },
    {
        "id": "e593dd3.052432",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

No, you want to check if the state is closed. If the door closes, the output will go out the top, nothing happens. Otherwise, it will continue waiting until it times out, meaning the door has been open for x time, so resend the notification.

1 Like