Jen pro inspiraci vlastní řešení Ikea. Světlo v pracovně je o dvou žárovkách Ikea. Za vypínačem je shelly1 nastaveno na MQTT komunikaci, s trvale sepnutým relé, aby byla žárovka pod napětím. Takže Shelly jen posílá informaci o stavu vypínače. Ikea je integrovaná pomocí zigbee2mqtt, mezi ovladačem a žárovkou není žádná vazba. O vše se stará node-red. Vypínač a zigbee ovladač se chovají jako zapojení typu 6.
Kód:
[
{
"id": "69e2235f.5b2b3c",
"type": "tab",
"label": "Ikea",
"disabled": false,
"info": ""
},
{
"id": "9d8954a6.331108",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Přepínač výstupu",
"func": "if(msg.payload.action == \"toggle\" || msg.payload == \"toggle\") {\n\nif(context.flow.stav === false){\n msg.payload = true; \n}else{\n msg.payload = false;\n}\ncontext.flow.stav = msg.payload;\n}\nvar newMsg = { payload: context.flow.stav };\nreturn [newMsg];",
"outputs": 1,
"noerr": 0,
"x": 770,
"y": 240,
"wires": [
[
"49f0bc08.f0f804",
"7cef1b26.4fc364"
]
]
},
{
"id": "b60c1685.182ab8",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Stav světla",
"func": "context.flow.stav = msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 854,
"y": 440,
"wires": [
[
"36734ab6.e026f6"
]
]
},
{
"id": "4df170cd.9a5c9",
"type": "inject",
"z": "69e2235f.5b2b3c",
"name": "První spuštění",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "",
"topic": "firsboot",
"payload": "false",
"payloadType": "bool",
"x": 360,
"y": 820,
"wires": [
[
"60109daa.a47d74",
"161a7e28.569072"
]
]
},
{
"id": "a8d620a6.ad9fe",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Status",
"func": "if(msg.payload.state == \"ON\") {\n \n msg.payload = true; \n \n}\n\nelse{\n \n msg.payload = false;\n \n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 711,
"y": 440,
"wires": [
[
"b60c1685.182ab8",
"83e5a4a.23aef58"
]
]
},
{
"id": "e53bce00.549dd",
"type": "comment",
"z": "69e2235f.5b2b3c",
"name": "Světlo Pracovna",
"info": "",
"x": 341,
"y": 189,
"wires": []
},
{
"id": "49f0bc08.f0f804",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "topic",
"func": "var topic = \"vstup\";\nvar newMsg = { payload: msg.payload,topic };\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 969,
"y": 294,
"wires": [
[
"5b7a8dcc.a0b984"
]
]
},
{
"id": "f77474b7.872d18",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "topic",
"func": "var topic = \"vystup\";\nvar newMsg = { payload: msg.payload,topic };\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 967,
"y": 242,
"wires": [
[
"5b7a8dcc.a0b984"
]
]
},
{
"id": "5b7a8dcc.a0b984",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "porovnání",
"func": "if (msg.topic == \"vstup\") {\n\tcontext.state1 = msg.payload;\n }\nif (msg.topic == \"vystup\") {\n\tcontext.state2 = msg.payload;\n }\nif (context.state1 == context.state2) {\n\nmsg.topic = \"shoda\";\n }\nelse if (context.state2 === false && context.state1 === undefined ) {\n\nmsg.topic = \"chyba\";\nmsg.payload = false;\nreturn [null,msg];\n }\nelse if (context.state2 === true && context.state1 === undefined ) {\n\nmsg.topic = \"chyba\";\nmsg.payload = true;\nreturn [null,msg];\n }\nelse {\n msg.topic = \"neshoda\"; \n msg.payload = context.state1;\n }\nreturn msg;",
"outputs": 2,
"noerr": 0,
"x": 1159.5,
"y": 294,
"wires": [
[
"60109daa.a47d74"
],
[]
]
},
{
"id": "69a2f56.226640c",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Ikea žárovka",
"topic": "zigbee2mqtt/0x000d6ffffe5b1fd6",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 330,
"y": 440,
"wires": [
[
"a04cbf14.f0df8"
]
]
},
{
"id": "601fc87c.9e6858",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "převod výstupu pro Ikea",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "true",
"fromt": "bool",
"to": "{\"state\":\"ON\"}",
"tot": "json"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "false",
"fromt": "bool",
"to": "{\"state\":\"OFF\"}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1650,
"y": 296,
"wires": [
[
"4a1bf459.f2245c"
]
],
"inputLabels": [
"true/false"
],
"outputLabels": [
"ON/OFF"
]
},
{
"id": "4a1bf459.f2245c",
"type": "mqtt out",
"z": "69e2235f.5b2b3c",
"name": "Pracovna žárovka 1",
"topic": "zigbee2mqtt/0x000d6ffffe5b1fd6/set",
"qos": "0",
"retain": "true",
"broker": "6d608c46.1fd3b4",
"x": 1920,
"y": 296,
"wires": []
},
{
"id": "a04cbf14.f0df8",
"type": "json",
"z": "69e2235f.5b2b3c",
"name": "překlad na JSON",
"property": "payload",
"action": "",
"pretty": false,
"x": 548,
"y": 440,
"wires": [
[
"a8d620a6.ad9fe",
"a3b7a1f8.50369",
"187cb59b.dfe9aa"
]
]
},
{
"id": "fdc1cc2f.3022f",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Ovladač Pracovna",
"topic": "zigbee2mqtt/0x000d6ffffe54f777",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 350,
"y": 600,
"wires": [
[
"726fa62e.a37ea8"
]
]
},
{
"id": "11e37099.ca773f",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Přepínač výstupu",
"func": "if(msg.payload.action == \"toggle\" || msg.payload == \"toggle\") {\n\nif(context.flow.stav1 === false){\n msg.payload = true; \n}else{\n msg.payload = false;\n}\ncontext.flow.stav1 = msg.payload;\n}\nvar newMsg = { payload: context.flow.stav1 };\nreturn [newMsg];",
"outputs": 1,
"noerr": 0,
"x": 810,
"y": 840,
"wires": [
[
"6b601613.1686a8",
"abfc6a1f.26bca8"
]
]
},
{
"id": "74861331.d52d0c",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Stav světla",
"func": "context.flow.stav1 = msg.payload;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 853,
"y": 1040,
"wires": [
[
"1cc8a3d4.3f0d2c"
]
]
},
{
"id": "726fa62e.a37ea8",
"type": "json",
"z": "69e2235f.5b2b3c",
"name": "překlad na JSON",
"property": "payload",
"action": "",
"pretty": false,
"x": 550,
"y": 600,
"wires": [
[
"9cf4518f.9563a"
]
]
},
{
"id": "e1c131ce.6f4e4",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Status",
"func": "if(msg.payload.state == \"ON\") {\n \n msg.payload = true; \n \n}\n\nelse{\n \n msg.payload = false;\n \n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 710,
"y": 1040,
"wires": [
[
"74861331.d52d0c",
"a021be.9bc46e4"
]
]
},
{
"id": "2b310b72.1479e4",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Shelly SW",
"topic": "shellies/shelly1-93EF36/input/0",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 316,
"y": 680,
"wires": [
[
"4911df08.79efb"
]
]
},
{
"id": "4911df08.79efb",
"type": "json",
"z": "69e2235f.5b2b3c",
"name": "překlad na JSON",
"property": "payload",
"action": "",
"pretty": false,
"x": 370,
"y": 760,
"wires": [
[
"8b6022c6.f3ce7"
]
]
},
{
"id": "6b601613.1686a8",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "topic",
"func": "var topic = \"vstup\";\nvar newMsg = { payload: msg.payload,topic };\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 989,
"y": 894,
"wires": [
[
"c081c0f.a2ce34"
]
]
},
{
"id": "603f6485.3d39fc",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "topic",
"func": "var topic = \"vystup\";\nvar newMsg = { payload: msg.payload,topic };\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 987,
"y": 842,
"wires": [
[
"c081c0f.a2ce34"
]
]
},
{
"id": "c081c0f.a2ce34",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "porovnání",
"func": "if (msg.topic == \"vstup\") {\n\tcontext.state1 = msg.payload;\n }\nif (msg.topic == \"vystup\") {\n\tcontext.state2 = msg.payload;\n }\nif (context.state1 == context.state2) {\n\nmsg.topic = \"shoda\";\n }\nelse if (context.state2 === false && context.state1 === undefined ) {\n\nmsg.topic = \"chyba\";\nmsg.payload = false;\nreturn [null,msg];\n }\nelse if (context.state2 === true && context.state1 === undefined ) {\n\nmsg.topic = \"chyba\";\nmsg.payload = true;\nreturn [null,msg];\n }\nelse {\n msg.topic = \"neshoda\"; \n msg.payload = context.state1;\n }\nreturn msg;",
"outputs": 2,
"noerr": 0,
"x": 1179.5,
"y": 894,
"wires": [
[
"161a7e28.569072"
],
[]
]
},
{
"id": "793c3e2a.9da53",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Ikea žárovka",
"topic": "zigbee2mqtt/0x000d6ffffe60a88a",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 335,
"y": 1040,
"wires": [
[
"944ca29d.5187d"
]
]
},
{
"id": "1346eccd.d2a1e3",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "převod výstupu pro Ikea",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "true",
"fromt": "bool",
"to": "{\"state\":\"ON\"}",
"tot": "json"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "false",
"fromt": "bool",
"to": "{\"state\":\"OFF\"}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1689,
"y": 896,
"wires": [
[
"c978c946.3ae468"
]
],
"inputLabels": [
"true/false"
],
"outputLabels": [
"ON/OFF"
]
},
{
"id": "c978c946.3ae468",
"type": "mqtt out",
"z": "69e2235f.5b2b3c",
"name": "Pracovna žárovka 2",
"topic": "zigbee2mqtt/0x000d6ffffe60a88a/set",
"qos": "0",
"retain": "true",
"broker": "6d608c46.1fd3b4",
"x": 1937,
"y": 896,
"wires": []
},
{
"id": "944ca29d.5187d",
"type": "json",
"z": "69e2235f.5b2b3c",
"name": "překlad na JSON",
"property": "payload",
"action": "",
"pretty": false,
"x": 526,
"y": 1040,
"wires": [
[
"e1c131ce.6f4e4",
"b99c8144.7d614",
"e3e9cd67.a03ef"
]
]
},
{
"id": "2d05cce1.360d34",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Shelly relé",
"topic": "shellies/shelly1-93EF36/relay/0",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 325,
"y": 1100,
"wires": [
[
"7fa03ff8.1644b"
]
]
},
{
"id": "aa5d5c26.7e808",
"type": "mqtt in",
"z": "69e2235f.5b2b3c",
"name": "Shelly SW",
"topic": "shellies/shelly1-93EF36/input/0",
"qos": "0",
"datatype": "auto",
"broker": "6d608c46.1fd3b4",
"x": 325,
"y": 1160,
"wires": [
[
"1d84867b.c2b18a"
]
]
},
{
"id": "4ba54f9a.af946",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "změna",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "on",
"fromt": "str",
"to": "1",
"tot": "num"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "off",
"fromt": "str",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "rele",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 701,
"y": 1100,
"wires": [
[
"879daccd.44018"
]
]
},
{
"id": "879daccd.44018",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "porovnání",
"func": "if (msg.topic == \"rele\") \n {\n\tcontext.state1 = msg.payload;\n }\nif (msg.topic == \"tlacitko\") \n {\n\tcontext.state2 = msg.payload;\n }\nif (context.state2 == 1 ) \n { \n if (context.state1 != context.state2) \n {\n var newMsg = {payload: context.state2}\n }\n }\nreturn newMsg;",
"outputs": 1,
"noerr": 0,
"x": 862,
"y": 1132,
"wires": [
[
"f80fd734.5eaf78"
]
]
},
{
"id": "456f991.d8a2f68",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "změna",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "tlacitko",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 697,
"y": 1160,
"wires": [
[
"879daccd.44018"
]
]
},
{
"id": "e55696cd.55ae48",
"type": "mqtt out",
"z": "69e2235f.5b2b3c",
"name": "Shelly relé",
"topic": "shellies/shelly1-93EF36/relay/0/command",
"qos": "0",
"retain": "true",
"broker": "6d608c46.1fd3b4",
"x": 1276,
"y": 1132,
"wires": []
},
{
"id": "7fa03ff8.1644b",
"type": "rbe",
"z": "69e2235f.5b2b3c",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 488,
"y": 1100,
"wires": [
[
"4ba54f9a.af946"
]
]
},
{
"id": "1d84867b.c2b18a",
"type": "rbe",
"z": "69e2235f.5b2b3c",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 488,
"y": 1160,
"wires": [
[
"456f991.d8a2f68",
"d87a7fe5.aa8d2"
]
]
},
{
"id": "f80fd734.5eaf78",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "převod výstupu pro Shelly",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "1",
"fromt": "num",
"to": "on",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1061,
"y": 1132,
"wires": [
[
"e55696cd.55ae48"
]
],
"inputLabels": [
"true/false"
],
"outputLabels": [
"ON/OFF"
]
},
{
"id": "b95f70b9.ef46a",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "změna",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "1",
"fromt": "num",
"to": "ON",
"tot": "str"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "0",
"fromt": "num",
"to": "OFF",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1462,
"y": 666,
"wires": [
[
"4a1bf459.f2245c",
"c978c946.3ae468"
]
]
},
{
"id": "e2322746.e30e68",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "změna",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "true",
"fromt": "bool",
"to": "ON",
"tot": "str"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "false",
"fromt": "bool",
"to": "OFF",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1462,
"y": 440,
"wires": [
[
"4a1bf459.f2245c"
]
]
},
{
"id": "9cf4518f.9563a",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Ovladač Ikea",
"func": "var trideni = msg.payload.action;\n\nif (trideni == \"toggle\"){return [msg, null, null, null, null, null, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"toggle_hold\"){return [null, msg, null, null, null, null, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_up_click\"){return [null, null, msg, null, null, null, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_up_hold\"){return [null, null, null, msg, null, null, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_up_release\"){return [null, null, null, null, msg, null, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_down_click\"){return [null, null, null, null, null, msg, null, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_down_hold\"){return [null, null, null, null, null, null, msg, null, null, null, null, null, null, null, null];}\n\nif (trideni == \"brightness_down_release\"){return [null, null, null, null, null, null, null, msg, null, null, null, null, null, null, null];}\n\nif (trideni == \"arrow_right_click\"){return [null, null, null, null, null, null, null, null, msg, null, null, null, null, null, null];}\n\nif (trideni == \"arrow_right_hold\"){return [null, null, null, null, null, null, null, null, null, msg, null, null, null, null, null];}\n\nif (trideni == \"arrow_right_release\"){return [null, null, null, null, null, null, null, null, null, null, msg, null, null, null, null];}\n\nif (trideni == \"arrow_left_click\"){return [null, null, null, null, null, null, null, null, null, null, null, msg, null, null, null];}\n\nif (trideni == \"arrow_left_hold\"){return [null, null, null, null, null, null, null, null, null, null, null, null, msg, null, null];}\n\nif (trideni == \"arrow_left_release\"){return [null, null, null, null, null, null, null, null, null, null, null, null, null, msg, null];}\n\nif (trideni === \"\"){return [null, null, null, null, null, null, null, null, null, null, null, null, null, null, msg];}",
"outputs": 15,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 730,
"y": 600,
"wires": [
[
"9d8954a6.331108",
"11e37099.ca773f"
],
[
"50da7ac8.55f194"
],
[
"c4ba2b75.340bc8",
"b83053be.c3a4d"
],
[
"652956c9.a5e038"
],
[
"652956c9.a5e038"
],
[
"c4ba2b75.340bc8",
"b83053be.c3a4d"
],
[
"652956c9.a5e038"
],
[
"652956c9.a5e038"
],
[
"1c00fdac.2551e2",
"48574499.0dc5dc"
],
[
"aff957.219a96a8"
],
[
"aff957.219a96a8"
],
[
"1c00fdac.2551e2",
"48574499.0dc5dc"
],
[
"aff957.219a96a8"
],
[
"aff957.219a96a8"
],
[]
],
"icon": "node-red-contrib-time-range-switch/switch.png"
},
{
"id": "c4ba2b75.340bc8",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "jas krok",
"func": " var x = 50;\n var jas = flow.get(\"pracovna1_jas\");\nif(msg.payload.action == \"brightness_up_click\") {\n \n var jas_out = (jas + x);\n if(jas_out >= 255) {jas_out = 255;}\n msg.payload = {\"brightness\": jas_out}\n return msg;\n}\n\nif(msg.payload.action == \"brightness_down_click\") {\n \n var jas_out = (jas - x);\n if(jas_out <= 5) {jas_out = 5;}\n msg.payload = {\"brightness\": jas_out}\n return msg;\n}\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1000,
"y": 619,
"wires": [
[
"d650268c.9f9748"
]
]
},
{
"id": "a3b7a1f8.50369",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "paměť jas",
"func": "var jas = msg.payload.brightness;\n flow.set(\"pracovna1_jas\", jas);\n return msg;",
"outputs": 1,
"noerr": 0,
"x": 678,
"y": 392,
"wires": [
[]
]
},
{
"id": "b83053be.c3a4d",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "jas krok",
"func": " var x = 50;\n var jas = flow.get(\"pracovna2_jas\");\nif(msg.payload.action == \"brightness_up_click\") {\n \n var jas_out = (jas + x);\n if(jas_out >= 255) {jas_out = 255;}\n msg.payload = {\"brightness\": jas_out}\n return msg;\n}\n\nif(msg.payload.action == \"brightness_down_click\") {\n \n var jas_out = (jas - x);\n if(jas_out <= 5) {jas_out = 5;}\n msg.payload = {\"brightness\": jas_out}\n return msg;\n}\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1000,
"y": 660,
"wires": [
[
"c9001183.73dc6"
]
]
},
{
"id": "b99c8144.7d614",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "paměť jas",
"func": "var jas = msg.payload.brightness;\n flow.set(\"pracovna2_jas\", jas);\n return msg;",
"outputs": 1,
"noerr": 0,
"x": 679,
"y": 995,
"wires": [
[]
]
},
{
"id": "652956c9.a5e038",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "jas plynule tlačítko",
"func": "var step = 10;\n\n if(msg.payload.action === \"brightness_up_hold\"){\n flow.set(\"incrementvalue1\",step)\n }\n else if(msg.payload.action === \"brightness_up_release\"){\n flow.set(\"incrementvalue1\",0)\n }\n \n if(msg.payload.action === \"brightness_down_hold\"){\n flow.set(\"incrementvalue1\",step * -1)\n }\n else if(msg.payload.action === \"brightness_down_release\"){\n flow.set(\"incrementvalue1\",0)\n } \nreturn msg\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1030,
"y": 570,
"wires": [
[]
]
},
{
"id": "979ada96.c72bd8",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "jas plynule hodnota",
"func": "var iv = flow.get(\"incrementvalue1\") || 0;\nif(iv === 0){\n return null\n}\nvar dimmer = flow.get(\"pracovna1_jas\") || 0;\ndimmer += iv;\nif(dimmer >= 255){\n dimmer = 255;\n}\nif(dimmer <= 5){\n dimmer = 5;\n}\n\nflow.set(\"pracovna1_jas\",dimmer)\n\nmsg.payload = {\"brightness\": dimmer}\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 1423,
"y": 492,
"wires": [
[
"d650268c.9f9748"
]
]
},
{
"id": "6a910130.db572",
"type": "inject",
"z": "69e2235f.5b2b3c",
"name": "0.25s",
"repeat": ".25",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 1210,
"y": 493,
"wires": [
[
"979ada96.c72bd8",
"fafb9c0f.e576c",
"7cc2ef3f.8c926",
"4fcbea67.fdb854"
]
]
},
{
"id": "fafb9c0f.e576c",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "jas plynule hodnota",
"func": "var iv = flow.get(\"incrementvalue1\") || 0;\nif(iv === 0){\n return null\n}\nvar dimmer = flow.get(\"pracovna2_jas\") || 0;\ndimmer += iv;\nif(dimmer >= 255){\n dimmer = 255;\n}\nif(dimmer <= 5){\n dimmer = 5;\n}\n\nflow.set(\"pracovna2_jas\",dimmer)\n\nmsg.payload = {\"brightness\": dimmer}\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 1423,
"y": 560,
"wires": [
[
"c9001183.73dc6"
]
]
},
{
"id": "d650268c.9f9748",
"type": "switch",
"z": "69e2235f.5b2b3c",
"name": "ON",
"property": "stav_pracovna1",
"propertyType": "flow",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1459,
"y": 393,
"wires": [
[
"4a1bf459.f2245c"
]
]
},
{
"id": "83e5a4a.23aef58",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "ON/OFF",
"rules": [
{
"t": "set",
"p": "stav_pracovna1",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 864,
"y": 393,
"wires": [
[]
]
},
{
"id": "a021be.9bc46e4",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "ON/OFF",
"rules": [
{
"t": "set",
"p": "stav_pracovna2",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 863,
"y": 987,
"wires": [
[]
]
},
{
"id": "c9001183.73dc6",
"type": "switch",
"z": "69e2235f.5b2b3c",
"name": "ON",
"property": "stav_pracovna2",
"propertyType": "flow",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 1464,
"y": 716,
"wires": [
[
"c978c946.3ae468"
]
]
},
{
"id": "1c00fdac.2551e2",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "barva krok",
"func": " var x = 50;\n var barva = flow.get(\"pracovna1_barva\");\nif(msg.payload.action == \"arrow_right_click\") {\n \n var barva_out = (barva + x);\n if(barva_out >= 500) {barva_out = 500;}\n if(barva_out == 500) {barva_out = 153;}\n msg.payload = {\"color_temp\": barva_out}\n return msg;\n}\n\nif(msg.payload.action == \"arrow_left_click\") {\n \n var barva_out = (barva - x);\n if(barva_out <= 153) {barva_out = 153;}\n if(barva_out == 153) {barva_out = 500;}\n msg.payload = {\"color_temp\": barva_out}\n return msg;\n}\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1010,
"y": 703,
"wires": [
[
"d650268c.9f9748"
]
]
},
{
"id": "187cb59b.dfe9aa",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "paměť barva",
"func": "var barva = msg.payload.color_temp;\n flow.set(\"pracovna1_barva\", barva);\n return msg;",
"outputs": 1,
"noerr": 0,
"x": 674,
"y": 348,
"wires": [
[]
]
},
{
"id": "48574499.0dc5dc",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "barva krok",
"func": " var x = 50;\n var barva = flow.get(\"pracovna2_barva\");\nif(msg.payload.action == \"arrow_right_click\") {\n \n var barva_out = (barva + x);\n if(barva_out >= 500) {barva_out = 500;}\n if(barva_out == 500) {barva_out = 153;}\n msg.payload = {\"color_temp\": barva_out}\n return msg;\n}\n\nif(msg.payload.action == \"arrow_left_click\") {\n \n var barva_out = (barva - x);\n if(barva_out <= 153) {barva_out = 153;}\n if(barva_out == 153) {barva_out = 500;}\n msg.payload = {\"color_temp\": barva_out}\n return msg;\n}\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1010,
"y": 747,
"wires": [
[
"c9001183.73dc6"
]
]
},
{
"id": "e3e9cd67.a03ef",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "paměť barva",
"func": "var barva = msg.payload.color_temp;\n flow.set(\"pracovna2_barva\", barva);\n return msg;",
"outputs": 1,
"noerr": 0,
"x": 668,
"y": 955,
"wires": [
[]
]
},
{
"id": "aff957.219a96a8",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "barva plynule tlačítko",
"func": "var step = 20;\n\n if(msg.payload.action === \"arrow_right_hold\"){\n flow.set(\"incrementvalue2\",step)\n }\n else if(msg.payload.action === \"arrow_right_release\"){\n flow.set(\"incrementvalue2\",0)\n }\n \n if(msg.payload.action === \"arrow_left_hold\"){\n flow.set(\"incrementvalue2\",step * -1)\n }\n else if(msg.payload.action === \"arrow_left_release\"){\n flow.set(\"incrementvalue2\",0)\n } \nreturn msg\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 1035,
"y": 794,
"wires": [
[]
]
},
{
"id": "7cc2ef3f.8c926",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "barva plynule hodnota",
"func": "var iv = flow.get(\"incrementvalue2\") || 0;\nif(iv === 0){\n return null\n}\nvar dimmer = flow.get(\"pracovna1_barva\") || 0;\ndimmer += iv;\nif(dimmer >= 500){dimmer = 500;}\nif(dimmer == 500){dimmer = 153;}\nif(dimmer <= 153){dimmer = 153;}\n\nflow.set(\"pracovna1_barva\",dimmer)\n\nmsg.payload = {\"color_temp\": dimmer}\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 1434,
"y": 767,
"wires": [
[
"d650268c.9f9748"
]
]
},
{
"id": "4fcbea67.fdb854",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "barva plynule hodnota",
"func": "var iv = flow.get(\"incrementvalue2\") || 0;\nif(iv === 0){\n return null\n}\nvar dimmer = flow.get(\"pracovna2_barva\") || 0;\ndimmer += iv;\nif(dimmer >= 500){dimmer = 500;}\nif(dimmer == 500){dimmer = 153;}\nif(dimmer <= 153){dimmer = 153;}\n\nflow.set(\"pracovna2_barva\",dimmer)\n\nmsg.payload = {\"color_temp\": dimmer}\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 1437,
"y": 836,
"wires": [
[
"c9001183.73dc6"
]
]
},
{
"id": "50da7ac8.55f194",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "default",
"func": " var barva = 153;\n var jas = 255;\nif(msg.payload.action == \"toggle_hold\") {\n\n msg.payload = {\"brightness\": jas, \"color_temp\": barva}\n return msg;\n}\n\n\n\n \n\n",
"outputs": 1,
"noerr": 0,
"x": 990,
"y": 524,
"wires": [
[
"d650268c.9f9748",
"c9001183.73dc6"
]
]
},
{
"id": "b885bb4f.6fc328",
"type": "function",
"z": "69e2235f.5b2b3c",
"name": "Status",
"func": "if(msg.payload.state == 1) {\n \n msg.payload = \"toggle\"; \n}\nelse {\n msg.payload = \"toggle\";\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 590,
"y": 660,
"wires": [
[
"9d8954a6.331108",
"11e37099.ca773f"
]
]
},
{
"id": "8b6022c6.f3ce7",
"type": "rbe",
"z": "69e2235f.5b2b3c",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"property": "payload",
"x": 544,
"y": 760,
"wires": [
[
"b885bb4f.6fc328"
]
]
},
{
"id": "84d5a16e.db6cc",
"type": "inject",
"z": "69e2235f.5b2b3c",
"name": "První spuštění",
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "",
"topic": "firsboot",
"payload": "{\"state\":\"OFF\"}",
"payloadType": "json",
"x": 1740,
"y": 580,
"wires": [
[
"4a1bf459.f2245c",
"c978c946.3ae468"
]
]
},
{
"id": "71b092fc.987cbc",
"type": "change",
"z": "69e2235f.5b2b3c",
"name": "změna",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "1",
"fromt": "num",
"to": "ON",
"tot": "str"
},
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": "0",
"fromt": "num",
"to": "OFF",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1482,
"y": 960,
"wires": [
[
"c978c946.3ae468"
]
]
},
{
"id": "1cc8a3d4.3f0d2c",
"type": "trigger",
"z": "69e2235f.5b2b3c",
"name": "10s",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "pay",
"duration": "-10",
"extend": true,
"units": "s",
"reset": "",
"bytopic": "all",
"outputs": 1,
"x": 1010,
"y": 1040,
"wires": [
[
"603f6485.3d39fc"
]
]
},
{
"id": "36734ab6.e026f6",
"type": "trigger",
"z": "69e2235f.5b2b3c",
"name": "10s",
"op1": "",
"op2": "",
"op1type": "pay",
"op2type": "pay",
"duration": "-10",
"extend": true,
"units": "s",
"reset": "",
"bytopic": "all",
"outputs": 1,
"x": 1010,
"y": 440,
"wires": [
[
"f77474b7.872d18"
]
]
},
{
"id": "d87a7fe5.aa8d2",
"type": "api-call-service",
"z": "69e2235f.5b2b3c",
"name": "hassio pracovna",
"server": "67e633d.daebecc",
"service_domain": "input_boolean",
"service": "turn_off",
"data": "",
"mergecontext": "",
"x": 1180,
"y": 666,
"wires": [
[
"b95f70b9.ef46a"
]
]
},
{
"id": "7cef1b26.4fc364",
"type": "api-call-service",
"z": "69e2235f.5b2b3c",
"name": "hassio pracovna",
"server": "67e633d.daebecc",
"service_domain": "input_boolean",
"service": "turn_off",
"data": "",
"mergecontext": "",
"x": 1180,
"y": 440,
"wires": [
[
"e2322746.e30e68"
]
]
},
{
"id": "abfc6a1f.26bca8",
"type": "api-call-service",
"z": "69e2235f.5b2b3c",
"name": "hassio pracovna",
"server": "67e633d.daebecc",
"service_domain": "input_boolean",
"service": "turn_off",
"data": "",
"mergecontext": "",
"x": 1200,
"y": 960,
"wires": [
[
"71b092fc.987cbc"
]
]
},
{
"id": "d0ae340f.a9aee8",
"type": "api-current-state",
"z": "69e2235f.5b2b3c",
"name": "hassio",
"server": "67e633d.daebecc",
"outputs": 2,
"halt_if": "on",
"override_topic": false,
"entity_id": "input_boolean.svetlo_pracovna",
"override_payload": "none",
"x": 1490,
"y": 896,
"wires": [
[],
[
"1346eccd.d2a1e3"
]
]
},
{
"id": "65bcb43e.77f2ac",
"type": "api-current-state",
"z": "69e2235f.5b2b3c",
"name": "hassio",
"server": "67e633d.daebecc",
"outputs": 2,
"halt_if": "on",
"override_topic": false,
"entity_id": "input_boolean.svetlo_pracovna",
"override_payload": "none",
"x": 1450,
"y": 296,
"wires": [
[],
[
"601fc87c.9e6858"
]
]
},
{
"id": "60109daa.a47d74",
"type": "traffic",
"z": "69e2235f.5b2b3c",
"name": "SR",
"property_allow": "topic",
"filter_allow": "neshoda",
"ignore_case_allow": false,
"negate_allow": false,
"send_allow": true,
"property_stop": "topic",
"filter_stop": "shoda",
"ignore_case_stop": false,
"negate_stop": false,
"send_stop": false,
"default_start": false,
"differ": false,
"x": 1329,
"y": 296,
"wires": [
[
"65bcb43e.77f2ac"
]
]
},
{
"id": "161a7e28.569072",
"type": "traffic",
"z": "69e2235f.5b2b3c",
"name": "SR",
"property_allow": "topic",
"filter_allow": "neshoda",
"ignore_case_allow": false,
"negate_allow": false,
"send_allow": true,
"property_stop": "topic",
"filter_stop": "shoda",
"ignore_case_stop": false,
"negate_stop": false,
"send_stop": false,
"default_start": false,
"differ": false,
"x": 1349,
"y": 896,
"wires": [
[
"d0ae340f.a9aee8"
]
]
},
{
"id": "6d608c46.1fd3b4",
"type": "mqtt-broker",
"z": "",
"name": "MOSQUITTO",
"broker": "",
"port": "",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]
jelikož máš z dimmeru pouze dva stavy, tak bych se zaměřil na vlastní generování "dimming"
Řešení máš ve výše uvedeném příkladu, kde si budeš muset jako první spolehlivě odfiltorvat 0 a 255, takže informaci zda zvyšuješ, nebo snižuješ jas. U Ikea řešení je tohle řešeno funkcí: