Motion Sensor Light ON If within Time Range/Schedule
Hello all,
This is my first post here. I'm pretty new to all this stuff, and looking for help. I would really appreciate any tips to solve the following.
I'm not using HomeAssistant, just node-red and MQTT.
I've got;
- a bedside lamp hooked up to a sonoff basic switch (tasmoto firmware).
- a PIR motion sensor hooked up to d1 mini
- a Pi 3 successfully running Node-red and Mosquitto (MQTT broker)
How can create a flow that:
- Uses a time/light schedule to switch on the lamp (e.g between sunset and midnight)
- ONLY IF motion is detected. Else, don't switch on the light as per the time schedule
I've tried several approaches found on this forum, but nearly all of them have incorporated Home Assistant (nodes) which I don't (intend to) use.
I can succesfully, separately, using MQTT topics;
- Get the light turning on and off ok with just the light-scheduler.
- Switch the light on with just motion detection, using a trigger with whatever time delay to switch off again.
Below is my flow as it currently stands.
Again, any help much appreciated!
[
{
"id": "d5a55d5358bf9c58",
"type": "tab",
"label": "Motion Light If Time Range",
"disabled": false,
"info": "",
"env": []
},
{
"id": "d0e63953bdd549a5",
"type": "mqtt in",
"z": "d5a55d5358bf9c58",
"name": "Motion detected",
"topic": "stat/porch/sensors/PIR1",
"qos": "2",
"datatype": "auto-detect",
"broker": "b0c9ee69a4523c65",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 180,
"y": 260,
"wires": [
[
"3ce78c8000a3284e"
]
]
},
{
"id": "4d406c9d48d76811",
"type": "mqtt out",
"z": "d5a55d5358bf9c58",
"name": "Bedroom Lamp ON/OFF",
"topic": "cmnd/bedroom/LampB/POWER",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "b0c9ee69a4523c65",
"x": 910,
"y": 260,
"wires": []
},
{
"id": "69248e2c42cb3399",
"type": "light-scheduler",
"z": "d5a55d5358bf9c58",
"settings": "b9f0a12258ae5bc5",
"events": "[{\"start\":{\"dow\":5,\"mod\":1170},\"end\":{\"dow\":6,\"mod\":0}},{\"start\":{\"dow\":6,\"mod\":1170},\"end\":{\"dow\":0,\"mod\":0}},{\"start\":{\"dow\":0,\"mod\":1170},\"end\":{\"dow\":1,\"mod\":0}},{\"start\":{\"dow\":2,\"mod\":1170},\"end\":{\"dow\":3,\"mod\":0}},{\"start\":{\"dow\":1,\"mod\":1165},\"end\":{\"dow\":2,\"mod\":0}}]",
"topic": "",
"name": "Bedroom Lamp timer",
"onPayload": "ON",
"onPayloadType": "str",
"offPayload": "OFF",
"offPayloadType": "str",
"onlyWhenDark": true,
"scheduleRndMax": 0,
"sunElevationThreshold": 6,
"sunShowElevationInStatus": false,
"outputfreq": "output.statechange.startup",
"x": 640,
"y": 260,
"wires": [
[
"4d406c9d48d76811"
]
]
},
{
"id": "3ce78c8000a3284e",
"type": "trigger",
"z": "d5a55d5358bf9c58",
"name": "",
"op1": "ON",
"op2": "OFF",
"op1type": "str",
"op2type": "str",
"duration": "5",
"extend": false,
"overrideDelay": false,
"units": "s",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 2,
"x": 420,
"y": 260,
"wires": [
[
"69248e2c42cb3399"
],
[]
]
},
{
"id": "b0c9ee69a4523c65",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.0.106",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "b9f0a12258ae5bc5",
"type": "light-scheduler-settings",
"name": "my settings",
"latitude": "40.729675",
"longitude": " -73.996925"
}
]