Hi @kriznik
I have set all that up. i believe ive done it all correctly, but i cant seam to get openhab to change the state of the switch
Here are my config files, ive modified them to suit my needs because my light switches are based based on a stateless design, it just sends the same string on each press i needed a way to store and check the state in Mqtt.
i made this Subflow
[{"id":"9c00f54f.6d8b28","type":"subflow","name":"Panel 20 button 41","info":"","category":"","in":[{"x":300,"y":320,"wires":[{"id":"177fd9f2.6de656"}]}],"out":[{"x":1060,"y":320,"wires":[{"id":"ea211b8a.407558","port":0},{"id":"59c06ba.0d6b894","port":0}]}],"env":[]},{"id":"b334b24f.d3394","type":"switch","z":"9c00f54f.6d8b28","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":320,"wires":[["ea211b8a.407558"],["59c06ba.0d6b894"]]},{"id":"ea211b8a.407558","type":"change","z":"9c00f54f.6d8b28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":280,"wires":[[]]},{"id":"59c06ba.0d6b894","type":"change","z":"9c00f54f.6d8b28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":340,"wires":[[]]},{"id":"177fd9f2.6de656","type":"function","z":"9c00f54f.6d8b28","name":"get next value","func":"if (msg.payload == \"20-41\") {\nmsg.payload = flow.get(\"next\")||0;\nreturn msg;\n} \nelse {\nmsg.payload=\"\"\n}\n","outputs":1,"noerr":0,"x":460,"y":320,"wires":[["b334b24f.d3394"]]}]
and this is my current flow.
[{"id":"9c00f54f.6d8b28","type":"subflow","name":"Panel 20 button 41","info":"","category":"","in":[{"x":300,"y":320,"wires":[{"id":"177fd9f2.6de656"}]}],"out":[{"x":1060,"y":320,"wires":[{"id":"ea211b8a.407558","port":0},{"id":"59c06ba.0d6b894","port":0}]}],"env":[]},{"id":"b334b24f.d3394","type":"switch","z":"9c00f54f.6d8b28","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":320,"wires":[["ea211b8a.407558"],["59c06ba.0d6b894"]]},{"id":"ea211b8a.407558","type":"change","z":"9c00f54f.6d8b28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":280,"wires":[[]]},{"id":"59c06ba.0d6b894","type":"change","z":"9c00f54f.6d8b28","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":340,"wires":[[]]},{"id":"177fd9f2.6de656","type":"function","z":"9c00f54f.6d8b28","name":"get next value","func":"if (msg.payload == \"20-41\") {\nmsg.payload = flow.get(\"next\")||0;\nreturn msg;\n} \nelse {\nmsg.payload=\"\"\n}\n","outputs":1,"noerr":0,"x":460,"y":320,"wires":[["b334b24f.d3394"]]},{"id":"4600abdd.2cc1a4","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4068230e.faf1ac","type":"mqtt in","z":"4600abdd.2cc1a4","name":"","topic":"buttons","qos":"0","datatype":"auto","broker":"ba6907f8.d77f18","x":170,"y":200,"wires":[["a48c0d0b.0ef5f"]]},{"id":"e47550bc.7f4dd","type":"openhab2-in","z":"4600abdd.2cc1a4","name":"","controller":"f7d06c8e.b7d0a","itemname":"Office_Light","x":150,"y":120,"wires":[["cb6877a9.dc9fb8"],[]]},{"id":"cb6877a9.dc9fb8","type":"change","z":"4600abdd.2cc1a4","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"20-41","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":100,"wires":[["d36595ad.8bfb68"]]},{"id":"d36595ad.8bfb68","type":"mqtt out","z":"4600abdd.2cc1a4","name":"","topic":"buttons","qos":"0","retain":"","broker":"ba6907f8.d77f18","x":660,"y":60,"wires":[]},{"id":"a48c0d0b.0ef5f","type":"subflow:9c00f54f.6d8b28","z":"4600abdd.2cc1a4","name":"","env":[],"x":430,"y":160,"wires":[["4174d83d.b994a8"]]},{"id":"65a40361.135abc","type":"comment","z":"4600abdd.2cc1a4","name":"Panel 20 button 41","info":"","x":150,"y":60,"wires":[]},{"id":"4174d83d.b994a8","type":"switch","z":"4600abdd.2cc1a4","name":"Change Payload to On or Off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":720,"y":120,"wires":[["21d47498.1f566c"],["56346c7d.136074"]]},{"id":"56346c7d.136074","type":"change","z":"4600abdd.2cc1a4","name":"Light ON","rules":[{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"str","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":140,"wires":[["7377e6d.32f9118"]]},{"id":"21d47498.1f566c","type":"change","z":"4600abdd.2cc1a4","name":"Light OFF","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":80,"wires":[["7377e6d.32f9118"]]},{"id":"7377e6d.32f9118","type":"delay","z":"4600abdd.2cc1a4","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":950,"y":200,"wires":[["dda2bda4.fa1e9"]]},{"id":"9bb9b8c5.7ca538","type":"debug","z":"4600abdd.2cc1a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":320,"wires":[]},{"id":"dda2bda4.fa1e9","type":"mqtt out","z":"4600abdd.2cc1a4","name":"","topic":"home/office/light/1/cmnd/POWER","qos":"","retain":"","broker":"ba6907f8.d77f18","x":1240,"y":100,"wires":[]},{"id":"50db30b0.ea713","type":"mqtt in","z":"4600abdd.2cc1a4","name":"","topic":"home/office/light/1/cmnd/POWER","qos":"0","datatype":"auto","broker":"ba6907f8.d77f18","x":680,"y":320,"wires":[["9bb9b8c5.7ca538"]]},{"id":"ba6907f8.d77f18","type":"mqtt-broker","z":"","name":"Mosquitto","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":"f7d06c8e.b7d0a","type":"openhab2-controller","z":"","name":"Openhab","protocol":"http","host":"localhost","port":"8080","path":"","username":"openhabian","password":"bedrock"}]
doing it this way i can have openhab effectively act in a somewhat stateless manner and have my subflow manage the state. this is all working correclty i just cant seam to get openhab to update the state.
just the rest of my configs.
lights.items
Switch Office_Light "Office Light" <light> (gWSwitch, gLightsHome, gLights, gStoreChange) ["Switchable"] { channel="mqtt:topic:officelight:switch" }
Switch Lounge_Light "Lounge Light" <light> (gWSwitch, gLightsHome, gLights, gStoreChange) ["Switchable"] { channel="mqtt:topic:loungelight:switch" }
switches.things
Thing mqtt:topic:officelight "Office Light" (mqtt:broker:rpi) @ "Office" {
Channels:
Type switch : switch "Office Lights" [ stateTopic="home/office/light/1/stat/POWER", commandTopic="home/office/light/1/cmnd/POWER", on="ON", off="OFF" ]
Type string : devicestate "Device State" [ stateTopic="home/office/light/1/tele/LWT" ]
}
Thing mqtt:topic:loungelight "Lounge Light" (mqtt:broker:rpi) @ "Lounge" {
Channels:
Type switch : switch "Dressroom Lights" [ stateTopic="home/lounge/light/2/stat/POWER", commandTopic="home/lounge/light/2/cmnd/POWER", on="ON", off="OFF" ]
Type string : devicestate "Device State" [ stateTopic="home/lounge/light/2/tele/LWT" ]
}
mqtt-broker.things
Bridge mqtt:broker:rpi "Mosquitto MQTT Broker" [
host="192.168.1.108",
secure=false,
port=1883,
qos=0,
retain=false,
clientid="1921681108",
//certificate="",
//certificatepin=false,
//publickey="",
//publickeypin=false,
keep_alive_time=30000,
reconnect_time=60000,
//lastwill_message="",
//lastwill_qos=1,
//lastwill_topic="",
username="openhabian",
password="bedrock"
]
default.sitemap
sitemap home label="Home" {
Frame {
Group item=Office
}
Frame {
Text label="Light" icon="light" {
Default item=Office_Light label="Office"
Default item=Lounge_Light label="Office"
}
}
}
toggling the switch in either openhab or pressing one of my light switch buttons it sends the correct command ON or OFF so im hoping its just a mistake ive made somewhere,
Cheers