Page 1 of 1

Creating a toggle switch

Posted: Monday 05 March 2018 20:16
by gavacac
I'm struggling with something that seems like it should be really simple. I've bought a lightwave RF switch that is designed to select lighting scenes. It is essentially a selector switch with 5 options.

I want to repurpose the buttons as toggle switches, so that rather than choosing between one of 5 scenes, each button can be used to toggle a device on and off.

Example: if I press button 3 once, a device switches on. If I press it again, the device switches off. I thought I could create a blocky logic as follows:

If lightwave switch = button 3, and device switch is off, set to on
Or
If lightwave switch = button 3 and device switch is on, set to off.

The problem with this is that the lightwave switch is a selector, so once I press button 3, it stays selected until I select another button. This results in an endless loop as the device switches on and off until I press a different button on the lightwave switch.

Is there a way to count the number of presses of a button? There is a record in the log each time I press the button so it seems like it should be possible. If I could count the number of presses, I could possibly create some logic to identify if pressing button 3 should be an On action or and Off action.

Or is there some other way? Any guidance would be appreciated.

Re: Creating a toggle switch

Posted: Tuesday 13 March 2018 9:11
by kunoch

Re: Creating a toggle switch

Posted: Tuesday 13 March 2018 9:32
by mrf68
Have you tried it yet? I suppose that after selecting a scene, the device is not continuously sending a signal. So in my opinion your own suggestion for the blockly is correct. But as I don’t know the exact function of the switch, it is a presumption.

Re: Creating a toggle switch

Posted: Tuesday 13 March 2018 10:02
by kunoch
I tried the same as @gavacac proposed with the zwave.me/Popp/devolo scene controller, but this only lead to blinking light (constantly on and off). Only the approach as given in the link did finally do what I wanted (toggle). The button report is always ON, so I ended up with the additional variable to check the current status. Unfortunately not so straight forward, but works reliably.

Re: Creating a toggle switch

Posted: Tuesday 13 March 2018 20:24
by mrf68
Could it be that the sender sends a signal multiple times in a very short period? That would explain the loop imho. Perhaps delaying the action could prevent it? Something like If signal then toggle light after 5 seconds? Just thinking out loud. ;)

Re: Creating a toggle switch

Posted: Saturday 17 March 2018 0:53
by Xztraz
have a look at https://www.domoticz.com/wiki/Blockly
last of the examples describe a toggle switch. make sure to set trigger to device!

Re: Creating a toggle switch

Posted: Wednesday 11 April 2018 14:57
by fargle
Another variation on the same theme. This allows a single button on a Remotec ZRC-90 to successively toggle 3 switches on and then back off again in reverse order.
2018-04-07 14_25_16-Domoticz.jpg
2018-04-07 14_25_16-Domoticz.jpg (56.37 KiB) Viewed 8115 times

Re: Creating a toggle switch

Posted: Thursday 27 February 2020 17:15
by Geitje
I tried different options to create a toggle switch from a wall switch using Blocky. Also tried the method mentioned in the wiki. The light keeps going on and of every 8 or so minutes. I tried these 2 options, both of them have this slow loop:
Spoiler: show
Toggle 1.png
Toggle 1.png (48.11 KiB) Viewed 3668 times
Toggle 2.png
Toggle 2.png (87.8 KiB) Viewed 3668 times
I set trigger to "Device". I checked wether the switch is reporting/messaging every 8 minutes or things like that: log of the switch only shows if I switch it myself. The Switch is a Shelly 1, I can set it to momentary switch or on/off switch.

Hope someone can help with this.

Re: Creating a toggle switch

Posted: Thursday 27 February 2020 21:12
by wouterlet
Shouldn't you only switch on the state on dor your switch?

Re: Creating a toggle switch

Posted: Thursday 27 February 2020 21:50
by Geitje
I solved it by using a DzVents script I already used for something else: Found it a while ago (credits @waaren).
Spoiler: show

Code: Select all

return {

   on = { devices = { 677 }},        -- idx of your button
               
   execute = function(dz, item )
        if item.state == "On" then
            dz.devices(77).toggleSwitch()    -- idx of your Yeelight
        elseif item.state == "Off" then
            dz.devices(77).toggleSwitch()    -- idx of your other light
        else 
            dz.log("state of " .. item.name .. " is now Off")
        end
   end
}
This behaves the way I expect. No unexpected state changes. I still do not know where the unexpected state in BLocky changes came from. I tried it with other switches and light, tried more than 5 different blocky patterns I found on the forums, but they kept coming.

Re: Creating a toggle switch

Posted: Tuesday 01 June 2021 8:51
by cody
Toggle.png
Toggle.png (24.45 KiB) Viewed 1905 times