Page 1 of 1

Help you create the device rules for the following requirements

Posted: 27 Sep 2018, 13:04
by lyovav
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

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

Posted: 27 Sep 2018, 17:35
by grovkillen
What are you wanting from us exactly?

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

Posted: 27 Sep 2018, 17:51
by lyovav
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...

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

Posted: 27 Sep 2018, 18:05
by grovkillen
https://www.letscontrolit.com/wiki/inde ... noff_basic

And for MQTT etc look at the tutorial

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

Posted: 29 Sep 2018, 20:40
by lyovav
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.

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

Posted: 29 Sep 2018, 22:30
by grovkillen
You send event,lamp_on or event,lamp_off to topic /Sonoff_1M/cmd and you get the and result.

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

Posted: 30 Sep 2018, 08:23
by lyovav
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

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

Posted: 30 Sep 2018, 09:00
by grovkillen
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

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

Posted: 30 Sep 2018, 09:14
by lyovav
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.

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

Posted: 30 Sep 2018, 09:17
by grovkillen
Ok I understand, but consider using my suggested change in the rule. It'll make it easier to maintain.

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

Posted: 30 Sep 2018, 09:32
by lyovav
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.

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

Posted: 07 Jan 2019, 20:30
by iron
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

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

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

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

Posted: 08 Jan 2019, 11:25
by iron
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

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

Posted: 08 Jan 2019, 17:56
by Domosapiens
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.

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

Posted: 08 Jan 2019, 19:33
by iron
(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

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

Posted: 08 Jan 2019, 19:43
by iron
On mcp#5 do
Publish,/%sysname%/MCP/5,%eventvalue%
endon

This seems to work...

-D