Hi,
I have an Ikea 'volume button' what I use for my sonos. This works.
The only annoying thing: when I adjust the volume with something else then the Ikea button, you have a volume 'jump' the next time you use the button again because I have no feedback.
This feedback is no problem for me the ask, but then I'm stuck, I will have to different inputs on my function and I really don't manage to combine them.
So 'flow' 1 works. I receive data from the pushbutton over MQTT and I increase or decrease the volume in my function
But now, I want to 'sync' this volume when I have an action on 'flow' 2.
You can see the commented code in my function and you will understand where I would like to go to, but this does not work. I also tried with the join function, but I get stuck every time.
Who can help me with this? The goal is that every time there is an action on 2, my internal variable volume is updated and saved... not return msg at that moment.
[
{
"id": "2183bd54719bd6df",
"type": "mqtt in",
"z": "9a5ec889a62524d2",
"name": "zigbee2mqtt/volumeknop_bureau",
"topic": "zigbee2mqtt/volumeknop_bureau",
"qos": "2",
"datatype": "json",
"broker": "ac0ebf430a1bb8e8",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 550,
"y": 1540,
"wires": [
[
"b9352ec6d93f4ecc"
]
]
},
{
"id": "7a52b6c58e35def1",
"type": "harmonyws-observer",
"z": "9a5ec889a62524d2",
"name": "Harmony Observer",
"server": "4c96c05d6c530ab5",
"startup": true,
"toContext": false,
"context": "global",
"contextKeyActivity": "activity",
"contextKeyAutomation": "automation",
"x": 110,
"y": 1480,
"wires": [
[
"10b5d4a54ab907ed"
]
]
},
{
"id": "6446a526e7c456fa",
"type": "sonos-universal",
"z": "9a5ec889a62524d2",
"confignode": "88e9fa70.4a53e8",
"command": "player.set.volume",
"state": "",
"stateType": "str",
"avoidCheckPlayerAvailability": false,
"name": "Set_Volume",
"x": 1075,
"y": 1520,
"wires": [
[]
],
"l": false
},
{
"id": "b9352ec6d93f4ecc",
"type": "function",
"z": "9a5ec889a62524d2",
"name": "Sonos volume",
"func": "var x = msg.payload.action;\n//var start_volume = msg.payload.volume ;\nvar volume=context.get('volume') || 0;\n\n//if (start_volume != volume) {\n// volume = start_volume;\n // context.set('volume',volume);\n // }\n\nif (x== \"rotate_right\") {\n volume +=2;\n if (volume >= 30) {\n volume = 30;\n }\n msg.payload= volume;\n context.set('volume',volume);\n return [msg, null];\n }\n\nif (x== \"rotate_left\") {\n volume -=2;\n if (volume <= 0) {\n volume = 0;\n }\n msg.payload= volume;\n context.set('volume',volume);\n return [msg, null];\n }\n \n //next if is not in use at the moment\nif (x== \"play_pause\") {\n msg.payload = 'Pushed';\n return [null, msg];\n }\n\n\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 840,
"y": 1540,
"wires": [
[
"6446a526e7c456fa",
"e14a7d6d57d4749b"
],
[
"6de6e7cfa5a7aec3"
]
]
},
{
"id": "10b5d4a54ab907ed",
"type": "sonos-universal",
"z": "9a5ec889a62524d2",
"confignode": "88e9fa70.4a53e8",
"command": "player.get.volume",
"state": "",
"stateType": "str",
"avoidCheckPlayerAvailability": false,
"name": "",
"x": 330,
"y": 1480,
"wires": [
[
"2958fc72007e716c"
]
]
},
{
"id": "2958fc72007e716c",
"type": "change",
"z": "9a5ec889a62524d2",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "payload.volume",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 1480,
"wires": [
[
"b9352ec6d93f4ecc",
"6a500c68d45bda7a"
]
]
},
{
"id": "e14a7d6d57d4749b",
"type": "debug",
"z": "9a5ec889a62524d2",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1140,
"y": 1460,
"wires": []
},
{
"id": "6de6e7cfa5a7aec3",
"type": "debug",
"z": "9a5ec889a62524d2",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1060,
"y": 1660,
"wires": []
},
{
"id": "6a500c68d45bda7a",
"type": "debug",
"z": "9a5ec889a62524d2",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 820,
"y": 1440,
"wires": []
},
{
"id": "ac0ebf430a1bb8e8",
"type": "mqtt-broker",
"name": "Mqtt",
"broker": "192.168.0.71",
"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": "4c96c05d6c530ab5",
"type": "harmonyws-server",
"name": "Woonkamer",
"ip": "192.168.0.80",
"debug": false
},
{
"id": "88e9fa70.4a53e8",
"type": "sonos-config",
"name": "Sonos_IP",
"serialnum": "",
"ipaddress": "192.168.0.111"
}
]