Creating a toggle switch

Moderator: leecollings

Post Reply
gavacac
Posts: 12
Joined: Tuesday 06 December 2016 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Creating a toggle switch

Post 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.
kunoch
Posts: 4
Joined: Wednesday 28 February 2018 14:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Switzerland
Contact:

Re: Creating a toggle switch

Post by kunoch »

mrf68

Re: Creating a toggle switch

Post 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.
kunoch
Posts: 4
Joined: Wednesday 28 February 2018 14:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Switzerland
Contact:

Re: Creating a toggle switch

Post 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.
mrf68

Re: Creating a toggle switch

Post 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. ;)
Xztraz
Posts: 107
Joined: Tuesday 31 January 2017 21:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post 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!
fargle
Posts: 70
Joined: Tuesday 27 March 2018 17:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post 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 8106 times
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post 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 3659 times
Toggle 2.png
Toggle 2.png (87.8 KiB) Viewed 3659 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.
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
wouterlet
Posts: 109
Joined: Tuesday 02 October 2018 20:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post by wouterlet »

Shouldn't you only switch on the state on dor your switch?
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post 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.
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
cody
Posts: 1
Joined: Tuesday 01 June 2021 8:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Creating a toggle switch

Post by cody »

Toggle.png
Toggle.png (24.45 KiB) Viewed 1896 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest