Send commands by MQTT to ESPeasy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
simon2023
New user
Posts: 4
Joined: 18 Aug 2023, 19:43

Send commands by MQTT to ESPeasy

#1 Post by simon2023 » 22 Aug 2023, 11:38

My aim
I want to send commandy by MQTT to my ESP8266.

Status
  • ESPeasy is running smoothly.
  • ESP is connected to my MQTT Server and the ESP sends messages by MQTT to the server. I just receive a test message send every X seconds. I can check with MQTT explorer that messages are sent from ESP to the MQTT server.
Problem
I cannot see that the ESP receives MQTT messages or reacts on MQTT messages.

Rule

Code: Select all

on MQTT#ESP8266_NAS/power_off=on do
  logentry,"power_off = %eventvalue%"
  gpio,D6,1 // Turn light on
  TimerSet 1,10 //Timer 1 waits 10 seconds, then action below is done
endon
Linked tutorials
https://nerdiy.de/de_de/howto-espeasy-m ... bonnieren/

Update:
I now read that you can directly send commands via MQTT like that:
topic: /%sysname%/gpio/12/cmd
to power GPIO 12
payload: „Pulse,12,1,500“
to set GPIO 12 to high (1) for 500 ms.

Log
The configuration of MQTT, subscribed topic and

Code: Select all

8102568: WD   : Uptime 135 ConnectFailures 0 FreeMem 19736 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8132568: WD   : Uptime 136 ConnectFailures 0 FreeMem 19736 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8161195: ADC  : Analog value: 0 = 0.00
8161207: EVENT: send2#Analog=2.00
8162568: WD   : Uptime 136 ConnectFailures 0 FreeMem 19736 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8192568: WD   : Uptime 137 ConnectFailures 0 FreeMem 19736 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8194331: Upload: START, filename: rules1.txt
8194586: Upload: WRITE, Bytes: 514
8194588: Upload: END, Size: 514
8194807: ESPEasy console using ESPEasySerial
8209591: Upload: START, filename: rules1.txt
8209697: Upload: WRITE, Bytes: 517
8209698: Upload: END, Size: 517
8209945: ESPEasy console using ESPEasySerial
8221197: ADC  : Analog value: 0 = 0.00
8221210: EVENT: send2#Analog=2.00
8222568: WD   : Uptime 137 ConnectFailures 0 FreeMem 20344 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8252568: WD   : Uptime 138 ConnectFailures 0 FreeMem 20344 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8281195: ADC  : Analog value: 0 = 0.00
8281212: EVENT: send2#Analog=2.00
8282568: WD   : Uptime 138 ConnectFailures 0 FreeMem 20344 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
8312568: WD   : Uptime 139 ConnectFailures 0 FreeMem 20344 WiFiStatus 3 ESPeasy internal wifi status: Conn. IP Init
Attachments
MQTT explorer
MQTT explorer
Clipboarder.2023.08.22-004.png (229.09 KiB) Viewed 1251 times
Rules
Rules
Clipboarder.2023.08.22-002.png (56.27 KiB) Viewed 1251 times
MQTT config in ESP
MQTT config in ESP
Clipboarder.2023.08.22.png (180.65 KiB) Viewed 1251 times

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Send commands by MQTT to ESPeasy

#2 Post by TD-er » 22 Aug 2023, 12:36

You need to keep in mind to which topic(s) you subscribe with your MQTT controller.
This means you need to publish to topics (with cmd in the topic) which are part of the subscriptions of that node.

The only controller supporting commands (right now) is the OpenHab/HomeAssistant controller.
So if you're using any of the other MQTT controllers, you will not be able to send commands to ESPEasy.

I think you already found this page, but just to be sure:
https://espeasy.readthedocs.io/en/lates ... d-handling

If you just need to act on values sent by others to some topic, you can also have a look at the MQTT import plugin.

User avatar
Ath
Normal user
Posts: 3520
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Send commands by MQTT to ESPeasy

#3 Post by Ath » 22 Aug 2023, 13:11

Handling events via rules doesn't support responding to string/text values, like you have, that should either be not specified, or a numeric value, or an asterisk to allow textual values as the first argument:

Code: Select all

on MQTT#ESP8266_NAS/power_off=0 do
  logentry,"power_off = %eventvalue%"
  gpio,D6,1 // Turn light on
  TimerSet 1,10 //Timer 1 waits 10 seconds, then action below is done
endon
String values can be used in logentries and commands sent to other systems, but you can't do comparisons on those values, so that requires the MQTT Import plugin, like TD-er already suggested. You'll need the Mapping feature of that plugin for that, but I'm not sure if that's included in the Climate build. In that case you'd need a self-built Custom build, use a Normal build that has the full feature set of MQTT Import, or switch to an ESP32, that has somewhat less restrictions in .bin size, and also has the full feature set of MQTT Import.
When using the MQTT Import plugin, you can handle the event properly, with the payload converted to a numeric value, but you can also send that on/off value numeric like 1/0, that would solve it too.

I assume you also have some code to handle the timer you just started?
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Send commands by MQTT to ESPeasy

#4 Post by TD-er » 22 Aug 2023, 13:22

If you decide to switch to an ESP32, please pick one with 16M flash.
This allows you to use the "Max" builds

Post Reply

Who is online

Users browsing this forum: No registered users and 29 guests