Thank you all for your help. I think I am nearly there, but the function node has an error - 'function tried to send a message of type string'.
Couldn't get my head around how to make it work with switch nodes.
[
{
"id": "d58a0e9fb6feb9d6",
"type": "tab",
"label": "Flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "b5c3e425c9bc66fc",
"type": "function",
"z": "d58a0e9fb6feb9d6",
"name": "",
"func": "let h = msg.payload.col1\nlet r = msg.payload.raspberry\nlet l = msg.payload.light\n\nif (l==0){\nif (h <= 63) msg.payload = \"on\";\nif (h >63) msg.payload = \"off\";\n}\n\nif (l==1){\nif (r == 0)\nreturn [msg.payload = \"on\"]\nif (r == 1)\nreturn [msg.payload = \"off\"]\n}\n\nreturn msg;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 780,
"wires": [
[
"a6575cbf05985683",
"f27e8e3d8502edd8"
]
]
},
{
"id": "a6575cbf05985683",
"type": "Sonoff device Enhanced",
"z": "d58a0e9fb6feb9d6",
"mode": "0",
"broker": "618e5d5400c6168e",
"device": "dry",
"name": "H",
"onValue": "ON",
"offValue": "OFF",
"toggleValue": "toggle",
"cmdPrefix": "cmnd",
"statPrefix": "stat",
"telePrefix": "tele",
"x": 730,
"y": 780,
"wires": [
[]
]
},
{
"id": "a01f4f92316c5cb0",
"type": "Sonoff device Enhanced",
"z": "d58a0e9fb6feb9d6",
"mode": "0",
"broker": "618e5d5400c6168e",
"device": "hum",
"name": "D",
"onValue": "ON",
"offValue": "OFF",
"toggleValue": "toggle",
"cmdPrefix": "cmnd",
"statPrefix": "stat",
"telePrefix": "tele",
"x": 730,
"y": 840,
"wires": [
[]
]
},
{
"id": "8c365de7bc347d93",
"type": "inject",
"z": "d58a0e9fb6feb9d6",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "123/test",
"payload": "64",
"payloadType": "str",
"x": 180,
"y": 660,
"wires": [
[
"1f4de87ca2d02a18"
]
]
},
{
"id": "e51d38ab37b6ee27",
"type": "join",
"z": "d58a0e9fb6feb9d6",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": true,
"timeout": "",
"count": "3",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 350,
"y": 820,
"wires": [
[
"bec8151e84814f6a",
"9ba1419ecb1f5f99",
"b5c3e425c9bc66fc"
]
]
},
{
"id": "688d1bf943e84c4b",
"type": "inject",
"z": "d58a0e9fb6feb9d6",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "raspberry",
"payload": "1",
"payloadType": "num",
"x": 170,
"y": 780,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "79cda72e5db0ecdd",
"type": "inject",
"z": "d58a0e9fb6feb9d6",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "raspberry",
"payload": "0",
"payloadType": "num",
"x": 170,
"y": 820,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "bec8151e84814f6a",
"type": "debug",
"z": "d58a0e9fb6feb9d6",
"name": "debug 308",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 430,
"y": 900,
"wires": []
},
{
"id": "631b7a4ecf4d1a79",
"type": "mqtt in",
"z": "d58a0e9fb6feb9d6",
"name": "",
"topic": "123/test",
"qos": "2",
"datatype": "auto",
"broker": "618e5d5400c6168e",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 190,
"y": 600,
"wires": [
[]
]
},
{
"id": "b1071f7e377bab24",
"type": "function",
"z": "d58a0e9fb6feb9d6",
"name": "",
"func": "delete msg.payload.col2\ndelete msg.payload.col3\ndelete msg.payload.col4\ndelete msg.payload.col5\ndelete msg.payload.col6\ndelete msg.payload.col7\ndelete msg.payload.col8\ndelete msg.payload.col9\ndelete msg.payload.col10\ndelete msg.payload.col12\ndelete msg.payload.col13\ndelete msg.payload.col14\ndelete msg.payload.col15\ndelete msg.payload.col16\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 720,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "1f4de87ca2d02a18",
"type": "csv",
"z": "d58a0e9fb6feb9d6",
"name": "",
"sep": ",",
"hdrin": "",
"hdrout": "none",
"multi": "one",
"ret": "\\n",
"temp": "",
"skip": "0",
"strings": true,
"include_empty_strings": "",
"include_null_values": "",
"x": 370,
"y": 620,
"wires": [
[
"b1071f7e377bab24"
]
]
},
{
"id": "918e93aa6b4e4fcc",
"type": "cronplus",
"z": "d58a0e9fb6feb9d6",
"name": "",
"outputField": "payload",
"timeZone": "",
"persistDynamic": false,
"commandResponseMsgOutput": "output1",
"outputs": 1,
"options": [
{
"name": "schedule1",
"topic": "light",
"payloadType": "num",
"payload": "1",
"expressionType": "cron",
"expression": "0 00 09 * * * *",
"location": "",
"offset": "0",
"solarType": "all",
"solarEvents": "sunrise,sunset"
},
{
"name": "schedule2",
"topic": "light",
"payloadType": "num",
"payload": "0",
"expressionType": "cron",
"expression": "0 00 03 * * * *",
"location": "",
"offset": "0",
"solarType": "all",
"solarEvents": "sunrise,sunset"
}
],
"x": 160,
"y": 900,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "ec4bd2cfac87ace7",
"type": "mqtt in",
"z": "d58a0e9fb6feb9d6",
"name": "",
"topic": "raspberry",
"qos": "2",
"datatype": "json",
"broker": "f03eb60e5379e1a3",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 180,
"y": 720,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "e2989af89ef6c16d",
"type": "inject",
"z": "d58a0e9fb6feb9d6",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "light",
"payload": "1",
"payloadType": "num",
"x": 170,
"y": 960,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "82a86590ec234930",
"type": "inject",
"z": "d58a0e9fb6feb9d6",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "light",
"payload": "0",
"payloadType": "num",
"x": 170,
"y": 1000,
"wires": [
[
"e51d38ab37b6ee27"
]
]
},
{
"id": "3294594606d6817d",
"type": "switch",
"z": "d58a0e9fb6feb9d6",
"name": "",
"property": "topic",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "raspberry = 1",
"vt": "str"
},
{
"t": "eq",
"v": "raspberry = 0",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 450,
"y": 1060,
"wires": [
[],
[]
]
},
{
"id": "76280934705d17de",
"type": "debug",
"z": "d58a0e9fb6feb9d6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 690,
"y": 900,
"wires": []
},
{
"id": "9ba1419ecb1f5f99",
"type": "function",
"z": "d58a0e9fb6feb9d6",
"name": "",
"func": "let h = msg.payload.col1\nlet r = msg.payload.raspberry\nlet l = msg.payload.light\n\nif (l==0){\nif (h >= 65) msg.payload = \"on\";\nif (h <65) msg.payload = \"off\";\n}\n\nif (l==1){\nif (r == 1)\nreturn [msg.payload = \"on\"]\nif (r == 0)\nreturn [msg.payload = \"off\"]\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 840,
"wires": [
[
"76280934705d17de",
"a01f4f92316c5cb0"
]
]
},
{
"id": "f27e8e3d8502edd8",
"type": "debug",
"z": "d58a0e9fb6feb9d6",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 690,
"y": 720,
"wires": []
},
{
"id": "618e5d5400c6168e",
"type": "mqtt-broker",
"name": "Mosquitto",
"broker": "localhost",
"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": {},
"sessionExpiry": ""
},
{
"id": "f03eb60e5379e1a3",
"type": "mqtt-broker",
"name": "rasp1",
"broker": "192.168.0.59",
"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": {},
"sessionExpiry": ""
}
]