MQTT subscribe does not fire event but issues "command unknown"

424 views
Skip to first unread message

FransOv

unread,
Dec 21, 2022, 9:36:02 AM12/21/22
to TasmotaUsers
I have a Tasmota device (ESP32CR D1 mini) decoding the datagrams from the P1 smart meter port and sending the sensors by MQTT to Home Assistant. The decoding is performed by a small Berry program. 
The next thing I want to do is to send the raw output from the P1 port to an EV-charger for dynamic load balancing. The distance is far more than the maximum length of a P1 data cable.
The idea is to place a tasmota device near the EV charger that subscribes to the RESULT topic with the SerialReceived key of the device that does the decoding.

I use the following rules:
  • on system#boot do backlog serialbuffer 999; baudrate 11500; serialsend1 1 endon on event#dsmr do serialsend3 %value% endon
  • on mqtt#connected do subscribe dsmr, tele/tasmota-esmr/RESULT, SerialReceived endon
The serialbuffer 999 is needed as the string received from the smart meter is quite long. It needs a change to INPUT_BUFFER_SIZE in tasmota.h. Tasmota was compiled with #define SUPPORT_MQTT_EVENT.
The mqtt messages are received, but the event does not fire. Instead I get a "Unknown command" each time a message arrives.
I must be doing something wrong, but I cannot figure out what.



Philip Knowles

unread,
Dec 21, 2022, 10:05:17 AM12/21/22
to FransOv, TasmotaUsers

There’s an easier way. If you have a device called EV-Charger

 

On the sender

On whatever do publish cmnd/EV-Charger/var1 %value% endon //sets var1 on the receiver to %value%

 

On the receiver

On var1#state do whatever endon // reacts to the change in var1

 

Sent from Mail for Windows

--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/b5d5065e-0c8b-449d-84a9-cca63de31762n%40googlegroups.com.

 

FransOv

unread,
Dec 21, 2022, 10:19:26 AM12/21/22
to TasmotaUsers
Thanks, I'll try that.

Op woensdag 21 december 2022 om 16:05:17 UTC+1 schreef knowles...@gmail.com:

FransOv

unread,
Dec 21, 2022, 10:47:56 AM12/21/22
to TasmotaUsers
The var's are not able to store those long strings(900> characters) but you pointed me in the direction to an even simpler solution that needed just one statement added to the berry program (the red one) :

def strReplace(haystack, needle, food)
  import string
  return string.split(haystack, needle).concat(food)
end

def decode(value, trigger, payload)
  import string
  import mqtt
  var codes={'1-0:1.8.1':'enrg_imp_t1','1-0:1.8.2':'enrg_imp_t2','1-0:2.8.1':'enrg_exp_t1','1-0:2.8.2':'enrg_exp_t2','0-0:96.14.0':'tariff','1-0:1.7.0':'pwr_imp','1-0:2.7.0':'pwr_exp','1-0:32.7.0':'volts_l1','1-0:52.7.0':'volts_l2','1-0:72.7.0':'volts_l3','1-0:31.7.0':'amps_l1','1-0:51.7.0':'amps_l2','1-0:71.7.0':'amps_l3','1-0:21.7.0':'l1_pwr_imp','1-0:41.7.0':'l2_pwr_imp','1-0:61.7.0':'l3_pwr_imp','1-0:22.7.0':'l1_pwr_exp','1-0:42.7.0':'l2_pwr_exp','1-0:62.7.0':'l3_pwr_exp'}

  var msg=string.split(str(value),"\r\n")
  var mqttmsg=map()
 
  for it: msg
    var it1=string.split(str(it),'(',1)
    var key=codes.find(it1[0])
    if (key!=nil)
      var val=string.split(it1[1],size(it1[1])-1)[0]
      val=string.split(val,'*')[0]
      mqttmsg.insert(key,number(val))
    end
  end
 
  mqtt.publish('tele/tasmota-esmr/DSMR5', strReplace(str(mqttmsg),"'",'"'))
  mqtt.publish('cmnd/tasmota-evc/serialsend3', value)
end

tasmota.add_rule("SerialReceived",decode)

Op woensdag 21 december 2022 om 16:19:26 UTC+1 schreef FransOv:
Reply all
Reply to author
Forward
0 new messages