I have a bunch of presence and motion sensors (like four, but shush) and when people leave rooms I would like to turn the lights off after five minutes, however if someone returns to the room before that five minutes is up, I’d like to start that countdown again. Is there a grateful way to do this that isn’t me just doing if no activity for five minutes, turn off the lights, else wait five minutes and then turn off the lights. Because that’s ugly, rigid and not very smart at all.

  • walden@sub.wetshaving.social
    link
    fedilink
    English
    arrow-up
    3
    ·
    11 months ago

    In NodeRED it would look like this:

    The top row is triggered when the motion detector changes to “on”. It turns the lights on without delay.
    The second row only triggers if the motion detector has been “off” for 5 minutes. If it goes back to “on” within those 5 minutes, the timer starts over automatically.

    You can try importing it using the following code:

    NodeRED code dropdown
    [
        {
            "id": "1fca03dc3d9e7066",
            "type": "server-state-changed",
            "z": "f3446183.7e46a",
            "name": "Motion On",
            "server": "144bcad2.81b925",
            "version": 5,
            "outputs": 2,
            "exposeAsEntityConfig": "",
            "entityId": "",
            "entityIdType": "exact",
            "outputInitially": false,
            "stateType": "str",
            "ifState": "on",
            "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": 80,
            "y": 1160,
            "wires": [
                [
                    "d01a14f220a57b71"
                ],
                []
            ]
        },
        {
            "id": "d01a14f220a57b71",
            "type": "api-call-service",
            "z": "f3446183.7e46a",
            "name": "Lights On",
            "server": "144bcad2.81b925",
            "version": 5,
            "debugenabled": false,
            "domain": "",
            "service": "",
            "areaId": [],
            "deviceId": [],
            "entityId": [],
            "data": "",
            "dataType": "jsonata",
            "mergeContext": "",
            "mustacheAltTags": false,
            "outputProperties": [],
            "queue": "none",
            "x": 300,
            "y": 1160,
            "wires": [
                []
            ]
        },
        {
            "id": "5737d7e58d22e1a6",
            "type": "api-call-service",
            "z": "f3446183.7e46a",
            "name": "Lights Off",
            "server": "144bcad2.81b925",
            "version": 5,
            "debugenabled": false,
            "domain": "",
            "service": "",
            "areaId": [],
            "deviceId": [],
            "entityId": [],
            "data": "",
            "dataType": "jsonata",
            "mergeContext": "",
            "mustacheAltTags": false,
            "outputProperties": [],
            "queue": "none",
            "x": 300,
            "y": 1200,
            "wires": [
                []
            ]
        },
        {
            "id": "b203774e1f8bea1f",
            "type": "server-state-changed",
            "z": "f3446183.7e46a",
            "name": "Motion Off for 5",
            "server": "144bcad2.81b925",
            "version": 5,
            "outputs": 2,
            "exposeAsEntityConfig": "",
            "entityId": "",
            "entityIdType": "exact",
            "outputInitially": false,
            "stateType": "str",
            "ifState": "off",
            "ifStateType": "str",
            "ifStateOperator": "is",
            "outputOnlyOnStateChange": 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": 100,
            "y": 1200,
            "wires": [
                [
                    "5737d7e58d22e1a6"
                ],
                []
            ]
        },
        {
            "id": "144bcad2.81b925",
            "type": "server",
            "name": "Home Assistant",
            "version": 5,
            "addon": true,
            "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": "at: ",
            "statusYear": "hidden",
            "statusMonth": "short",
            "statusDay": "numeric",
            "statusHourCycle": "h23",
            "statusTimeFormat": "h:m",
            "enableGlobalContextStore": true
        }
    ]
    
      • Flying_Hellfish@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        11 months ago

        No, but you CAN use HA timers in NodeRED. You just have to trigger off the state of the timer itself. I did get it to work but it was quite a bit of spaghetti, I found it easier to use eventID triggers in the standard automation GUI for dealing with persistent timers.

      • walden@sub.wetshaving.social
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        When I restart mine, I restart HA only, and all of the add-ons (including NodeRED) keep running. The problem is as soon as HA restarts, it blasts all of the states to NodeRED, and for the most part (I think), they all go from “unavailable” to “on/off”. This restarts whatever timers NodeRED keeps track of. I don’t know of a good way around this, but I restart HA so infrequently that it doesn’t matter for me.

    • sabreW4K3@lemmy.tfOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      11 months ago

      OMG! What type of person are you? I ask a simple question and you introduce me to cool new stuff and now I need to learn all about it. You will be recommending me NodeRed videos for weeks now.

      Thank you!