Witam,
jest to moje pierwsze podejście do Node Red.
Dużo czytałem na ten temat, al nie mogę sobie poradzić z jednym problemem.
To mój kod z NR:
[
{
"id": "ff8ced7818e0a1c1",
"type": "tab",
"label": "plate",
"disabled": false,
"info": ""
},
{
"id": "89d95b39426da6c5",
"type": "inject",
"z": "ff8ced7818e0a1c1",
"name": "Co 10 minut",
"props": [
{
"p": "payload"
}
],
"repeat": "600",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{}",
"payloadType": "json",
"x": 70,
"y": 60,
"wires": [
[
"25166d1e026059b6"
]
]
},
{
"id": "25166d1e026059b6",
"type": "api-current-state",
"z": "ff8ced7818e0a1c1",
"name": "Sprawdź zachód słońca",
"server": "f8e3f945.af0568",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "sun.sun",
"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": 270,
"y": 60,
"wires": [
[
"1e0d62ebabd9f48a"
]
]
},
{
"id": "1e0d62ebabd9f48a",
"type": "function",
"z": "ff8ced7818e0a1c1",
"name": "Ustaw jasność",
"func": "// Debugowanie: Sprawdzamy stan\nnode.warn(\"Stan sun.sun: \" + msg.payload.state);\n\n// Jeśli słońce jest poniżej horyzontu (czyli po zachodzie)\nif (msg.payload.state === \"below_horizon\") {\n // Po zachodzie słońca ustaw jasność na 50% (128)\n msg.payload = { brightness: 25};\n} else {\n // Przed zachodem słońca ustaw jasność na 100% (255)\n msg.payload = { brightness: 128 };\n}\n\n// Debugowanie: Pokazujemy wynik jasności\nnode.warn(\"Ustawiona jasność: \" + msg.payload.brightness);\n\nreturn msg;\n",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 480,
"y": 60,
"wires": [
[
"09da71d3b2b4254a"
]
]
},
{
"id": "09da71d3b2b4254a",
"type": "api-call-service",
"z": "ff8ced7818e0a1c1",
"name": "Ustaw jasność light.plate_backlight",
"server": "f8e3f945.af0568",
"version": 7,
"debugenabled": false,
"action": "light.turn_on",
"floorId": [],
"areaId": [],
"deviceId": [],
"entityId": [],
"labelId": [],
"data": "{\"entity_id\":\"light.plate_backlight\",\"brightness\":{{payload.brightness}}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"blockInputOverrides": false,
"domain": "light",
"service": "turn_on",
"x": 750,
"y": 60,
"wires": [
[]
]
},
{
"id": "f8e3f945.af0568",
"type": "server",
"name": "Home Assistant",
"addon": true
}
]
a to mój debug log z NR:
8 Mar 10:54:40 - [warn] [function:Ustaw jasność] Stan sun.sun: undefined
8 Mar 10:54:40 - [warn] [function:Ustaw jasność] Ustawiona jasność: 128
Co robię źle że nie otrzymuję stanów sun.sun “above_horizon” i “below_horizon”, tylko stan jest “undefined”?