logo elektroda
logo elektroda
X
logo elektroda

[Tutorial] Detached Mode for Openbeken wall switch

ferbulous 
This is a quick guide on setting up 'detached mode' with openbk flashed switches.
This would continuously power your wifi/zigbee bulbs without turning it off when the switch is toggled.

On your switch. you'll need to change the relay that's wired to your wifi bulbs to AlwaysHigh and assign a fake relay to any random unused pin.



P8 - Relay 1
P14 - Button 1
P9 - Fake relay


P8 AlwaysHigh 
P9 Relay 1


Add this script:


//publish button actions to mqtt for button 1 (pin 14)
addEventHandler OnClick 14  publish button click
addEventHandler OnDblClick 14 publish button dblclick
addEventHandler OnHoldStart 14 publish button holdstart
addEventHandler OnHold 14 publish button hold
addEventHandler OnRelease 14  publish button release
//reassign pin 8 as relay when MQTT is offline
addEventHandler MQTTState 1 backlog setPinRole 8 AlwaysHigh; setPinRole 9 Rel
addEventHandler MQTTState 0 backlog setPinRole 8 Rel; setPinRole 9 AlwaysLow


Now, you can toggle the switch and do some custom actions based on published mqtt button payload
MQTT topic to subscribe

<device name>/<channel number>/get
<device name>/button/get

Example for my device:

living_room_switches/1/get
living_room_switches/button/get


