Create a rule note based on a device

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Create a rule note based on a device

#1 Post by rudloffl » 04 Jul 2019, 07:32

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

User avatar
grovkillen
Core team member
Posts: 3106
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Create a rule note based on a device

#2 Post by grovkillen » 04 Jul 2019, 08:03

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 ;)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#3 Post by rudloffl » 04 Jul 2019, 18:40

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

User avatar
grovkillen
Core team member
Posts: 3106
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Create a rule note based on a device

#4 Post by grovkillen » 04 Jul 2019, 18:45

I wouldn't use the tasks for relays, simply use internal variables to keep track of them instead.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#5 Post by rudloffl » 04 Jul 2019, 19:03

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

User avatar
grovkillen
Core team member
Posts: 3106
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Create a rule note based on a device

#6 Post by grovkillen » 04 Jul 2019, 19:09

Yes you can add up to 16 internal variables and create events and set values just as any task.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#7 Post by rudloffl » 04 Jul 2019, 19:24

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 ?

User avatar
grovkillen
Core team member
Posts: 3106
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Create a rule note based on a device

#8 Post by grovkillen » 04 Jul 2019, 19:40

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
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#9 Post by rudloffl » 04 Jul 2019, 19:58

Thank you Grovkillen, I will work on that solution.

Really appreciate the help, stay tuned !

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#10 Post by rudloffl » 04 Jul 2019, 22:42

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

rudloffl
Normal user
Posts: 9
Joined: 04 Jul 2019, 07:17

Re: Create a rule note based on a device

#11 Post by rudloffl » 04 Jul 2019, 23:20

I can control via http with:

Code: Select all

http;//...event,RelayToggle=1,5

User avatar
grovkillen
Core team member
Posts: 3106
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Create a rule note based on a device

#12 Post by grovkillen » 05 Jul 2019, 05:34

Yes you need to set those interval variables using Let. And you access them using [VAR#n] where n is 1...16
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests