X
Forum

Forum

ZigBee - Xiaomi Aqa...
 
Notifications
Clear all

ZigBee - Xiaomi Aqara smart LED bulb

11 Posts
3 Users
0 Likes
3,273 Views
(@franta)
Trusted Member
Joined: 7 years ago
Posts: 67
Topic starter  

Ahoj,

rozcházím zigbee zařízení, teploměry, kostka, vše ok, ale nemohu přijít na to jak ovládat žárovku. Nemá někdo vyzkoušeno? Neposlal by jste mi vyexportovaný flow?

Díky

 


   
Quote
 L
(@l)
Famed Member Admin
Joined: 9 years ago
Posts: 3070
 

zalezi jakou zarovku, jake API nabizi, jesli je na ni napsany mqtt shepperd, jestli vlastne pouzivas zigbee2mqtt nebo jiny HW,...

chtelo by to dodat o dost vic info.


   
ReplyQuote
(@franta)
Trusted Member
Joined: 7 years ago
Posts: 67
Topic starter  

Mám žárovku Xiaomi Aqara smart LED bulb a šel jsem přesně podle tvého článku, takže USB Wireless Zigbee CC2531 Sniffer -> zigbee2mqtt -> nodered (na RPI).


   
ReplyQuote
 L
(@l)
Famed Member Admin
Joined: 9 years ago
Posts: 3070
 

Tim padem si musis zjistit, jake prikazy presne zarovka podporuje (tuhle vyzkousenou nemam). 

https://github.com/Koenkk/zigbee-shepherd-converters/blob/master/converters/toZigbee.js

https://github.com/Koenkk/zigbee-shepherd-converters/blob/master/devices.js

https://github.com/Koenkk/zigbee-shepherd-converters/blob/master/converters/fromZigbee.js

a podle toho pak udelat json objekt a ten poslat. Bohuzel, lepsi zpusob sem zatim nenasel.

ikea zarovka zere napriklad toto

ON: { "brightness": 255, "transition": 0}

OFF: { "state": "off"}

co je co je popsano taky v te dokumentaci


   
ReplyQuote
J_K
 J_K
(@j_k)
Active Member
Joined: 5 years ago
Posts: 5
 

Ahoj,

vložím se do diskuse, jelikož se to týká primárně mě 🙂

 

Již jsem přišel na to, co žárovce poslat. Základní problém byl v tom, že jsem nevěděl, že Zigbee Topicu se zapisuje pomocí /set. Takže nyní jsem schopen žárovku ovládat. I se mi podařilo v Node Red vytvořit tlačítko, které přímo posílá JSON řetězec ve správném formátu. Vypadá to takto:

[
{
"id": "ec3e0b17.24b098",
"type": "mqtt out",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "zigbee2mqtt/svetlo_1/set",
"qos": "",
"retain": "",
"broker": "2c7374d9.8a6c9c",
"x": 1430,
"y": 1000,
"wires": []
},
{
"id": "8e398436.fbb558",
"type": "ui_button",
"z": "b2e437b6.7f5e98",
"name": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "ON",
"tooltip": "",
"color": "",
"bgcolor": "green",
"icon": "",
"payload": "{\"state\":\"on\"}",
"payloadType": "json",
"topic": "",
"x": 1130,
"y": 800,
"wires": [
[
"ec3e0b17.24b098",
"1325867.1ec677a"
]
]
},
{
"id": "63dc3682.fb3038",
"type": "ui_button",
"z": "b2e437b6.7f5e98",
"name": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"label": "OFF",
"tooltip": "",
"color": "",
"bgcolor": "red",
"icon": "",
"payload": "{\"state\":\"off\"}",
"payloadType": "json",
"topic": "",
"x": 1130,
"y": 860,
"wires": [
[
"ec3e0b17.24b098"
]
]
},
{
"id": "1325867.1ec677a",
"type": "debug",
"z": "b2e437b6.7f5e98",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 1340,
"y": 800,
"wires": []
},
{
"id": "2c7374d9.8a6c9c",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "987fe6b8.7b5dd8",
"type": "ui_group",
"z": "",
"name": "Světla",
"tab": "a1fe1abd.ae8898",
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "a1fe1abd.ae8898",
"type": "ui_tab",
"z": "",
"name": "Světla",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]

Nicméně teď bych rád vyrobil např. Slider pro ovládání teploty bílé. Ručně jsem schopný odeslat do žárovky hodnotu. Nedaří se mi však v Node Red převést číslo do JSON stringu. Prosím o radu (ideálně export z Node Red), jak převést/vložit číslo, příp. jinou hodnotu do JSON. Děkuji.


   
ReplyQuote
 L
(@l)
Famed Member Admin
Joined: 9 years ago
Posts: 3070

   
ReplyQuote
J_K
 J_K
(@j_k)
Active Member
Joined: 5 years ago
Posts: 5
 

Tak nějak si nevím rady. Asi dělám něco blbě při extrakci hodnoty ze slideru. Do funkce přichází toto:

msg.payload : number

78

Nedaří se mi z toho vytáhnout hodnotu a tu nacpat do JSON řetezce, který bych chtěl dál poslat do MQTT. Ručně mi to jde, když pošlu Inject nodem toto:

{"brightness":100}

Poradil by někdo, jak převést výše uvedený výstup ze slideru na tento řetezec? Díky.


   
ReplyQuote
 L
(@l)
Famed Member Admin
Joined: 9 years ago
Posts: 3070
 

toto jsi cetl? https://www.vodnici.net/wiki/zigbee2mqtt-nodered-a-loxone/

je tam presne vysvetleno jak hodnoty extrahovat a jak z nich vytvorit pak dalsi data


   
ReplyQuote
J_K
 J_K
(@j_k)
Active Member
Joined: 5 years ago
Posts: 5
 

Četl, ale bohužel z toho nejsem moc moudrý...


   
ReplyQuote
J_K
 J_K
(@j_k)
Active Member
Joined: 5 years ago
Posts: 5
 

Ráno moudřejší večera... Už mi to funguje. Nevím, kde jsem před tím dělal chybu. Díky.


   
ReplyQuote
J_K
 J_K
(@j_k)
Active Member
Joined: 5 years ago
Posts: 5
 

Pokud by někoho zajímalo, jak jsem nakonec vyřešil ovládání žárovky pomocí Aqara Cube, přikládám export flow:

[
{
"id": "b2e437b6.7f5e98",
"type": "tab",
"label": "Světla",
"disabled": false,
"info": ""
},
{
"id": "b93c2f79.9832a",
"type": "mqtt in",
"z": "b2e437b6.7f5e98",
"name": "CUBE",
"topic": "zigbee2mqtt/CUBE",
"qos": "2",
"broker": "2c7374d9.8a6c9c",
"x": 150,
"y": 100,
"wires": [
[
"e38301a3.b84b6"
]
]
},
{
"id": "e38301a3.b84b6",
"type": "json",
"z": "b2e437b6.7f5e98",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 290,
"y": 200,
"wires": [
[
"f87f3cf2.9933a",
"20e27d21.2be632"
]
]
},
{
"id": "32ea7fb5.1d8fd",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"brightness\":1}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 260,
"y": 940,
"wires": [
[]
]
},
{
"id": "e3d4ad09.7f361",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"color_temp\":500}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 590,
"y": 1240,
"wires": [
[]
]
},
{
"id": "c08091f5.93f01",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"state\":\"off\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 250,
"y": 1080,
"wires": [
[]
]
},
{
"id": "30129d02.4051f2",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"state\":\"on\"}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 250,
"y": 1120,
"wires": [
[]
]
},
{
"id": "723af94a.3b4d18",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"color_temp\":200}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 590,
"y": 1180,
"wires": [
[]
]
},
{
"id": "61098b2f.0df7c4",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"brightness\":100}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 980,
"wires": [
[]
]
},
{
"id": "6a4f996d.15ee88",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"brightness\":255}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 270,
"y": 1020,
"wires": [
[]
]
},
{
"id": "1d5d2f18.2af671",
"type": "ui_slider",
"z": "b2e437b6.7f5e98",
"name": "",
"label": "Úroveň jasu",
"tooltip": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"outs": "end",
"topic": "",
"min": "1",
"max": "255",
"step": 1,
"x": 970,
"y": 240,
"wires": [
[
"8a06d6a1.299558"
]
]
},
{
"id": "8a06d6a1.299558",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "to-MQTT_brightness",
"func": "\nvar value = String(msg.payload);\n \n//preapre MQTT command\nmsg.payload = {};\nmsg.payload.brightness = value;\n \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1200,
"y": 240,
"wires": [
[
"ec3e0b17.24b098"
]
]
},
{
"id": "ad497b10.85ada8",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"color_temp\":1000}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 590,
"y": 1300,
"wires": [
[]
]
},
{
"id": "d9d7647c.f0d568",
"type": "inject",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "",
"payload": "{\"color_temp\":1}",
"payloadType": "json",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 580,
"y": 1120,
"wires": [
[]
]
},
{
"id": "ec38b804.be3a78",
"type": "ui_slider",
"z": "b2e437b6.7f5e98",
"name": "",
"label": "Teplota bílé",
"tooltip": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": false,
"outs": "end",
"topic": "",
"min": "1",
"max": "500",
"step": 1,
"x": 970,
"y": 200,
"wires": [
[
"4863eda6.3623c4"
]
]
},
{
"id": "73a43fa7.5d971",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "shake detection",
"func": "var local=context.get('data') || {};\nif (local.count===undefined)//test exists\n{\n local.count=0;\n}\n\nvar action={ payload: msg.payload };\nvar positive = 1;\nvar negative = 0;\n\nif (action.payload === \"shake\") \n {\n \n if (local.count === 0)\n {\n local.count+=1;\n context.set('data',local);\n msg.payload = positive;\n return msg;\n }\n else \n {\n local.count-=1;\n msg.payload = negative;\n return msg;\n }\n\n }\n",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 120,
"wires": [
[
"aa193a0a.1a2ac8"
]
]
},
{
"id": "aa193a0a.1a2ac8",
"type": "switch",
"z": "b2e437b6.7f5e98",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "num"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 790,
"y": 120,
"wires": [
[
"8e398436.fbb558"
],
[
"63dc3682.fb3038"
]
]
},
{
"id": "ec3e0b17.24b098",
"type": "mqtt out",
"z": "b2e437b6.7f5e98",
"name": "",
"topic": "zigbee2mqtt/svetlo_1/set",
"qos": "",
"retain": "",
"broker": "2c7374d9.8a6c9c",
"x": 1290,
"y": 120,
"wires": []
},
{
"id": "8e398436.fbb558",
"type": "ui_button",
"z": "b2e437b6.7f5e98",
"name": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"label": "ON",
"tooltip": "",
"color": "",
"bgcolor": "green",
"icon": "",
"payload": "{\"state\":\"on\"}",
"payloadType": "json",
"topic": "",
"x": 950,
"y": 100,
"wires": [
[
"ec3e0b17.24b098"
]
]
},
{
"id": "63dc3682.fb3038",
"type": "ui_button",
"z": "b2e437b6.7f5e98",
"name": "",
"group": "987fe6b8.7b5dd8",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"label": "OFF",
"tooltip": "",
"color": "",
"bgcolor": "red",
"icon": "",
"payload": "{\"state\":\"off\"}",
"payloadType": "json",
"topic": "",
"x": 950,
"y": 140,
"wires": [
[
"ec3e0b17.24b098"
]
]
},
{
"id": "4863eda6.3623c4",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "to-MQTT_white_temp",
"func": "\nvar value = String(msg.payload);\n \n//preapre MQTT command\nmsg.payload = {};\nmsg.payload.color_temp = value;\n \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 1200,
"y": 200,
"wires": [
[
"ec3e0b17.24b098"
]
]
},
{
"id": "a904554e.14f048",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "angle counter brightness",
"func": "var local=context.get('data') || {};\nif (local.count===undefined)//test exists\n{\n local.count=0;\n}\n\nvar angle=Number(msg.payload);\nlocal.count +=(angle/1.5);\nif (local.count<1)\n {\n local.count=1;\n }\n else if (local.count>255)\n {\n local.count=255;\n }\n \n\nmsg.payload=\" \"+local.count;\ncontext.set('data',local);\nmsg.payload=Number(msg.payload);\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 910,
"y": 360,
"wires": [
[
"8a06d6a1.299558"
]
]
},
{
"id": "f87f3cf2.9933a",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "extrakt baterie",
"func": "var baterie={\"payload\":msg.payload.battery.toString()};\n\n \nreturn baterie;",
"outputs": 1,
"noerr": 0,
"x": 300,
"y": 320,
"wires": [
[
"2ba3c625.86a10a",
"7e14a4a4.11749c"
]
]
},
{
"id": "2ba3c625.86a10a",
"type": "ui_gauge",
"z": "b2e437b6.7f5e98",
"name": "Úroveň nabití baterie",
"group": "a5abd441.60b878",
"order": 0,
"width": 0,
"height": 0,
"gtype": "gage",
"title": "Úroveň nabití baterie",
"label": "units",
"format": "{{value}}",
"min": 0,
"max": "100",
"colors": [
"#e30e02",
"#e6e600",
"#29ae26"
],
"seg1": "20",
"seg2": "60",
"x": 560,
"y": 320,
"wires": []
},
{
"id": "8ed458e9.44d338",
"type": "e-mail",
"z": "b2e437b6.7f5e98",
"server": "smtp.seznam.cz",
"port": "465",
"secure": true,
"name": "[email protected]",
"dname": "",
"x": 570,
"y": 380,
"wires": []
},
{
"id": "7e14a4a4.11749c",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "Battery check",
"func": "var angle=Number(msg.payload);\nif (angle < 25)\n {\n msg.payload = \"Baterie v kostce téměř vybitá!\"\n return msg;\n }\n else\n {\n return null; \n }\n",
"outputs": 1,
"noerr": 0,
"x": 300,
"y": 380,
"wires": [
[
"8ed458e9.44d338"
]
]
},
{
"id": "20e27d21.2be632",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "Action detection",
"func": "if (msg.payload.action === \"shake\")\n{\n var msg={\"payload\":msg.payload.action.toString()};\n return [msg,null,null];\n}\nelse if (msg.payload.action === \"rotate_left\")\n{\n var angle={\"payload\":msg.payload.angle.toString()};\n return [null,angle,null];\n}\nelse if (msg.payload.action === \"rotate_right\")\n{\n var angle={\"payload\":msg.payload.angle.toString()};\n return [null,angle,null];\n}\nelse if (msg.payload.action === \"flip90\")\n{\n var to_side={\"payload\":msg.payload.to_side};\n return [null,null,to_side];\n}\nelse if (msg.payload.action === \"flip180\")\n{\n var side={\"payload\":msg.payload.side};\n return [null,null,side];\n}\nelse return null;\n\n\n",
"outputs": 3,
"noerr": 0,
"x": 480,
"y": 200,
"wires": [
[
"73a43fa7.5d971"
],
[
"2396ae00.39ac82"
],
[
"e8592537.a61158"
]
]
},
{
"id": "852a8424.a46668",
"type": "function",
"z": "b2e437b6.7f5e98",
"name": "angle counter color temp",
"func": "var local=context.get('data') || {};\nif (local.count===undefined)//test exists\n{\n local.count=0;\n}\n\nvar angle=Number(msg.payload);\nlocal.count +=(angle/1.5);\nif (local.count<150)\n {\n local.count=150;\n }\n else if (local.count>500)\n {\n local.count=500;\n }\n \n\nmsg.payload=\" \"+local.count;\ncontext.set('data',local);\nmsg.payload=Number(msg.payload);\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 910,
"y": 300,
"wires": [
[
"4863eda6.3623c4"
]
]
},
{
"id": "e8592537.a61158",
"type": "change",
"z": "b2e437b6.7f5e98",
"name": "Set side persitent",
"rules": [
{
"t": "set",
"p": "to_side",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 260,
"wires": [
[]
]
},
{
"id": "2396ae00.39ac82",
"type": "switch",
"z": "b2e437b6.7f5e98",
"name": "angle switch",
"property": "to_side",
"propertyType": "flow",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "str"
},
{
"t": "eq",
"v": "3",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 670,
"y": 260,
"wires": [
[
"a904554e.14f048"
],
[
"852a8424.a46668"
]
]
},
{
"id": "2c7374d9.8a6c9c",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "987fe6b8.7b5dd8",
"type": "ui_group",
"z": "",
"name": "Světla",
"tab": "a1fe1abd.ae8898",
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "a5abd441.60b878",
"type": "ui_group",
"z": "",
"name": "CUBE",
"tab": "bea0ad47.6592b",
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "a1fe1abd.ae8898",
"type": "ui_tab",
"z": "",
"name": "Světla",
"icon": "dashboard",
"order": 2,
"disabled": false,
"hidden": false
},
{
"id": "bea0ad47.6592b",
"type": "ui_tab",
"z": "",
"name": "Baterie",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]


   
ReplyQuote
Share: