Send MQTT to different topics?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
PieterS
Normal user
Posts: 87
Joined: 27 Mar 2018, 17:18
Location: NL

Send MQTT to different topics?

#1 Post by PieterS » 19 Mar 2024, 11:23

I have 2 energy-counters with Modbus (Eastron SDM630 and Eastron SDM120) in my garage and want to connect them together in one bus and to one controller (Lolin NodeMcu).
Is it possible to send data to different topics through MQTT from one NodeMcu to the same broker? One topic (for the SDM603) is domoticz/in and the second meter (SDM120M) should send to topic energy/goodwe.
In the software (Build: ESP_Easy_mega_20231130_energy_ESP8266_4M1M Nov 30 2023) I created a second MQTT controller with different topicname but that seems to be not allowed... Error: One one mqtt controller should be active. :?

Is there a solution for this problem? In tab Devices I can select a controller... :evil:

Or build another NodeMcu with another configuration of the topic: energy/goodwe

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

Re: Send MQTT to different topics?

#2 Post by TD-er » 19 Mar 2024, 12:22

You can send whatever you like via rules.
For example act on the event of a new measurement and send all values using the publish command.

See also documentation for formatting domoticz-syntax formatted messages: https://espeasy.readthedocs.io/en/lates ... er-parsing

Assuming your task is called "SDM2" and you have checked the checkbox to send all values in a single event (checkbox in the task config page)

Code: Select all

on sdm2#all do
  publish,"energy/goodwe/1",%eventvalue1%
  publish,"energy/goodwe/2",%eventvalue2%
  publish,"energy/goodwe/3",%eventvalue3%
  publish,"energy/goodwe/4",%eventvalue4%
endon
Or if you need the values all in a single message:

Code: Select all

  publish,"energy/goodwe","%eventvalue1%,%eventvalue2%,%eventvalue3%,%eventvalue4%"

PieterS
Normal user
Posts: 87
Joined: 27 Mar 2018, 17:18
Location: NL

Re: Send MQTT to different topics?

#3 Post by PieterS » 19 Mar 2024, 16:24

Thnx Gijs for quick reply and examples.

I forgot to tell that data from the SDM120 must be sent via broker to 2 different destinations. The one to Domoticz is clear to me.

This is the rule:

Code: Select all

On SDM_Goodwe#All Do  
  Publish,energy/goodwe,'{"command":"udevice","idx":2506,"nvalue":0,"svalue":"%eventvalue1%"}' 
  Publish,energy/goodwe,'{"command":"udevice","idx":2507,"nvalue":0,"svalue":"%eventvalue2%"}' 
  Publish,energy/goodwe,'{"command":"udevice","idx":2508,"nvalue":0,"svalue":"%eventvalue3%"}'  
  Publish,energy/goodwe,'{"command":"udevice","idx":2509,"nvalue":0,"svalue":"%eventvalue4%"}'
Endon
The second destination is to Node-Red...
I am able to simulate that proces by sending a message by Publish in MQTT Explorer. The data is picked up by the flow and send correctly to PVoutput.org.. :P

Hopefully tomorrow I recieve the new SDM120M and in the mean time I can figure out how to edit the MQTT-node in NodeRED.. Or create a rule in ESPeasy for NodeRED..

The message I publish is for example:

Code: Select all

{{"pvpowerout": 130, "pvenergytoday": 2400}}


I must rearrange that in the rule I guess with some extra text. That is the goal for this evening. :)

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

Re: Send MQTT to different topics?

#4 Post by TD-er » 19 Mar 2024, 16:40

Just as a tip, you can easily test your strings by sending them to log using the command "logentry".
This also does all string replacements.

Code: Select all

//Publish,energy/goodwe,'{"command":"udevice","idx":2509,"nvalue":0,"svalue":"%eventvalue4%"}'
  logentry,'{"command":"udevice","idx":2509,"nvalue":0,"svalue":"%eventvalue4%"}'

Post Reply

Who is online

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