Nodered flows for dimming & changing color temperature:
[
Spoiler:
 
[{"id":"18d64a1a715694fc","type":"mqtt in","z":"4cb2d8d4.f1ff18","name":"","topic":"living_room_switches/button/get","qos":"2","datatype":"auto-detect","broker":"da8d15474208fac9","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":780,"wires":[["4a5e5569a15691e5"]]},{"id":"4a5e5569a15691e5","type":"switch","z":"4cb2d8d4.f1ff18","name":"Switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"click","vt":"str"},{"t":"eq","v":"dblclick","vt":"str"},{"t":"eq","v":"hold","vt":"str"},{"t":"eq","v":"release","vt":"str"},{"t":"eq","v":"holdstart","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":390,"y":780,"wires":[["9a0699ccd15bc40a"],["a7e3bedb345795e4"],["0b2252d48c11a5f6"],["5cfd4e38daddc201"],["bf794dd51f95e6d2"]]},{"id":"0bda89995a681890","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"toggle lights","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"light","service":"toggle","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":620,"wires":[[]]},{"id":"bf794dd51f95e6d2","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"toggle_dimming","server":"10991ca8.1f1c03","version":5,"debugenabled":false,"domain":"input_boolean","service":"toggle","areaId":[],"deviceId":[],"entityId":["input_boolean.dim_switch"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":540,"y":940,"wires":[[]]},{"id":"a7e3bedb345795e4","type":"api-current-state","z":"4cb2d8d4.f1ff18","name":"input cycle colors","server":"f4149317.d3794","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_select.cycle_colors","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":630,"y":720,"wires":[["44d99c8c08d5e1ee"]]},{"id":"44d99c8c08d5e1ee","type":"switch","z":"4cb2d8d4.f1ff18","name":"Switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Cool","vt":"str"},{"t":"eq","v":"Warm","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":720,"wires":[["7316fa48add4a421"],["87c641df2d84020a"]]},{"id":"7316fa48add4a421","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Cool","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"{\"color_temp\":153}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":700,"wires":[["03c552b5c13531ed"]]},{"id":"87c641df2d84020a","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Warm","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"{\"color_temp\":490}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":760,"wires":[["03c552b5c13531ed"]]},{"id":"03c552b5c13531ed","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"input_select","service":"select_next","areaId":[],"deviceId":[],"entityId":["input_select.cycle_colors"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1150,"y":720,"wires":[[]]},{"id":"0b2252d48c11a5f6","type":"api-current-state","z":"4cb2d8d4.f1ff18","name":"check dim","server":"f4149317.d3794","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.dim_switch","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":600,"y":800,"wires":[["5f94ea1ad5c9da8b"],["6034cf15d769023f"]]},{"id":"5cfd4e38daddc201","type":"change","z":"4cb2d8d4.f1ff18","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":880,"wires":[["5f94ea1ad5c9da8b","6034cf15d769023f"]]},{"id":"5f94ea1ad5c9da8b","type":"trigger","z":"4cb2d8d4.f1ff18","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":860,"wires":[["f4f5fd69f4ccefe2"]]},{"id":"6034cf15d769023f","type":"trigger","z":"4cb2d8d4.f1ff18","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-250","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":920,"wires":[["92cc63045a3ad078"]]},{"id":"92cc63045a3ad078","type":"api-current-state","z":"4cb2d8d4.f1ff18","name":"Check lights state","server":"22f5da40.d3e236","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.living_room_lights_prime","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1090,"y":920,"wires":[["e07a0bcb27553333"],[]]},{"id":"f4f5fd69f4ccefe2","type":"api-current-state","z":"4cb2d8d4.f1ff18","name":"Check lights state","server":"22f5da40.d3e236","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.living_room_lights_prime","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1090,"y":860,"wires":[["fbb46d6331d169ab"],[]]},{"id":"e07a0bcb27553333","type":"function","z":"4cb2d8d4.f1ff18","name":"Brightness -40","func":"var brightness = msg.data.attributes.brightness; //setup brightness and set to msg.payload\nbrightness = parseInt(brightness);\n\nif (brightness > 70) {\n    brightness = brightness - 40;\n} else {\n    brightness = 50;\n}\n\nmsg.payload = brightness;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":920,"wires":[["8a533c20131b57b0"]]},{"id":"fbb46d6331d169ab","type":"function","z":"4cb2d8d4.f1ff18","name":"Brightness +30","func":"var brightness = msg.data.attributes.brightness;\nbrightness = parseInt(brightness);\n\nvar dimmSize = 30;  //ONLY CHANGE THIS VALUE IF YOU WANT A DIFFERENT DIMM SPEED\nvar maxBrightness = 255;\nif (brightness <= maxBrightness - dimmSize) {\n    brightness += dimmSize;\n} else {\n    brightness = maxBrightness;\n}\n\nmsg.payload = brightness;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1300,"y":860,"wires":[["44b27c64043219f4"]]},{"id":"8a533c20131b57b0","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Light On","server":"22f5da40.d3e236","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"{    \"entity_id\": \"light.bedroom_1_light\",    \"brightness\": {{payload}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1500,"y":920,"wires":[[]]},{"id":"44b27c64043219f4","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Light On","server":"22f5da40.d3e236","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"{    \"entity_id\": \"light.bedroom_1_light\",    \"brightness\": {{payload}}}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1500,"y":860,"wires":[[]]},{"id":"9a0699ccd15bc40a","type":"api-current-state","z":"4cb2d8d4.f1ff18","name":"Check lights","server":"f4149317.d3794","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.living_room_lights_prime","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":550,"y":660,"wires":[["ca3d5ec50c904c8b"],["fa29de278dcf515f"]]},{"id":"fa29de278dcf515f","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Lights off","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":660,"wires":[[]]},{"id":"ca3d5ec50c904c8b","type":"api-call-service","z":"4cb2d8d4.f1ff18","name":"Lights on","server":"f4149317.d3794","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights_prime"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":620,"wires":[[]]},{"id":"8a20507042a29c50","type":"mqtt in","z":"4cb2d8d4.f1ff18","name":"","topic":"living_room_switches/1/get","qos":"2","datatype":"auto-detect","broker":"da8d15474208fac9","nl":false,"rap":true,"rh":0,"inputs":0,"x":130,"y":700,"wires":[["46d961b14905441e"]]},{"id":"46d961b14905441e","type":"switch","z":"4cb2d8d4.f1ff18","name":"Switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":600,"wires":[["ca3d5ec50c904c8b"],["fa29de278dcf515f"]]},{"id":"da8d15474208fac9","type":"mqtt-broker","name":"MQTT hass","broker":"192.168.1.40","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":"f4149317.d3794","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"10991ca8.1f1c03","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false},{"id":"22f5da40.d3e236","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"","statusSeparator":"","enableGlobalContextStore":false}]


1) Create input boolean for dimming (input_boolean.dim_switch)
2) Add a new input helper dropdown for 'cycle colors'


Brief summary of the flow
a. single click to toggle lights on/off
b. 'holdstart' payload would toggle 'input_boolean.dim_switch' that switches between dimming or increasing brightness
c. hold action (with trigger node) would continuously increase/decrease brightness every 250ms
d. release payload sends reset payload to stop the trigger node thus stopping the dimming action
f. double click to change from warm or cold temperature
e. toggle channel 1 relay to toggle on/off for the lights

Demo:




As you can see, the led indicator for switch 1 is always on, that's because for my switch, the led is tied to the relay.
There are other switches in the market with its dedicated pin for led such as these:

https://templates.blakadder.com/DS-102_3.html
https://templates.blakadder.com/milfra_TB12.html

Alternative way would be to use device group to perform all the actions above without relying on homeassistant, however device group isn't quite stable for my usage yet as I continue testing it.

I'm sure there are other ways of setting 'detached' mode, anyway this is my approach.
Your ideas are welcome

About Author
ferbulous wrote 417 posts with rating 55 , helped 8 times. Been with us since 2022 year.

Comments

p.kaczmarek2 14 Dec 2022 19:38

Very clever way to get around the device limitations, although with the latest OBK updates (that weren' t in place at the time of creating automation from the first post) it should be possible to do it... [Read more]

ferbulous 14 Dec 2022 20:54

Indeed, all those action are doable in script I did try implementing with device group earlier, but I was still getting 'dgr socket error', device group randomly not broadcasting/receiving or just the... [Read more]

p.kaczmarek2 14 Dec 2022 21:17

I am using DGR to control LED strips and it seem reliable for me, but we will investigate more. But for now, have you considering replacing DGR_SendBrightness with SendGET? Maybe it could work..... [Read more]

ferbulous 15 Dec 2022 02:08

@pkaczmarek2 SendGET didn’t work when i tried replacing DGR_SendBrightness I did put a request if channel variable can be passed to the url [Read more]

p.kaczmarek2 15 Dec 2022 09:48

@ferbulous it was already granted, from what I can tell. Almost immediately. The target URL is now expanding the $CH11 etc etc syntax. [Read more]

ferbulous 16 Dec 2022 08:25

Thanks, I haven't checked that yet Example for the URL to utilize that? addEventHandler OnHoldStart 22 SetChannel 6 0 // when Hold repeats, add a 10 value as a step // AddChannelSyntax: channelindex... [Read more]

p.kaczmarek2 16 Dec 2022 08:45

The following example looks correct, altough I do not know if our software is currently capable of sending GET packet, every, how often does "hold event" repeat, 300ms? You might need to make repeats less... [Read more]

ferbulous 16 Dec 2022 09:12

Indeed, it's probably not suitable especially if you have multiple bulbs [Read more]

%}