[
{
"id": "0667a86b20ba952b",
"type": "function",
"z": "houseMemberStatusFlow",
"name": "Prepare Sunrise Effect",
"func": "// Parse dawn time from the sensor\nconst sunDawn = new Date(msg.sun_dawn); // Time from sensor\nconst currentTime = new Date(); // Current time\n\n// Calculate time difference between dawn and now\nconst timeDiff = (currentTime - sunDawn) / 1000; // Time difference in seconds\n\n// Sunrise effect duration (15 minutes)\nconst sunriseDuration = 15 * 60; // 15 minutes in seconds\nconst steps = 30; // Number of steps for smooth transitions\n\n// Brightness and color temperature settings\nconst startBrightness = 1; // Start brightness\nconst endBrightness = 70; // End brightness\n\n// Adjust color temperature dynamically based on dawn time\nconst dawnColorTemp = 1800; // Use 1800K as the base warm color temperature\nconst startColorTemp = dawnColorTemp; // Start with the dawn color temperature\nconst endColorTemp = 4000; // End with neutral daylight color temperature\n\nconst interval = Math.round(sunriseDuration / steps); // Time per step\n\nconst brightnessStep = (endBrightness - startBrightness) / steps;\nconst colorTempStep = (endColorTemp - startColorTemp) / steps;\n\nconst sunriseSteps = [];\nfor (let i = 0; i <= steps; i++) {\n sunriseSteps.push({\n brightness: Math.round(startBrightness + i * brightnessStep),\n color_temp: Math.round(startColorTemp + i * colorTempStep)\n });\n}\n\nmsg.steps = sunriseSteps;\nmsg.interval = interval * 1000; // Convert to milliseconds\nmsg.stepIndex = 0; // Initialize step index\nmsg.entity_id = \"light.main_door_light\"; // Replace with your light entity\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1800,
"y": 860,
"wires": [
[
"bf4e345a6bed7601"
]
]
},
{
"id": "bf4e345a6bed7601",
"type": "delay",
"z": "houseMemberStatusFlow",
"name": "Step Interval",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 2000,
"y": 860,
"wires": [
[
"c22290f5dd129d2a"
]
]
},
{
"id": "c22290f5dd129d2a",
"type": "function",
"z": "houseMemberStatusFlow",
"name": "Process Sunrise Step",
"func": "const steps = msg.steps;\nconst stepIndex = msg.stepIndex;\n\nif (stepIndex >= steps.length) {\n // All steps are completed\n msg.payload = {\n entity_id: msg.entity_id // Light to turn off\n };\n return [null, msg]; // Output to the \"Turn Off Lamp\" node\n}\n\n// Get the current step\nconst currentStep = steps[stepIndex];\n\n// Build the payload for the API call\nmsg.payload = {\n entity_id: msg.entity_id, // Include the light entity ID\n brightness_pct: currentStep.brightness,\n color_temp: currentStep.color_temp\n};\n\n// Increment step index\nmsg.stepIndex++;\n\nreturn [msg, null];",
"outputs": 2,
"noerr": 0,
"x": 2200,
"y": 860,
"wires": [
[
"c8752a44f658ae6c",
"bf4e345a6bed7601"
],
[
"e8cb300728373c81"
]
]
},
{
"id": "c8752a44f658ae6c",
"type": "api-call-service",
"z": "houseMemberStatusFlow",
"name": "Adjust Light",
"server": "",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_on",
"areaId": [],
"deviceId": [],
"entityId": [
"light.main_door_light"
],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2500,
"y": 840,
"wires": [
[]
]
},
{
"id": "e8cb300728373c81",
"type": "api-call-service",
"z": "houseMemberStatusFlow",
"name": "Turn Off Lamp",
"server": "",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"entity_id\": \"light.main_door_light\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2400,
"y": 960,
"wires": [
[]
]
},
{
"id": "34536d756a4e97b1",
"type": "api-current-state",
"z": "houseMemberStatusFlow",
"name": "Get Sun Dawn Time",
"server": "",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sensor.home_sun_dawn",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [],
"for": "",
"forType": "num",
"x": 1550,
"y": 860,
"wires": [
[]
]
},
{
"id": "1ba74ce55cfa520d",
"type": "server-state-changed",
"z": "houseMemberStatusFlow",
"name": "house morning ON?",
"server": "",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "on",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": 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": 1300,
"y": 860,
"wires": [
[
"34536d756a4e97b1"
],
[]
]
}
]
[
{
"id": "b17ffd5282f5a6a4",
"type": "server-state-changed",
"z": "houseMemberStatusFlow",
"name": "house morning ON ?",
"server": "",
"version": 5,
"outputs": 2,
"exposeAsEntityConfig": "toggle_sunrise",
"entityIdType": "exact",
"outputInitially": false,
"stateType": "str",
"ifState": "on",
"ifStateType": "str",
"ifStateOperator": "is",
"outputOnlyOnStateChange": true,
"for": 0,
"forType": "num",
"forUnits": "minutes",
"ignorePrevStateNull": false,
"ignorePrevStateUnknown": false,
"ignorePrevStateUnavailable": false,
"ignoreCurrentStateUnknown": false,
"ignoreCurrentStateUnavailable": false,
"outputProperties": [],
"x": 1380,
"y": 320,
"wires": [
[
"5235cd40b7f851e2"
],
[]
]
},
{
"id": "5235cd40b7f851e2",
"type": "function",
"z": "houseMemberStatusFlow",
"name": "Calculate Sunrise Steps",
"func": "const sunriseDuration = 15 * 60; // 15 minutes in seconds\nconst steps = 30; // Number of steps (adjust for smoothness)\n\nconst startBrightness = 5; // Start brightness (more visible than 1%)\nconst endBrightness = 100; // End brightness (full daylight)\n\nconst startColorTemp = 1800; // Start color temperature (candlelight)\nconst endColorTemp = 5500; // End color temperature (sunlight)\n\nconst interval = Math.round(sunriseDuration / steps); // Time per step\n\nconst brightnessStep = (endBrightness - startBrightness) / steps;\nconst colorTempStep = (endColorTemp - startColorTemp) / steps;\n\nconst sunriseSteps = [];\nfor (let i = 0; i <= steps; i++) {\n sunriseSteps.push({\n brightness: Math.round(startBrightness + i * brightnessStep),\n color_temp: Math.round(startColorTemp + i * colorTempStep)\n });\n}\n\nmsg.steps = sunriseSteps;\nmsg.interval = interval * 1000; // Convert to milliseconds\nmsg.stepIndex = 0; // Initialize step index\nmsg.entity_id = \"light.main_door_light\"; // Replace with your light entity\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1650,
"y": 320,
"wires": [
[
"eec207b41688b350"
]
]
},
{
"id": "eec207b41688b350",
"type": "delay",
"z": "houseMemberStatusFlow",
"name": "Step Interval",
"pauseType": "delay",
"timeout": "1",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 1850,
"y": 320,
"wires": [
[
"d2e56b444dd6174c"
]
]
},
{
"id": "d2e56b444dd6174c",
"type": "function",
"z": "houseMemberStatusFlow",
"name": "Process Sunrise Step",
"func": "const steps = msg.steps;\nconst stepIndex = msg.stepIndex;\n\nif (stepIndex >= steps.length) {\n // All steps are completed\n msg.payload = {\n entity_id: msg.entity_id // Light to turn off\n };\n return [null, msg]; // Output to the \"Turn Off Lamp\" node\n}\n\n// Get the current step\nconst currentStep = steps[stepIndex];\n\n// Build the payload for the API call\nmsg.payload = {\n entity_id: msg.entity_id, // Include the light entity ID\n brightness_pct: currentStep.brightness,\n color_temp: currentStep.color_temp\n};\n\n// Increment step index\nmsg.stepIndex++;\n\nreturn [msg, null];",
"outputs": 2,
"x": 2050,
"y": 320,
"wires": [
[
"c3be3f5435f52f4d",
"eec207b41688b350"
],
[
"2e1cb1a126584c72"
]
]
},
{
"id": "c3be3f5435f52f4d",
"type": "api-call-service",
"z": "houseMemberStatusFlow",
"name": "Adjust Light",
"server": "",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_on",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2280,
"y": 280,
"wires": [
[]
]
},
{
"id": "2e1cb1a126584c72",
"type": "api-call-service",
"z": "houseMemberStatusFlow",
"name": "Turn Off Lamp",
"server": "",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2330,
"y": 400,
"wires": [
[]
]
},
{
"id": "toggle_sunrise",
"type": "ha-entity-config",
"server": "your_ha_server",
"deviceConfig": "",
"name": "exposed as for Sunrise Toggle",
"version": 6,
"entityType": "switch",
"haConfig": [
{
"property": "name",
"value": "Sunrise Automation Toggle"
},
{
"property": "icon",
"value": "mdi:weather-sunset-up"
}
],
"resend": false
}
]