Help you create the device rules for the following requirements

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Help you create the device rules for the following requirements

#1 Post by lyovav » 27 Sep 2018, 13:04

Help you create the device rules for the following requirements

1. is the control button on the off 1 relay (GPIO2)
2. is a mqtt server with the help of which is remotely controlled by 1 relay by topic /neopixel/relay1/status

for that

2 threads are created on the mqtt server

topics
/neopixel/relay1/switch
/neopixel/relay1/status


when the status changes /neopixel/relay1/Status

switching on (1) or switching off (0) relay1 occurs

and the value in the topic /neopixel/relay1/Switch changes switching on (1) or switching off (0)

thx

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

Re: Help you create the device rules for the following requirements

#2 Post by grovkillen » 27 Sep 2018, 17:35

What are you wanting from us exactly?
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:

lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Re: Help you create the device rules for the following requirements

#3 Post by lyovav » 27 Sep 2018, 17:51

I have Sonof BASIC and I really liked the project esp easy like custom software.
but I could not find a ready-made solution to manage Sonof BASIC using mqtt server
I've already figured out how to control the relay using a button but can not do it with a mqtt server with a reverse connection...

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

Re: Help you create the device rules for the following requirements

#4 Post by grovkillen » 27 Sep 2018, 18:05

https://www.letscontrolit.com/wiki/inde ... noff_basic

And for MQTT etc look at the tutorial
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:

lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Re: Help you create the device rules for the following requirements

#5 Post by lyovav » 29 Sep 2018, 20:40

Thank you very much for your help
I almost found a rule what I wanted

Code: Select all

on lamp_on do
    gpio,12,1
    gpio,13,0
endon

on lamp_off do
    gpio,12,0
    gpio,13,1
endon

on lamp_change do
  if [relay#Switch]=1
    event,lamp_off
    
  else
    event,lamp_on
    
  endif
endon

on button#Switch do
  event,lamp_change
endon
I can remotely control the by URL code like

Code: Select all

http://IP/control?cmd=event,lamp_on
http://IP/control?cmd=event,lamp_off
and that's not exactly what I wanted...

I'd like to manage relay by the topic change in the MQTT server like change /Sonoff_1M/relay/Switch/0 - lamp_off and Sonoff_1M/relay/Switch/1 lamp_on
and of course the button on the Sonoff device.

Thx.

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

Re: Help you create the device rules for the following requirements

#6 Post by grovkillen » 29 Sep 2018, 22:30

You send event,lamp_on or event,lamp_off to topic /Sonoff_1M/cmd and you get the and result.
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:

lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Re: Help you create the device rules for the following requirements

#7 Post by lyovav » 30 Sep 2018, 08:23

Ok) thx Mqtt import that's exactly what I needed)

Code: Select all

on lamp_on do
Publish /%sysname%/state,1
    gpio,12,1
    gpio,13,0

endon

on lamp_off do
Publish /%sysname%/state,0
    gpio,12,0
    gpio,13,1

endon

on lamp_change do
  if [relay#Switch]=1
    event,lamp_off
    
  else
    event,lamp_on
    
  endif
endon

[code]
on button#Switch do
  event,lamp_change
endon

on rele_state#state=1 do
    gpio,12,1
    gpio,13,0

endon

on rele_state#state=0 do
    gpio,12,0
    gpio,13,1

endon

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

Re: Help you create the device rules for the following requirements

#8 Post by grovkillen » 30 Sep 2018, 09:00

Using MQTT import is over complicating I think. Why not use the "cmd" topic?

Or if you want to use MQTT import you should do this:

Code: Select all

on rele_state#state=1 do
    event,lamp_on
endon

on rele_state#state=0 do
    event,lamp_off
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:

lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Re: Help you create the device rules for the following requirements

#9 Post by lyovav » 30 Sep 2018, 09:14

The fact is that with a new start or when changing the name of a Unit Name: of this topic does not exist and control via MQTT will not work.

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

Re: Help you create the device rules for the following requirements

#10 Post by grovkillen » 30 Sep 2018, 09:17

Ok I understand, but consider using my suggested change in the rule. It'll make it easier to maintain.
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:

lyovav
New user
Posts: 9
Joined: 27 Sep 2018, 12:46

Re: Help you create the device rules for the following requirements

#11 Post by lyovav » 30 Sep 2018, 09:32

Thanks again for the help.
For my smart house (majordomo) I used different custom firmware until I chose on ESP Easy
Since I like it as a universal platform for sensors, relays and etc.
I have not really figured it out yet but I try not to miss the opportunity to acquire certain knowledge on the forum.

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: Help you create the device rules for the following requirements

#12 Post by iron » 07 Jan 2019, 20:30

grovkillen wrote: 30 Sep 2018, 09:17 Ok I understand, but consider using my suggested change in the rule. It'll make it easier to maintain.
Is there an option for GPIOs (gpio/pcfgpio/mcpgpio) to publish their state w/o being declared as input switch in the Tasks ?

/%sysname%/GPIO/<pin#>, <payload 0 or 1> changes the state of the pin w/o being declared as input but never publishes its state it back.

Was thinking something like :

gpio,12,0,1 Would initialize the controller state of the GPIO

{
"log": "GPIO 12 Set to 0",
"plugin": 1,
"pin": 12,
"mode": "output",
"state": 1,
"controller:1"
}

Would be handy saving up on the amount of tasks !!!

-D
-D

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

Re: Help you create the device rules for the following requirements

#13 Post by grovkillen » 07 Jan 2019, 22:13

Yes you can do it using rules. Not super simple (not like a setting) but very much workable.
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:

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: Help you create the device rules for the following requirements

#14 Post by iron » 08 Jan 2019, 11:25

grovkillen wrote: 07 Jan 2019, 22:13 Yes you can do it using rules. Not super simple (not like a setting) but very much workable.
I am thinking something like :

on <gpio> do
Publish,%sysname%/<gpio>/<pin>,<state>
endon

So every time any gpio pin changes for any reason from any source, the Rule posts its new value

Not sure if this even possible outside of a Task or even the value's syntax...

-D
-D

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Help you create the device rules for the following requirements

#15 Post by Domosapiens » 08 Jan 2019, 17:56

I think there is a command:

Code: Select all

monitor,GPIO,<pin>
And I think

Code: Select all

On GPIO#<pin> Do
will give an event.

Mentioned here:
viewtopic.php?f=4&t=5868&p=31804&hilit= ... 2Cx#p31804

Also for:
monitor,PCF,<pin>
monitor,MCP,<pin>

Give it a try and share it with us.
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: Help you create the device rules for the following requirements

#16 Post by iron » 08 Jan 2019, 19:33

(I am working on MCP,5)

This works :

on system#boot do
monitor,mcp,5
endon

On mcp#5=1 do
Publish,/%sysname%/MCP/5,1
endon

On mcp#5=0 do
Publish,/%sysname%/MCP/5,0
endon

Wondering if it is possible to post the value of MCP#5 directly, instead of conditioning ?

On mcp#5 do
Publish,/%sysname%/MCP/5,<mcp#5>
endon

To get by with a single event ?

-D
-D

User avatar
iron
Normal user
Posts: 221
Joined: 24 Sep 2016, 08:37
Location: Greece
Contact:

Re: Help you create the device rules for the following requirements

#17 Post by iron » 08 Jan 2019, 19:43

On mcp#5 do
Publish,/%sysname%/MCP/5,%eventvalue%
endon

This seems to work...

-D
-D

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 14 guests