Hi!
In node-red, how do I extend a delay timer by X minutes, if a sensor is triggered?
Let me explain: I have a pir sensor that turns on a light, if another light is turned off and if current time is night time. If these triggers are true, the light is turned on for 5 minutes.
What I really want is that after initial timer start, if sensor is triggered again, add +2 minutes to the light timmer. My PIR sensor has a timeout of 1 minute, so I think adding +1 minute on each ‘detection’ will be fine…but how do I get this?
This is my current flow:
[
{
"id": "c60afa80.acc318",
"type": "tab",
"label": "Spot Noturno Copa",
"disabled": false,
"info": ""
},
{
"id": "a8581414.fd9928",
"type": "server-state-changed",
"z": "c60afa80.acc318",
"name": "Copa",
"server": "2ba92c0c.9dae24",
"version": 4,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "binary_sensor.sala_de_jantar_pir_occupancy",
"entityidfiltertype": "exact",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"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": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "eventData"
},
{
"property": "topic",
"propertyType": "msg",
"value": "",
"valueType": "triggerId"
}
],
"x": 130,
"y": 280,
"wires": [
[
"c44f5425.21fcf8",
"b3e460bc.40055"
]
]
},
{
"id": "c1778193.e6f73",
"type": "time-range-switch",
"z": "c60afa80.acc318",
"name": "",
"lat": "-20.5414",
"lon": "-47.4025",
"startTime": "21:00",
"endTime": "07:00",
"startOffset": 0,
"endOffset": 0,
"x": 570,
"y": 200,
"wires": [
[
"7426341644098565"
],
[]
]
},
{
"id": "eba96d0.1bb539",
"type": "delay",
"z": "c60afa80.acc318",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "minutes",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"outputs": 1,
"x": 1400,
"y": 420,
"wires": [
[
"40bad5b1.cccd0c"
]
]
},
{
"id": "9686ccb3.00f14",
"type": "api-call-service",
"z": "c60afa80.acc318",
"name": "Liga Spot Copa",
"server": "2ba92c0c.9dae24",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_on",
"areaId": [],
"deviceId": [],
"entityId": [
"light.sala_de_jantar_spot_4"
],
"data": "{\"brightness_pct\": 20, \"color_temp\": 370}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1420,
"y": 300,
"wires": [
[
"eba96d0.1bb539"
]
]
},
{
"id": "40bad5b1.cccd0c",
"type": "api-call-service",
"z": "c60afa80.acc318",
"name": "Desliga Spot Copa",
"server": "2ba92c0c.9dae24",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [
"light.sala_de_jantar_spot_4"
],
"data": "",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1630,
"y": 540,
"wires": [
[]
]
},
{
"id": "c44f5425.21fcf8",
"type": "switch",
"z": "c60afa80.acc318",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 360,
"y": 280,
"wires": [
[
"c1778193.e6f73"
]
]
},
{
"id": "5b1fb03.82bfb5",
"type": "inject",
"z": "c60afa80.acc318",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1200,
"y": 100,
"wires": [
[
"9686ccb3.00f14"
]
]
},
{
"id": "ebac1854.ba02f8",
"type": "inject",
"z": "c60afa80.acc318",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1340,
"y": 600,
"wires": [
[
"40bad5b1.cccd0c"
]
]
},
{
"id": "b3e460bc.40055",
"type": "debug",
"z": "c60afa80.acc318",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 390,
"y": 560,
"wires": []
},
{
"id": "7426341644098565",
"type": "api-current-state",
"z": "c60afa80.acc318",
"name": "",
"server": "2ba92c0c.9dae24",
"version": 3,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "light.sala_de_jantar_spot_1",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 920,
"y": 240,
"wires": [
[
"cdbd8749a13089f1"
],
[]
]
},
{
"id": "cdbd8749a13089f1",
"type": "api-current-state",
"z": "c60afa80.acc318",
"name": "",
"server": "2ba92c0c.9dae24",
"version": 3,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "light.sala_de_jantar_spot_2",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 920,
"y": 300,
"wires": [
[
"d159f89173b2d36e"
],
[]
]
},
{
"id": "d159f89173b2d36e",
"type": "api-current-state",
"z": "c60afa80.acc318",
"name": "",
"server": "2ba92c0c.9dae24",
"version": 3,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "light.sala_de_jantar_spot_3",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 920,
"y": 360,
"wires": [
[
"86dea2d728940e94"
],
[]
]
},
{
"id": "86dea2d728940e94",
"type": "api-current-state",
"z": "c60afa80.acc318",
"name": "Luz Sala desligada",
"server": "2ba92c0c.9dae24",
"version": 3,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "light.interruptor_sala",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 990,
"y": 420,
"wires": [
[
"4e6d019ea6ac4dd2"
],
[]
]
},
{
"id": "4e6d019ea6ac4dd2",
"type": "api-current-state",
"z": "c60afa80.acc318",
"name": "Luz Cozinha desligada",
"server": "2ba92c0c.9dae24",
"version": 3,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "light.luz_cozinha",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": 0,
"forType": "num",
"forUnits": "minutes",
"x": 980,
"y": 480,
"wires": [
[
"9686ccb3.00f14"
],
[]
]
},
{
"id": "2ba92c0c.9dae24",
"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
}
]