Motion, timers and lights / getting started

Hi

I am using Node-Red on Home Assistant.
I am new to Node-Red and Home Assistant

lets take an example

i have a Sonoff motion sensor
when activated it triggers a Sonoff basic switch that turns on the lamp on the night stand.
when the motionsensor resets the lamp turns of.
easy!! but i am restricted to the 90 seconds that is the timeout for the sensor
I have build the sequense so that it only works in a preset timerange.

if i want to have the lights turn on by auto from 18:30 - 20:30 i can also do that but combining the two ! aarrgghh :frowning: it is disco lights all ove the place. on off on on off on off off off on off and so on

i have done some Ladder and FB programming on Siemens and on WAGO PLC's before so it is not all ne to me but i would like some pointers in the right direction to make my life easier.

my "problem" is all the nodes and what to begin with in a sequense
normaly i use input and output and some sort of logic betwen reading input to activating output.

Is there a good "Node-Red for idiots" guide out there or some good video resources / written guides

BR
BlueScreenTT

Use the lightscheduler Nodes - which offers you a graphical interface to filter times. So you can let your auto flow as it is - but with the filter nodes you can decide if the messages reach your switch.

You can even use astro times - instead of fixed times.

Welcome to the forum @bluescreentt

Have a look at this playlist: Node-RED Essentials. The videos are done by the developers of node-red.

Thanks to both of you
:slight_smile:

This one didnt solve my problem having a "auto on" function together with a motion sensor :frowning:

i kind of got it working but my problem is that I can not figure out how to start the sequense

I get it that there are input and output nodes and in my herad it will be logical to start with an output node but i cant find one.

using scheduler just gave me more problems, it is not logic how it is working :frowning:
here is my almost working flow, I am missing a starting node for the first time range node

i think my question is

can i start a sequense with an input to output node ?? like call service - big timer - current state and so on ! ???

[
    {
        "id": "c7338da316b5f946",
        "type": "tab",
        "label": "Ninja",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "3c57816acc7bac9a",
        "type": "time-range-switch",
        "z": "c7338da316b5f946",
        "name": "20:46 - 08:00",
        "lat": "",
        "lon": "",
        "startTime": "20:46",
        "endTime": "08:00",
        "startOffset": "",
        "endOffset": "",
        "x": 270,
        "y": 160,
        "wires": [
            [
                "0288adf244e93216"
            ],
            []
        ]
    },
    {
        "id": "203576209dcbf585",
        "type": "server-state-changed",
        "z": "c7338da316b5f946",
        "name": "Motion Nijna",
        "server": "aa22a8c9.f573b8",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "binary_sensor.so_ms_03_nin_ias_zone",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "on",
        "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": "true",
                "valueType": "bool"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 70,
        "y": 160,
        "wires": [
            [
                "3c57816acc7bac9a"
            ],
            [
                "f964153db80bf6ba"
            ]
        ]
    },
    {
        "id": "f2bfb800053422dd",
        "type": "api-call-service",
        "z": "c7338da316b5f946",
        "name": "Turn Unicorn off",
        "server": "aa22a8c9.f573b8",
        "version": 3,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_off",
        "entityId": "switch.ninjaunic",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 760,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "0288adf244e93216",
        "type": "api-call-service",
        "z": "c7338da316b5f946",
        "name": "Turn Unicorn on",
        "server": "aa22a8c9.f573b8",
        "version": 3,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_on",
        "entityId": "switch.ninjaunic",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 740,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "4e32ab0643e8ec73",
        "type": "time-range-switch",
        "z": "c7338da316b5f946",
        "name": "18:30 - 20:45",
        "lat": "",
        "lon": "",
        "startTime": "18:30",
        "endTime": "20:45",
        "startOffset": "",
        "endOffset": "",
        "x": 270,
        "y": 60,
        "wires": [
            [
                "34fb258c7e13dd99"
            ],
            [
                "e691c0a55f9e529c"
            ]
        ]
    },
    {
        "id": "34fb258c7e13dd99",
        "type": "api-current-state",
        "z": "c7338da316b5f946",
        "name": "Is Unicorn on",
        "server": "aa22a8c9.f573b8",
        "version": 2,
        "outputs": 2,
        "halt_if": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "switch.ninjaunic",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 530,
        "y": 40,
        "wires": [
            [],
            [
                "0288adf244e93216"
            ]
        ]
    },
    {
        "id": "e691c0a55f9e529c",
        "type": "api-current-state",
        "z": "c7338da316b5f946",
        "name": "Is Unicorn off",
        "server": "aa22a8c9.f573b8",
        "version": 2,
        "outputs": 2,
        "halt_if": "off",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "switch.ninjaunic",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 530,
        "y": 140,
        "wires": [
            [],
            [
                "f2bfb800053422dd"
            ]
        ]
    },
    {
        "id": "f964153db80bf6ba",
        "type": "time-range-switch",
        "z": "c7338da316b5f946",
        "name": "08:01 - 18:29",
        "lat": "",
        "lon": "",
        "startTime": "08:01",
        "endTime": "18:29",
        "startOffset": "",
        "endOffset": "",
        "x": 270,
        "y": 220,
        "wires": [
            [
                "f2bfb800053422dd"
            ],
            []
        ]
    },
    {
        "id": "aa22a8c9.f573b8",
        "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
    }
]

