Motion light with dimming and restoring if motion

Hi!

I’m trying to create some light automations in our house. I don’t want them to turn on automatically during motion (we will use the wall switches). However, if the light is on and there is no motion there for 15 minutes, I would like to dim the lights to 10%. If there is motion during that time, restore the previous brightness, else turn off the light after 1 minute. Any ideas of how I could store the brightness value so I can restore that?

I can imagine a helper variable can store the brightness.
You could add it after a state change node, so the payload transfers the brightness to the helper.

I don’t have one flow that does what you want, but do have both parts in different flows.

The key part of this one is the “pause”.


It waits for a minute (configurable), or until there is motion, then either resets the light, or turns it off.

I don’t do it in this flow (as the light is always 100%), but you can just get the current state values of the light and write into the message for reuse later.

Hi!

Thanks! Looks like a better setup of the flow.

I’m not so confident with the flow and passing of variables in Nodered just yet. I have the flow running and it performs it´s tasks, but not really correct. I’ve tried debugging but can’t figure this out.

It works to set the dimming level, but it doesn’t restore to it´s original state. When I debug it´s using the dimmed state, so I do something incorrect apperantly. How do I “store” the original state and how do I pass it in to restore it?

Also the weirdest thing is that in the end when it´s supposed to turn the light off, it turns it on. See the snip of the config where its turn_off service, and the result in the first snip where it says turn_on…




Could you share your flow so far please? the code, not just pictures

Hi!

Hmm. When looking at the flow again today it seems to work :smiley: I will validate a bit more…

Here is the code by the way:

[
    {
        "id": "577952c40573e083",
        "type": "server-state-changed",
        "z": "a8def6d13f69b9b1",
        "name": "No motion vardagsrum 15 min",
        "server": "2545e2ef.9a5a0e",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.ir_vardagsrum",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "habool",
        "haltifstate": "false",
        "halt_if_type": "bool",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": false,
        "for": "10",
        "forType": "num",
        "forUnits": "seconds",
        "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": 360,
        "y": 1640,
        "wires": [
            [
                "14176ba016edc25f"
            ],
            []
        ]
    },
    {
        "id": "14176ba016edc25f",
        "type": "api-current-state",
        "z": "a8def6d13f69b9b1",
        "name": "Already On?",
        "server": "2545e2ef.9a5a0e",
        "version": 3,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "light.vrum_taklampa",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "light_orig_state",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "x": 590,
        "y": 1640,
        "wires": [
            [
                "7a95a871fa826a47"
            ],
            []
        ]
    },
    {
        "id": "7a95a871fa826a47",
        "type": "api-call-service",
        "z": "a8def6d13f69b9b1",
        "name": "Dim down",
        "server": "2545e2ef.9a5a0e",
        "version": 5,
        "debugenabled": true,
        "domain": "light",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.vrum_taklampa"
        ],
        "data": "{ \"brightness\": 10 }",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "queue": "none",
        "x": 760,
        "y": 1640,
        "wires": [
            [
                "a07dcb79f051981e"
            ]
        ]
    },
    {
        "id": "a07dcb79f051981e",
        "type": "ha-wait-until",
        "z": "a8def6d13f69b9b1",
        "name": "pause 1 min",
        "server": "2545e2ef.9a5a0e",
        "version": 1,
        "outputs": 2,
        "entityId": "binary_sensor.ir_vardagsrum",
        "entityIdFilterType": "exact",
        "property": "state",
        "comparator": "is",
        "value": "on",
        "valueType": "str",
        "timeout": "10",
        "timeoutType": "num",
        "timeoutUnits": "seconds",
        "entityLocation": "data",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 950,
        "y": 1640,
        "wires": [
            [
                "1e35fb489f889768"
            ],
            [
                "6cac6d63981041bc"
            ]
        ]
    },
    {
        "id": "b4988af385f071ee",
        "type": "api-call-service",
        "z": "a8def6d13f69b9b1",
        "name": "OFF",
        "server": "2545e2ef.9a5a0e",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "turn_off",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.vrum_taklampa"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1390,
        "y": 1660,
        "wires": [
            []
        ]
    },
    {
        "id": "6cac6d63981041bc",
        "type": "api-call-service",
        "z": "a8def6d13f69b9b1",
        "name": "Restore brightness",
        "server": "2545e2ef.9a5a0e",
        "version": 5,
        "debugenabled": true,
        "domain": "light",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.vrum_taklampa"
        ],
        "data": "{\"brightness\":\"{{light_orig_state.attributes.brightness}}\",\"transition\":1}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1150,
        "y": 1680,
        "wires": [
            [
                "b4988af385f071ee"
            ]
        ]
    },
    {
        "id": "5d8cca040307fbbb",
        "type": "inject",
        "z": "a8def6d13f69b9b1",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 400,
        "y": 1720,
        "wires": [
            [
                "14176ba016edc25f"
            ]
        ]
    },
    {
        "id": "1e35fb489f889768",
        "type": "api-call-service",
        "z": "a8def6d13f69b9b1",
        "name": "Restore brightness",
        "server": "2545e2ef.9a5a0e",
        "version": 5,
        "debugenabled": true,
        "domain": "light",
        "service": "turn_on",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.vrum_taklampa"
        ],
        "data": "{\"brightness\":\"{{light_orig_state.attributes.brightness}}\",\"transition\":1}",
        "dataType": "json",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1150,
        "y": 1620,
        "wires": [
            []
        ]
    },
    {
        "id": "2545e2ef.9a5a0e",
        "type": "server",
        "name": "Home Assistant",
        "version": 4,
        "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"
    }
]