Switch rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Switch rules

#1 Post by Jufo » 16 Mar 2017, 22:56

Hi,

I'm currently using this configuration:

Code: Select all

on SwitchAOn do
   gpio 16,0
   inputswitchstate 14,1
endon

on SwitchAOff do
   gpio 16,1
   inputswitchstate 14,0
endon
on SwitchBOn do
   gpio 12,0
   inputswitchstate 13,1
endon

on SwitchBOff do
   gpio 12,1
   inputswitchstate 13,0
endon

on SwitchA#switch do
   if [SwitchA#switch]=1
      event SwitchAOn
   else
      event SwitchAOff
   endif
endon

on SwitchB#switch do
   if [SwitchB#switch]=1
      event SwitchBOn
   else
      event SwitchBOff
   endif
endon
It works, but it needs to turn on or off the relay with every change of position of the physical switch (no matter if this is a state from 1 to 0 or 0 to 1), it can be done?

Thanks,
Robert

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#2 Post by paxi » 16 Mar 2017, 23:36

Sure.

Create a new switch device (i. e. Name RelayA, valuename state) with gpio 16 as input.

Rule:

Code: Select all

On switchA#switch do
  If [RelayA#state]=0
    Gpio 16,1
  Else
    Gpio 16,0
  Endif 
Endon 
Similar for your second switch/relay of course.
You may need to delete the "inputswitchstate" commands if you call the first 4 events remotely. Or omit them at all and just use the gpio command from outside.

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#3 Post by Jufo » 16 Mar 2017, 23:45

I do not quite understand, my configuration:
GPIO-14 = SwitchA
GPIO-16 = RelayA
GPIO-13 = SwitchB
GPIO-12 = RelayB

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#4 Post by paxi » 16 Mar 2017, 23:50

I know. Just try it. ;)
The new "pseudo" switch stores the status of the relay which my suggested rule then uses to toggle it.

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#5 Post by Jufo » 16 Mar 2017, 23:59

I've tested, unfortunately, it does not work properly. He falls into a loop when, they try to turn off.

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#6 Post by paxi » 17 Mar 2017, 00:00

See my edit above re inputswitchstate.

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#7 Post by Jufo » 17 Mar 2017, 00:08

I lost me at all, use remotely from domoticz and two physical buttons to control two relays. Can you give me the full code for Rules?

Thx
Robert

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#8 Post by paxi » 17 Mar 2017, 00:29

Code: Select all

On switchA#switch do
  If [RelayA#state]=0
    Gpio 16,1
  Else
    Gpio 16,0
  Endif 
Endon 

On switchB#switch do
  If [RelayB#state]=0
    Gpio 12,1
  Else
    Gpio 12,0
  Endif 
Endon 
Nothing else.
I don't use domoticz and therefore can't exactly advice how to reconfigure it.
Make only the pseudo switches send data to the controler so it knows if the relays are on or off, untick "pullup" in task settings, enter an IDX and reboot the esp. Use the gpio command to switch the relays from the controler.

The general idea is to use the relay state instead of the switch state for the whole control logic.

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#9 Post by Jufo » 17 Mar 2017, 08:56

Your script (Rules) only works properly when you turn on the relay. It does not work turn off (another change of state the switch).

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#10 Post by paxi » 17 Mar 2017, 10:11

It works for me. This is my switch setup:
Screenshot_2017-03-17-10-09-20.png
Screenshot_2017-03-17-10-09-20.png (86.53 KiB) Viewed 3546 times
Screenshot_2017-03-17-10-09-03.png
Screenshot_2017-03-17-10-09-03.png (99.62 KiB) Viewed 3546 times

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#11 Post by Jufo » 17 Mar 2017, 13:44

I use bistable switch

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#12 Post by paxi » 17 Mar 2017, 14:28

Then select "normal switch". ;)

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#13 Post by Jufo » 17 Mar 2017, 23:02

But I have already tested this configuration and it does not work. Maybe something is wrong, tomorrow it will analyze ...

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#14 Post by Jufo » 18 Mar 2017, 15:25

I tested again, and unfortunately for me does not work :(

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#15 Post by paxi » 18 Mar 2017, 17:21

"It does not work" is not sufficient info to help. ;)

Post your complete setup:
-devices like above
-rules
-schematic of switches
-domoticz code

Describe exactly what happens when and preferably provide logs from the serial interface.

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#16 Post by Jufo » 19 Mar 2017, 15:53

Rules based on your code:

Code: Select all

On SwitchA#switch do
  If [SpeakersA#state]=0
    Gpio 16,1
  Else
    Gpio 16,0
  Endif
Endon 

On SwitchB#switch do
  If [SpeakersB#state]=0
    Gpio 12,1
  Else
    Gpio 12,0
  Endif
Endon 
Configuration ESP Easy:
Image
Image
Image
Image

Connection GPIO to switch:
Image

Dual 5V Relay module (connected IN1 to GPIO16, IN2 to GPIO12):
Image

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#17 Post by paxi » 20 Mar 2017, 01:20

"inversed" setting for SpeakersA switch is the culprit: value is 0 with gpio high and vice versa - this way the rules can't work. ;)

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#18 Post by Jufo » 20 Mar 2017, 11:33

paxi wrote:
20 Mar 2017, 01:20
"inversed" setting for SpeakersA switch is the culprit: value is 0 with gpio high and vice versa - this way the rules can't work. ;)
yes, but I have to be Inversed (Domoticz get the flag 0 is off)

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#19 Post by paxi » 20 Mar 2017, 21:29

Then change

Code: Select all

If [SpeakersA#state]=0
to

Code: Select all

If [SpeakersA#state]=1

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#20 Post by Jufo » 20 Mar 2017, 21:43

I tested this version, but I only manage to turn on the relay, I can not turn it off.

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#21 Post by paxi » 20 Mar 2017, 22:15

I think there is something conflicting in domoticz.
But honestly: its no fun trying to help you - you didn't provide the information asked for (there is still no hint what you're doing in domoticz) and most of your replies are just "it didn't work".

Again: it works perfect for me in standalone

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#22 Post by Jufo » 20 Mar 2017, 22:30

I try as I can :) Domoticz allows remote control buttons with Easy ESP, commands, respectively:

Amp / Speakers A
On Action: http://192.168.3.120/control?cmd=GPIO,16,0
Off Action: http://192.168.3.120/control?cmd=GPIO,16,1

Amp / Speakers B
On Action: http://192.168.3.120/control?cmd=GPIO,12,0
Off Action http://192.168.3.120/control?cmd=GPIO,12,1

Your Rules does not want to work off (changing any state of the physical button when the relays are on does not turn them off)
Thank you for your support and patience.

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#23 Post by paxi » 20 Mar 2017, 22:58

I've overlooked that your relays are active low - my mistake. Anyhow it should work with the latest code.
But:
Earlier you wrote "bistable switch" now "physical button". Different things and a momentary button (opposed to a toggle switch) needs to be configured as pushbutton (active low from your schematic).

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#24 Post by Jufo » 20 Mar 2017, 23:07

I'm sorry for my mistake
I use the physical bistable button/switch (press this button in this position)

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#25 Post by paxi » 20 Mar 2017, 23:40

It's still unclear what you mean:
- toggle switch
- momentary pushbutton
- latching pushbutton

Jufo
Normal user
Posts: 35
Joined: 12 Mar 2017, 13:47

Re: Switch rules

#26 Post by Jufo » 22 Mar 2017, 12:08

I use toggle switch (on/off) for example:
Image

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Switch rules

#27 Post by paxi » 22 Mar 2017, 22:28

Hmm, I've just noticed you configured speakersA to send boot state but it is default (and thus possibly undefined) in the hardware page. Set the gpio to the desired output state but I'm not sure it will help.

Another test is to disconnect espeasy from domoticz (i. e. with a non-valid conroller IP) and check if the rule works locally.

In all your testing you should update the devices page after each action and carefully observe the values. More info can be obtained from the log, best is via serial since the weblog is rather short.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests