Skip to content

Commit 0b2d19a

Browse files
authored
add shelly pro 3em emulation
1 parent f946b0c commit 0b2d19a

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed

docs/Smart-Meter-Interface.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3905,6 +3905,237 @@ Script to extract readings from Eastron [SDM72D Series](https://www.eastroneurop
39053905
#
39063906
```
39073907

3908+
### Shelly PRO 3EM emulation
3909+
script to emulate a shelly pro 3em to use with solar storage devices e.g. marstek
3910+
3911+
??? summary "View script"
3912+
```
3913+
>D 250
3914+
; this script emulates a shelly pro, with small modifications may also emulate an ecotracker
3915+
; proven to work an marstek Venus, Jupiter and B2500
3916+
res=0
3917+
c1p=0
3918+
c2p=0
3919+
c3p=0
3920+
c1c=0
3921+
c2c=0
3922+
c3c=0
3923+
cpwr=0
3924+
str=""
3925+
tstr=""
3926+
cstr=""
3927+
mstr1=""
3928+
mstr2=""
3929+
mstr3=""
3930+
header=""
3931+
once=0
3932+
3933+
>B
3934+
=>sensor53 r
3935+
; if you modify this section you must restart tasmota
3936+
3937+
>ah
3938+
; http rpc handler
3939+
res=won(1 "/rpc/*")
3940+
; http status
3941+
res=won(2 "/status")
3942+
; http ecotacker status
3943+
res=won(3 "/v1/json")
3944+
3945+
>on1
3946+
;print here comes http rpc request
3947+
str=warg
3948+
res=ins(str "EM.GetStatus")
3949+
if res>=0 {
3950+
wcs so(4)
3951+
=#htph
3952+
wcs %mstr1%
3953+
=#getsrc
3954+
wcs %header%
3955+
=#getstat
3956+
wcs %mstr1%
3957+
wcs %mstr2%
3958+
wcf
3959+
break
3960+
}
3961+
res=ins(str "Shelly.GetDeviceInfo")
3962+
if res>=0 {
3963+
wcs so(4)
3964+
=#htph
3965+
wcs %mstr1%
3966+
=#getsrc
3967+
=#getdefi
3968+
wcs %header%
3969+
wcs %mstr1%
3970+
wcs %mstr2%
3971+
wcf
3972+
break
3973+
}
3974+
res=ins(str "EM.GetConfig")
3975+
if res>=0 {
3976+
wcs so(4)
3977+
=#htph
3978+
wcs %mstr1%
3979+
=#getsrc
3980+
=#getcfg
3981+
wcs %header%
3982+
wcs %mstr1%
3983+
wcf
3984+
break
3985+
}
3986+
res=ins(str "EMData.GetStatus")
3987+
if res>=0 {
3988+
wcs so(4)
3989+
=#htph
3990+
wcs %mstr1%
3991+
=#getsrc
3992+
=#egetstat
3993+
wcs %header%
3994+
wcs %mstr1%
3995+
wcf
3996+
break
3997+
}
3998+
3999+
print unknown http equest: %str%
4000+
4001+
>on2
4002+
;print here comes the status request
4003+
wcs so(4)
4004+
=#htph
4005+
wcs %mstr1%
4006+
dp(0 2)
4007+
wcs {"Power": %cpwr%,"E_in":%sml[1]%,"E_out":%sml[2]%}
4008+
wcf
4009+
4010+
>on3
4011+
;print here comes the v1/json for ecotracker
4012+
wcs so(4)
4013+
=#htph
4014+
wcs %mstr1%
4015+
dp(0 2)
4016+
wcs {"energyCounterIn":%sml[1]%,"energyCounterOut":%sml[2]%,"powerAvg":%cpwr%,"energyCounterInT1":0,
4017+
wcs "energyCounterInT2":0,"power":%cpwr%}
4018+
wcf
4019+
4020+
#htph
4021+
mstr1="HTTP/1.1 200 OK\r\nContent-type: application/json\r\n\r\n"
4022+
4023+
#getcfg
4024+
mstr1="{\"id\":0,\"name\":null,\"blink_mode_selector\":\"active_energy\",\"phase_selector\":\"a\",\"monitor_phase_sequence\":true,\"ct_type\":\"120A\"}}"
4025+
4026+
#getdefi
4027+
mstr1="{\"name\":\""+tstr+"\",\"id\":\""+tstr+"\",\"mac\":\""+maca+"\",\"slot\":1,\"model\":\"SPEM-003CEBEU\","
4028+
mstr2="\"gen\":2,\"fw_id\":\"20241011-114455/1.4.4-g6d2a586\","
4029+
mstr2+="\"ver\":\"1.4.4\",\"app\":\"Pro3EM\",\"auth_en\":0,\"profile\":\"triphase\"}}"
4030+
4031+
#getstat
4032+
dp(0 2)
4033+
mstr1="{\"id\":0,\"a_current\":"+s(c1c)+",\"a_voltage\":230,\"a_act_power\":"+s(c1p)+",\"a_aprt_power\":"+s(c1p)+",\"a_pf\":1,\"a_freq\":50,"
4034+
mstr1+="\"b_current\":"+s(c2c)+",\"b_voltage\":230,\"b_act_power\":"+s(c2p)+",\"b_aprt_power\":"+s(c2p)+",\"b_pf\":1,\"b_freq\":50,"
4035+
mstr2="\"c_current\":"+s(c3c)+",\"c_voltage\":230,\"c_act_power\":"+s(c3p)+",\"c_aprt_power\":"+s(c3p)+",\"c_pf\":1,\"c_freq\":50,"
4036+
mstr2+="\"total_current\":"+s(c1c+c2c+c3c)+",\"total_act_power\":"+s(cpwr)+",\"total_aprt_power\":"+s(cpwr)+"}}"
4037+
4038+
#egetstat
4039+
dp(0 2)
4040+
mstr1="{\"id\":0,\"a_total_act_energy\":"+s(c1p)+",\"a_total_act_ret_energy\":"+s(c1p)+",\"b_total_act_energy\":"+s(c2p)+",\"b_total_act_ret_energy\":"+s(c2p)+",\"c_total_act_energy\":"+s(c3p)+",\"c_total_act_ret_energy\":"+s(c3p)+",\"total_act\":"+s(cpwr)+",\"total_act_ret\":"+s(cpwr)+"}}"
4041+
4042+
#getsrc
4043+
tstr="shellypro3em-"+maca
4044+
header="{\"id\":0,\"src\":\""+tstr+"\",\"result\":"
4045+
4046+
>S
4047+
if year<2000 {
4048+
break
4049+
}
4050+
4051+
; adapt this to your meter
4052+
; update every 3 seconds
4053+
if upsecs%3==0 {
4054+
cpwr=sml[3]
4055+
c1p=sml[4]
4056+
c2p=sml[5]
4057+
c3p=sml[6]
4058+
}
4059+
4060+
; use this if you only have only one phase meter values
4061+
;c1p=cpwr/3
4062+
;c2p=cpwr/3
4063+
;c3p=cpwr/3
4064+
4065+
; calculate phase currents
4066+
c1c=c1p/230
4067+
c2c=c2p/230
4068+
c3c=c3p/230
4069+
4070+
if once==0 {
4071+
; start mdns for Shelly second parameter "-" means use device mac
4072+
res=mdns("shellypro3em-" "-" "shelly")
4073+
; start udp rpc handler on port 1010 or on port 2220 (for b2500)
4074+
res=udp(0 1010)
4075+
;res=udp(0 2220)
4076+
once=1
4077+
}
4078+
4079+
; evaluate udp input
4080+
str=udp(1)
4081+
if str!="" {
4082+
;print udp rpc payload=%str%
4083+
res=ins(str "EM.GetStatus")
4084+
if res>=0 {
4085+
=#getsrc
4086+
=#getstat
4087+
udp(2 header mstr1 mstr2)
4088+
;print >> %header%
4089+
;print >> %mstr1%
4090+
;print >> %mstr2%
4091+
break
4092+
}
4093+
4094+
res=ins(str "Shelly.GetDeviceInfo")
4095+
if res>=0 {
4096+
=#getsrc
4097+
=#getdefi
4098+
udp(2 header mstr1 mstr2)
4099+
;print >> 1 %mstr1%
4100+
;print >> 2 %mstr2%
4101+
break
4102+
}
4103+
4104+
res=ins(str "EM.GetConfig")
4105+
if res>=0 {
4106+
=#getsrc
4107+
=#getcfg
4108+
udp(2 header mstr1)
4109+
;print >> 1 %mstr1%
4110+
break
4111+
}
4112+
4113+
res=ins(str "EMData.GetStatus")
4114+
if res>=0 {
4115+
=#getsrc
4116+
=#egetstat
4117+
udp(2 header mstr1)
4118+
;print >> 1 %mstr1%
4119+
break
4120+
}
4121+
}
4122+
4123+
; adapt your own meter descriptor here
4124+
>M 1
4125+
+1,5,o,16,9600,eBZ,4
4126+
1,1-0:1.8.0*255(@1,Verbrauch,kWh,E_in,3
4127+
1,1-0:2.8.0*255(@1,Einspeisung,kWh,E_out,3
4128+
1,1-0:16.7.0*255(@1,akt. Leistung,W,Power,0
4129+
1,1-0:36.7.0*255(@1,Leistung L1,W,36_7_0,0
4130+
1,1-0:56.7.0*255(@1,Leistung L2,W,56_7_0,0
4131+
1,1-0:76.7.0*255(@1,Leistung L3,W,76_7_0,0
4132+
1,1-0:32.7.0*255(@1,Spannung L1,V,32_7_0,1
4133+
1,1-0:52.7.0*255(@1,Spannung L2,V,52_7_0,1
4134+
1,1-0:72.7.0*255(@1,Spannung L3,V,72_7_0,1
4135+
1,1-0:96.1.0*255(@#),Identifikation,,96_1_0,0
4136+
#
4137+
```
4138+
39084139
### Sorel LTDC (CANBus)
39094140

39104141
Compile firmware with #define ```USE_SML_CANBUS```. Use a proper CAN transceiver. You need a 120Ohms resistor in the second CAN port of the controller, otherwise ESP32 device will not decode anything on the bus, the baudrate is 250 KBITS.

0 commit comments

Comments
 (0)