Lua to control dim level with pulse switch

Moderator: leecollings

Post Reply
User avatar
mvveelen
Posts: 687
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Lua to control dim level with pulse switch

Post by mvveelen »

Hi,

I just got rid of the last ZWave device in my Domoticz setup and I am now facing the following challenge:

With the ZWave unit I could control the light with a pulse switch to switch ON / OFF and control the DIM level by holding the switch a bit longer. When I released the switch, the dim level was set.

So now I want to accomplish the same with, for instance, a KaKu switch. Domotcz should then handle it further instead of the (ZWave device).

Is this possible, and if so: how would such a Lua script look like ?
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: Lua to control dim level with pulse switch

Post by niceandeasy »

Hmm. My goal is to get rid of the KAKU devices and replacing them with ZWAVE.

ZWave is the better, because of its bi-directional communication, mesh-network-capability, more functionality in the devices, sensors and switches, more speed, each powered device is able to pass-through, in case another device is not able to reach the controller directly, thus, acting as an intelligent repeater. Most zwave switches can be configured what commands to send at taps, double-taps, press&hold.
KAKU communication fails when two devices send at the same time. No network, no bi-directional, so no feedback on device/switch state to Domoticz. If you would use a repeater for controlling out-of-range KAKU devices, chances are that Domoticz will receive the signal twice. In some cases, this can lead to a signal avalance. Most KAKU switches cannot be configured.

The KAKU switches I know of, will keep transmitting the ON code repeatedly if you press&hold them. Old-style KAKU-dimmers will switch on and off at the press of one button and will start cycling between slowly brightening and slowly dimming at the push of the other button, until you stop it by pressing the same button again.
Newer style KAKU-dimmers can be directly set to Off, On or 14 brightness levels in between full on or off. Domoticz is capable of sending and receiving such commands. And the newer dimmer-compatible wall-switches will have a user manual that will tell you how to fiddle with them to make them send brightness levels. And I don't think that they work the same as your ZWave device.

If you would press&hold an ordinary KAKU switch On-button, Domoticz will receive and interpret that as a push. If that KAKU device is configured in Domoticz, Domoticz will just update its switch to On and will execute scripting if necessary. Domoticz will not 'register' how long you pressed the button and will not do something else because you pressed&held it, instead of just pushed it.

If you want to change that, you need to determine if your 433MHz tranceiver hardware is actually putting out the continuous stream of codes that the button will transmit if you press&hold it. If that is the case, you can try to code a new 433MHz hardware driver for Domoticz that will actually invoke dimmer commands in case of a detected press&hold, if you know the programming language.

What you can do if you have a normal on/off KAKU pushbutton-switch and a modern KAKU dimmer module, is, learning them to different codes in Domoticz. Then you can use scripting to make your dimmer turn full on at the first button-on-signal received and step down the dimmer level at every next received button-on-signal. Make your dimmer turn off when then button-off-signal is received and step up the dimmer at every next received button-off-signal. But don't push the buttons too fast and don't hold it, because that will block the signal that Domoticz tries to send to the dimmer-module, resulting in Domoticz showing you that the lamp is dimmed but in real, the lamp is still at full power. And, of course, this will take time: approx. 1/4 second or so.
This is not the way Domoticz is intended to be used with KAKU equipment.

If you really want to build this, you'll end up with quite a big script for one pair of pulse-switch and dimmer-module. Maybe dzVents could be helpful. If you have a lot of such pairs, I suggest naming them with a code in the name. You can make the script act only on devicechanges of switches with that code and use the rest of the switch's name to identify what module should be controlled. Put the buttons in a hidden room and put the modules viewable in Domoticz.
The script needs to act on a button's push, only if it has the code in the name. If so, it will then need to query the state of the module, extract the name of the corresponding module out of the button's name, calculate what needs to be done and output that via the commandArray.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest