Page 1 of 1

MQTT input in rules

Posted: 03 May 2018, 15:41
by werner_g
My watering systems grows in line with all the plants in springtime. I have this rules working, and I receive MQTT-messages in my Node-RED:

Code: Select all

On startwatering do 
   Pulse,4,1,40
   Pulse,5,0,40 //start watering (open valve)
   Publish aussen/state/WM/Garten01/watering,startwatering
   timerSet,1,60 //timer 1 set for 1 minutes
endon
I need help - I have no idea how I can send a MQTT-message from Node-RED (or any other system) to open/close the valve.

Re: MQTT input in rules

Posted: 03 May 2018, 17:07
by grovkillen

Re: MQTT input in rules

Posted: 04 May 2018, 00:05
by werner_g
Thanks. So I modified my rules in adding the event-command:

Code: Select all

On startwatering do 
   Pulse,4,1,40
   Pulse,5,0,40 //start watering (open valve)
   Publish aussen/state/WM/Garten01/watering,startwatering
   event,MQTTwatering=startwatering
   timerSet,1,60 //timer 1 set for 1 minutes
endon
But nothing happens when I set this command:

Code: Select all

msg: aussen/state/WM/Garten01/watering/cmd
payload: event,MQTTwatering
So still I am looking for help.

Re: MQTT input in rules

Posted: 04 May 2018, 00:26
by grovkillen
werner_g wrote: 04 May 2018, 00:05 Thanks. So I modified my rules in adding the event-command:

Code: Select all

On startwatering do 
   Pulse,4,1,40
   Pulse,5,0,40 //start watering (open valve)
   Publish aussen/state/WM/Garten01/watering,startwatering
   event,MQTTwatering=startwatering
   timerSet,1,60 //timer 1 set for 1 minutes
endon
But nothing happens when I set this command:

Code: Select all

msg: aussen/state/WM/Garten01/watering/cmd
payload: event,MQTTwatering
So still I am looking for help.
You're calling an event that you have not defined, try this:

Code: Select all

payload: event,startwatering
And remove this one:

Code: Select all

event,MQTTwatering=startwatering

Re: MQTT input in rules

Posted: 04 May 2018, 09:36
by werner_g
so easy... thanks a lot, of course now it works!

Re: MQTT input in rules

Posted: 11 Jul 2018, 15:11
by joyNstay
Did this works if you want to set the rules for the lights too? I mean If you want to set a rule that opens the light and close it after 8 hours? or it is possible only for some seconds?
Thanks

Re: MQTT input in rules

Posted: 12 Jul 2018, 02:50
by waspie
joyNstay wrote: 11 Jul 2018, 15:11 Did this works if you want to set the rules for the lights too? I mean If you want to set a rule that opens the light and close it after 8 hours? or it is possible only for some seconds?
Thanks
the sky is the limit.

whatever is sending the mqtt should be able to send whenever you want it to...

Re: MQTT input in rules

Posted: 12 Jul 2018, 11:37
by joyNstay
Nice! If I understood correctly this rules can only me applied and change throw the website of ESP easy ,right? Is it possible to create a custom UI to change the rules? For example may be there are some numbers to the rules that I want to change with the press of a button? What should I look for?

Re: MQTT input in rules

Posted: 12 Jul 2018, 11:50
by grovkillen
Yes you can do that with dummy devices. Store the value with them.

Re: MQTT input in rules

Posted: 12 Jul 2018, 12:04
by joyNstay
I don't know if that will work... It seems that this is just commands in the rule section. When I wrote button I mean a visual button in the browser. Sorry for the confusion.

Re: MQTT input in rules

Posted: 12 Jul 2018, 12:34
by grovkillen
No problem to send HTTP commands using a web interface. Or what's the hiccups?

Re: MQTT input in rules

Posted: 12 Jul 2018, 14:34
by waspie
joyNstay wrote: 12 Jul 2018, 12:04 I don't know if that will work... It seems that this is just commands in the rule section. When I wrote button I mean a visual button in the browser. Sorry for the confusion.
i don't think the espeasy is really meant to be used as a control panel (of sorts). it's more for setting up the device to control things (motors, lights, etc). what you need is home automation software that sends the commands to the esp and then the esp makes it happen.


you need to be looking at openhab, domoticz, home assistant, etc.

Re: MQTT input in rules

Posted: 18 Jul 2018, 16:13
by joyNstay
So If I have understood currently ESPeasy is more to send an signal and the esp do it immediately and software like openhab is more hard coded and you have the logic in the esp( or sonoff)?

Re: MQTT input in rules

Posted: 18 Jul 2018, 22:13
by TD-er
joyNstay wrote: 18 Jul 2018, 16:13 So If I have understood currently ESPeasy is more to send an signal and the esp do it immediately and software like openhab is more hard coded and you have the logic in the esp( or sonoff)?
ESPeasy has a number of possibilities.
For example:
- Operate sensors/displays on a number of pins. (support for specific sensors is done in "Plugins" or "Tasks" as they are called in ESPeasy)
- Collect data from the sensors and do some simple computations on them. (Formulas at the bottom of each "plugin" page)
- Send sensor data to a number of typical data-collecting/processing units (they are called controllers in ESPeasy)
- Act on events and perform some time-based actions (Rules in ESPeasy)

Its possibilities are not limited to these, but in general it is the functionality of ESPeasy.

The controllers interface to some other tools, which are often more the general interface hubs of the home automation system.
For example Domoticz, OpenHAB, HomeAssistant, etc.

There is also a plugin called MQTT input, which is just plainly a hack, since it does not fit as plugin (a plugin interacts with hardware) and it is not used as a controller (what it should be)
Problem with the current implementation of controllers is that they're just sending data and not (yet) meant to collect data, so I get why it was written like it is now.

I hope it is now a bit more clear how each interacts with eachother.
N.B. this may (and will) change/shift in the future, but for now, that's how it is working.

Re: MQTT input in rules

Posted: 19 Jul 2018, 00:47
by joyNstay
Thank you for you reply but still nobody has answer my question. Can from the ESPeasy and maybe MQTT change the code from ESP( foe example sonoff)?
For example some how to say to sonoff turn on in 3 hour and after 4 hours turn off. And that will happened both when it is connected to the network and when it is not connected. I have found that it is possible throw MQTT message but MQTT works only when it is connected to the network because the message is turn onn/off NOW. I need a tool to do time scheduling. Do you know anything about that?

Re: MQTT input in rules

Posted: 19 Jul 2018, 08:06
by grovkillen
You can use event command and send a integer/float values as %eventvalue% and that value could be used as the timer duration.

Re: MQTT input in rules

Posted: 19 Jul 2018, 09:48
by wim16
And you might store the %eventvalue% in a dummy variable so that it is still available when there is no network connection.

Re: MQTT input in rules

Posted: 14 Sep 2020, 20:18
by kirelam
Dear IOT'ers,

Maybe someone here can help me also. My problem may be of a silimar one.

I have build a chickenbot with stepper motor in it driven on a Adafruit motorshield.
over HTTP the command works great, but now i am switching to MQTT.

No command seems to work :S

finally i found this thread, and it seems mayby i can solve my problem though a rule!

My rule right now in ESPEASY is:
This is just for testing, but it is an important one (otherwise the motor burns itself crisp)

on Chickenbot#Feeder=Release do
MotorShieldCMD,Stepper,1,Release
endon

My HA command is:
ChickenBot_4/Chickenbot (with the payload) Release

nothing happens :(

Regards,
Kirelam

Re: MQTT input in rules

Posted: 14 Sep 2020, 21:51
by Ath
There are at least a few misunderstandings in your code.
ESPEasy works with float and integer values. And though it is possible to trigger events based on string values, you can't store a string in a Dummy Device, so trying to send it over MQTT, to trigger an event on it, will not work.

Using "1" instead of "Release" should be able to work.

NB: I know nearly nothing about MQTT, so that side of the story I can't help you further, sorry.

Re: MQTT input in rules

Posted: 14 Sep 2020, 21:53
by TD-er
Sending commands via MQTT should be done via the subscribed topic + /cmd
So if you subscribe to the topic

Code: Select all

ChickenBot_4/Chickenbot 
you should publish the ESPEasy commands to

Code: Select all

ChickenBot_4/Chickenbot/cmd