Light state help

Hello. Brand new to Node Red so you may need to dumb it way down for me. I have a flow that uses a motion sensor to turn on a set of lights at 30% brightness when motion is detected but only between 2200- 0600, stays on for x min then if no motion it turns off. Works great. What I want it to further do is starting at 0601 if the light is turned on by using google or a switch etc.since the motion sensor is not active during daylight, I want them to turn on at 100% instead them turning on at 30% and then I have to tell them to go to 100%. How could I accomplish this? TIA for any help!

Hello @balucanb.

Instead of having your 30% level hard coded maybe use the value of a context variable flow.lightlevel.

Set flow.lightlevel to 30 in the evening and 100 in the morning using Inject or Cronplus nodes.

If you share the flow you currently have we can give more precise advice.

...deleted this and put the code in the right way below.

Unfortunately I can't import your flow. You should use the </> button before you paste it or the forum mangles the javascript.
Nor do I have the HomeAssistant nodes but it should be possible to use something like this to set the brightness based on the time:
Untitled 1

[
    {
        "id": "16eb9d515b3b13eb",
        "type": "inject",
        "z": "1744d37c2c9f5c5f",
        "name": "30% at 22:00",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "00 22 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "30",
        "payloadType": "num",
        "x": 340,
        "y": 480,
        "wires": [
            [
                "c8c80b63cec2b107"
            ]
        ]
    },
    {
        "id": "90d370cefc37b67f",
        "type": "inject",
        "z": "1744d37c2c9f5c5f",
        "name": "100% at 06:00",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "00 06 * * *",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "100",
        "payloadType": "num",
        "x": 340,
        "y": 520,
        "wires": [
            [
                "c8c80b63cec2b107"
            ]
        ]
    },
    {
        "id": "c8c80b63cec2b107",
        "type": "change",
        "z": "1744d37c2c9f5c5f",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "lightlevel",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 500,
        "wires": [
            []
        ]
    },
    {
        "id": "40cead3c6facbfbc",
        "type": "function",
        "z": "1744d37c2c9f5c5f",
        "name": "",
        "func": "const lightlevel = flow.get('lightlevel') | 30;\nmsg.payload =  {entity_id:\"light.kitchen_lights\",\nbrightness_pct: lightlevel,\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 600,
        "wires": [
            [
                "82363129fbe7bbf9"
            ]
        ]
    }
]

OK thanks for the tip let me try to paste it the right way- to see if it helps you help me! Thanks again.
EDIT- pasted the wrong flow the 1st time.

[
    {
        "id": "cb7cbed90d03b8cd",
        "type": "tab",
        "label": "Kitchen lights",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "0e93c8877cc85350",
        "type": "server-state-changed",
        "z": "cb7cbed90d03b8cd",
        "name": "When motion is detected",
        "server": "2c9c44de.834a0c",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.kitchen_motion_sensor_occupancy",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": false,
        "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": 230,
        "y": 220,
        "wires": [
            [
                "141056f780c5fd91"
            ]
        ]
    },
    {
        "id": "79d9cf42156e9e04",
        "type": "switch",
        "z": "cb7cbed90d03b8cd",
        "name": "on or off",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "on",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "off",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 710,
        "y": 220,
        "wires": [
            [
                "7f54a3a201d9129b",
                "f237cde633397a0b"
            ],
            [
                "f237cde633397a0b"
            ]
        ]
    },
    {
        "id": "7f54a3a201d9129b",
        "type": "api-call-service",
        "z": "cb7cbed90d03b8cd",
        "name": "on kitchen lights",
        "server": "2c9c44de.834a0c",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_on",
        "entityId": "light.kitchen_lights",
        "data": "{\t   \"entity_id\":\"light.kitchen_lights\",\t   \"brightness_pct\":30\t}    ",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 970,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "f237cde633397a0b",
        "type": "trigger",
        "z": "cb7cbed90d03b8cd",
        "name": "trigger",
        "op1": "",
        "op2": "off",
        "op1type": "nul",
        "op2type": "str",
        "duration": "5",
        "extend": false,
        "overrideDelay": false,
        "units": "min",
        "reset": "on",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 680,
        "y": 320,
        "wires": [
            [
                "5ea68ba3912d6c74"
            ]
        ]
    },
    {
        "id": "5ea68ba3912d6c74",
        "type": "api-call-service",
        "z": "cb7cbed90d03b8cd",
        "name": "off kitchen lights",
        "server": "2c9c44de.834a0c",
        "version": 3,
        "debugenabled": false,
        "service_domain": "light",
        "service": "turn_off",
        "entityId": "light.kitchen_lights",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 970,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "141056f780c5fd91",
        "type": "time-range-switch",
        "z": "cb7cbed90d03b8cd",
        "name": "2330-sunrise",
        "lat": "32.81683",
        "lon": "-96.87138",
        "startTime": "23:30",
        "endTime": "sunrise",
        "startOffset": 0,
        "endOffset": "30",
        "x": 460,
        "y": 220,
        "wires": [
            [
                "79d9cf42156e9e04"
            ],
            []
        ]
    },
    {
        "id": "2c9c44de.834a0c",
        "type": "server",
        "name": "Home Assistant",
        "version": 2,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": 30
    }
]

So I imported your example- you will need to bear with me here because to say I understand how all this works would be a lie. I understand the inject nodes are saying turn the lights to X brightness at this time and set it to this brightness at this time which go into the change node, which I think is what actually tells the flow, based on the msg it gets from either of the inject nodes what the brightness needs to be? The function node is running code about brightness level? Now no clue how /where to place the function node or exactly where to drop these into my flow ( playing with it now). I could be 100% wrong but it appears like this will set the brightness at the correct levels at the correct times but I may not have been clear (or I just don't understand how it works) what I am going for which is at 0601 the motion sensor will not have any effect on on/off and when anyone turns the light on ( They would be using a voice command) the light would then turn on at 100% brightness every time until 2200 when the flow nighttime mode kicked in. If your example does that then accept my apologies for my total lack of understanding here!

My example is not complete because I have none of your nodes server-state-changed, time-range-switch or api-call-service. I presume these come from Home Assistant.

Anyway, at some point in your flow as you first posted it there was something similar to this:

{entity_id:"light.kitchen_lights", "brightness_pct": 30,}

The snippet of code I posted :
1 creates a variable which is accessible just on that flow and which is given the value 100 or 30 depending on the time.
2 (the function node) assembles in msg.payload a JS object similar to yours above, but instead of 30 it uses the current value of the variable.

I assumed that you could pass that object instead of your version to whatever turns the lights on.
But the code you have posted now seems to be completely different, it does not include brightness_pct at all.

Maybe someone else who does have Home Assistant can be more useful. I can't help.

My mistake I reposted the correct info- I mistakenly posted the wrong flow. Yes I am working with Home Assistant. Thanks for the help.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.