Page 1 of 1
Create a rule note based on a device
Posted: 04 Jul 2019, 07:32
by rudloffl
Hello to all,
I'm working on a sprinkler system, and I'm running short on devices available (8 relais + LCD display + Temperature)
I have added a PCF8574 on which I want to connect (8X) press-buttons to control zones, I was planning to use rules to activate the zones without the home automation system (no devices or event crested for each button).
Is it possible to create an event "on the fly" (see example below) ?
Thanks
Code: Select all
on [pcfgpio,9] do
if [pcfgpio,1]=1
pcfgpio,1,0
else
pcfgpio,1,1
endif
endon
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 08:03
by grovkillen
No not what you typed there, that's not possible but if you explain more to me what you are wanting to accomplish I'll be able to help you further. It doesn't sound that unique
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 18:40
by rudloffl
Thanks for getting back to me, here are more details
Features/ materials details:
- control 8 relays via a PCF8574
- Uses a LCD display to see what's going on (also via I2c)
- Control the 8 relays via 8 press-buttons on the main panel (an other PCF8574)
- A temperature sensor directly on the GPIO that i don't think is relevant here (and optional)
My knowledge of espeasy is limited, and I might miss some details. I was hoping to code rules to control the relays with press-buttons. The problem is that I'm limited to 12 devices (that automatically create events/triggers used in rules) and I'm already using 8 of them just for the relays. I have potentially only 4 devices left to create events.
I think that my main questions are:
- Is it possible to use PCFGPIOs directly as event/triggers in rules ?
- Is it possible to gather switch status of the press buttons into a single device ? (to keep the number of devices below 12)
- An other solution I might be missing ?
Comments are welcome
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 18:45
by grovkillen
I wouldn't use the tasks for relays, simply use internal variables to keep track of them instead.
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 19:03
by rudloffl
But I need to transmit the relays status. When you say "internal", you mean GPIO address directly in rules ?
I can try to use devices for each press-buttons and publish the relays status via rules. I have to make sure they will always stay synchro (actual relays status vs info that rules are publishing)
Would generic variables help me ?
Thanks
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 19:09
by grovkillen
Yes you can add up to 16 internal variables and create events and set values just as any task.
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 19:24
by rudloffl
by "internal variables" you mean "Generic - Dummy device" ?
To control the relays with my home automation service, can I overwrite the press-button status via http ?
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 19:40
by grovkillen
No I mean setting the variables using the command "let".
So as an example you may do it like this:
Code: Select all
On Button1#State Do
If [VAR#1]=1
Event,RelayToggle=1,14,0
Else
Event,RelayToggle=1,14,1
EndIf
EndOn
//Add all your buttons
On RelayToggle Do
Let,%eventvalue1%,%eventvalue3%
GPIO,%eventvalue2%,%eventvalue3%
//Here you can also publish the states
EndOn
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 19:58
by rudloffl
Thank you Grovkillen, I will work on that solution.
Really appreciate the help, stay tuned !
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 22:42
by rudloffl
I have done some progress, below is my code inspired from what you shared.
What it can do:
- It can switch the relay each time you press a button
- Works with 2 zones, should be able to expand to 8....
What I can't do yet:
- Control the system via http, I tried a "http:// ....PCFPulse,9,0,250" but it doesn't work.
- Still need to work on the publishing
What I'm pretty sure I don't understand...:
- VAR ? is it a special command ? Is it related with the let (i assume so)
- Do I need the boot to initialize ?
Any idea ?
Code: Select all
On System#Boot do //setup all the zones to 0
[VAR#1]=0
[VAR#2]=0
// complete all the zones
endon
on button1#State Do
if [button1#State]=1
Event,RelayToggle=1 //zone 1 = pdfgpio 1
endif
EndOn
on button2#State Do
if [button2#State]=1
Event,RelayToggle=2 //zone 2 =pcfgpio 2
endif
EndOn
On RelayToggle Do
if [VAR#%eventvalue%]=0 // not sure about the VAR, how does it work ?
pcfgpio,%eventvalue%,1
Let,%eventvalue%,1
// Publish for zone
else
pcfgpio,%eventvalue%,0
Let,%eventvalue%,0
// Publish for zone
endif
EndOn
Re: Create a rule note based on a device
Posted: 04 Jul 2019, 23:20
by rudloffl
I can control via http with:
Re: Create a rule note based on a device
Posted: 05 Jul 2019, 05:34
by grovkillen
Yes you need to set those interval variables using Let. And you access them using [VAR#n] where n is 1...16