the lightscheduling nodes - have filter nodes - that means that they do not trigger. You can use you existing triggers. For sure you can trigger with a scheduler including an inject node - but I think you need as primary trigger still your motion sensor and you allow them to be only active within a specific time frame. So I think your input trigger is still you motion sensor.

hmm i will give it one more try :slight_smile:

If you don't want to use additional nodes ( I have not the time range switches ) you can use normal switch nodes as well - the only thing is - you have to use time ranges within a day otherwise you just negate the output

So there is no need for your time range switches:

until is alway excluded. If you which do decide over night switch then just negate or take the false exit.

[
    {
        "id": "9ec63930.7a41d8",
        "type": "switch",
        "z": "6e170384.60c96c",
        "name": "Between 10:48 and 11:00",
        "property": "$moment().isBetween($moment(\"10:48\", \"HH:mm\"),$moment(\"11:00\", \"HH:mm\"),'minute')",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1670,
        "y": 2140,
        "wires": [
            [
                "63e091c.217c47"
            ],
            [
                "57759b84.262984"
            ]
        ]
    },
    {
        "id": "76ac8c2.21f6f74",
        "type": "inject",
        "z": "6e170384.60c96c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "is payload",
        "payloadType": "str",
        "x": 1480,
        "y": 2140,
        "wires": [
            [
                "9ec63930.7a41d8"
            ]
        ]
    },
    {
        "id": "63e091c.217c47",
        "type": "debug",
        "z": "6e170384.60c96c",
        "name": "true",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1870,
        "y": 2120,
        "wires": []
    },
    {
        "id": "57759b84.262984",
        "type": "debug",
        "z": "6e170384.60c96c",
        "name": "false",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1870,
        "y": 2160,
        "wires": []
    }
]

If you want to include the until time then use the closing square brackets as a third parameter string - as described in the moments library.

ok

i will take a look and see if i understand it

Thank you

why is this not working ?

[{"id":"c7338da316b5f946","type":"tab","label":"Ninja","disabled":false,"info":"","env":[]},{"id":"43a09d7519428796","type":"time-range-switch","z":"c7338da316b5f946","name":"20:01 - 08:00","lat":"","lon":"","startTime":"20:01","endTime":"08:00","startOffset":"","endOffset":"","x":310,"y":180,"wires":[["ed220976b6a6f70d"],[]]},{"id":"dfebe1fdd71ad3bb","type":"server-state-changed","z":"c7338da316b5f946","name":"Motion living room","server":"aa22a8c9.f573b8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.so_ms_03_nin_ias_zone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","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":"true","valueType":"bool"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":200,"wires":[["43a09d7519428796"],["c0e3c78a8d2912b7"]]},{"id":"b6e2a4e960c561c9","type":"api-call-service","z":"c7338da316b5f946","name":"Turn Unicorn off","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.ninjaunic","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":240,"wires":[[]]},{"id":"ed220976b6a6f70d","type":"api-call-service","z":"c7338da316b5f946","name":"Turn Unicorn on","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.ninjaunic","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":100,"wires":[[]]},{"id":"17761876434b479d","type":"api-current-state","z":"c7338da316b5f946","name":"Is Unicorn on","server":"aa22a8c9.f573b8","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.ninjaunic","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":510,"y":60,"wires":[[],["ed220976b6a6f70d"]]},{"id":"1ad29596f7bc68e4","type":"api-current-state","z":"c7338da316b5f946","name":"Is Unicorn off","server":"aa22a8c9.f573b8","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.ninjaunic","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":570,"y":180,"wires":[[],["b6e2a4e960c561c9"]]},{"id":"c0e3c78a8d2912b7","type":"time-range-switch","z":"c7338da316b5f946","name":"08:01 - 18:29","lat":"","lon":"","startTime":"08:01","endTime":"18:29","startOffset":"","endOffset":"","x":310,"y":240,"wires":[["1ad29596f7bc68e4"],[]]},{"id":"555efe1fcc4d24fa","type":"bigtimer","z":"c7338da316b5f946","outtopic":"","outpayload1":"on","outpayload2":"off","name":"Big Timer","comment":"","lat":0,"lon":0,"starttime":"1110","endtime":"1200","starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"ON","outtext2":"OFF","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":0,"xmonth7":0,"xday8":0,"xmonth8":0,"xday9":0,"xmonth9":0,"xday10":0,"xmonth10":0,"xday11":0,"xmonth11":0,"xday12":0,"xmonth12":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":140,"y":60,"wires":[["17761876434b479d"],[],[]]},{"id":"aa22a8c9.f573b8","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}]
[{"id":"8bb0e5ac41f12b18","type":"tab","label":"Living room","disabled":false,"info":"","env":[]},{"id":"1bf2917a380e19f8","type":"time-range-switch","z":"8bb0e5ac41f12b18","name":"23:56 - 08:00","lat":"","lon":"","startTime":"23:56","endTime":"08:00","startOffset":"","endOffset":"","x":310,"y":160,"wires":[["4e291c7ed4720ce2"],[]]},{"id":"20fba06bc588f1b6","type":"server-state-changed","z":"8bb0e5ac41f12b18","name":"Motion living room","server":"aa22a8c9.f573b8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.so_ms_02_liv_ias_zone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","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":"true","valueType":"bool"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":180,"wires":[["1bf2917a380e19f8"],[]]},{"id":"4e291c7ed4720ce2","type":"api-call-service","z":"8bb0e5ac41f12b18","name":"Turn Globe on","server":"aa22a8c9.f573b8","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.livwin1, switch.livwin2, switch.livwin3","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":80,"wires":[[]]},{"id":"7fab683eb8dd2d40","type":"api-current-state","z":"8bb0e5ac41f12b18","name":"are the lights on","server":"aa22a8c9.f573b8","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"switch.livwin1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":520,"y":40,"wires":[[],["4e291c7ed4720ce2"]]},{"id":"885f41f20706c215","type":"bigtimer","z":"8bb0e5ac41f12b18","outtopic":"","outpayload1":"ok","outpayload2":"off","name":"Big Timer","comment":"","lat":0,"lon":0,"starttime":"900","endtime":1425,"starttime2":0,"endtime2":0,"startoff":0,"endoff":0,"startoff2":0,"endoff2":0,"offs":0,"outtext1":"ON","outtext2":"OFF","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":true,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":true,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"day6":0,"month6":0,"day7":0,"month7":0,"day8":0,"month8":0,"day9":0,"month9":0,"day10":0,"month10":0,"day11":0,"month11":0,"day12":0,"month12":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"d6":0,"w6":0,"xday1":0,"xmonth1":0,"xday2":0,"xmonth2":0,"xday3":0,"xmonth3":0,"xday4":0,"xmonth4":0,"xday5":0,"xmonth5":0,"xday6":0,"xmonth6":0,"xday7":0,"xmonth7":0,"xday8":0,"xmonth8":0,"xday9":0,"xmonth9":0,"xday10":0,"xmonth10":0,"xday11":0,"xmonth11":0,"xday12":0,"xmonth12":0,"xd1":0,"xw1":0,"xd2":0,"xw2":0,"xd3":0,"xw3":0,"xd4":0,"xw4":0,"xd5":0,"xw5":0,"xd6":0,"xw6":0,"suspend":false,"random":false,"randon1":false,"randoff1":false,"randon2":false,"randoff2":false,"repeat":true,"atstart":true,"odd":false,"even":false,"x":220,"y":60,"wires":[["7fab683eb8dd2d40"],[],[]]},{"id":"aa22a8c9.f573b8","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}]