Skip to content

Instantly share code, notes, and snippets.

@dgehriger
Created March 4, 2025 21:07
Show Gist options
  • Save dgehriger/87580c563b693e5077db1c3d74c4b9ab to your computer and use it in GitHub Desktop.
Save dgehriger/87580c563b693e5077db1c3d74c4b9ab to your computer and use it in GitHub Desktop.
gPlug-M Meter Script for SIL
>D 48
; Your encryption key
KEY="4cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
; The meter ID
METER_ID="1234567"
; Variables
uptime_hours=0
sensor_reset=0
sensor_send=0
red_led_blink=0
led_delay_ms=750
no_wifi_s=0
; Pins
red_led_pin=1
blue_led_pin=3
green_led_pin=4
button_a_pin=9
; =================================
; BOOT SECTION
; =================================
>B
; Upon boot, disable publishing at MQTT teleperiod
smlj=0
; Enable mDNS
->setOption55 1
; Activate data parsing
->sensor53 r
; Enable green LED to indicate serial activity
->sensor53 l4
; =================================
; BOOT SECTION (AFTER SENSOR INIT)
; =================================
>BS
; Configure LED pins
spinm(blue_led_pin O)
spinm(green_led_pin O)
spinm(red_led_pin O)
; Lightshow at startup
spin(red_led_pin 1)
delay(led_delay_ms)
spin(red_led_pin 0)
spin(green_led_pin 1)
delay(led_delay_ms)
spin(green_led_pin 0)
spin(blue_led_pin 1)
delay(led_delay_ms)
spin(blue_led_pin 0)
; Referrer check
->setOption128 ON
; Dynamic WiFi Tx power
->wifipower 0
; MQTT Period 10 s (minimum possible)
->teleperiod 10
; =================================
; METER CONFIG
; =================================
>M 1
+1,7,r,0,2400,
1,=so2,0c
1,=so3,128
1,=so4,%KEY%
1,=h<hr/>
1,=h<h4>Instant Power<h4/>
1,0212x24U32@1,Pi ___ 1_7,W,Pi,0
1,0212x29U32@1,Pe ___ 2_7,W,Pe,0
1,0212x62U32@1,PiL1 ___ 21_7,W,PiL1,0
1,0212x67U32@1,PiL2 ___ 41_7,W,PiL2,0
1,0212x72U32@1,PiL3 ___ 61_7,W,PiL3,0
1,0212x77U32@1,PoL1 ___ 22_7,W,PoL1,0
1,0212x82U32@1,PoL2 ___ 42_7,W,PoL2,0
1,0212x87U32@1,PoL3 ___ 62_7,W,PoL3,0
1,0212x34U32@1,Qi ___ 3_7,VAr,Qi,0
1,0212x39U32@1,Qo ___ 4_7,VAr,Qo,0
1,=h<hr/>
1,=h<h4>Instant Voltage<h4/>
1,0212x44UUuu@1,U1 ___ 32_7,V,U1,0
1,0212x47UUuu@1,U2 ___ 52_7,V,U2,0
1,0212x50UUuu@1,U3 ___ 72_7,V,U3,0
1,=h<h4>Instant Current<h4/>
1,0212x53UUuu@100,I1 ___ 31_7,A,I1,2
1,0212x56UUuu@100,I2 ___ 51_7,A,I2,2
1,0212x59UUuu@100,I3 ___ 71_7,A,I3,2
1,=h<hr/>
1,=h<h4>Real Energy Counters<h4/>
1,020fx87U32@1000,Ei ___ 1_8_0,kWh,Ei,1
1,020fx92U32@1000,Ee ___ 2_8_0,kWh,Eo,1
1,020fx47U32@1000,Ei1 ___ 1_8_1,kWh,Ei1,1
1,020fx52U32@1000,Ei2 ___ 1_8_2,kWh,Ei2,1
1,020fx57U32@1000,Ee1 ___ 2_8_1,kWh,Eo1,1
1,020fx62U32@1000,Ee2 ___ 2_8_2,kWh,Eo2,1
1,=h<hr/>
1,=h<h4>Reactive Energy Counters<h4/>
1,020fx97U32@1000,EiQ ___ 3_8_0,kVArh,EiQ,1
1,020fx102U32@1000,EeQ ___ 4_8_0,kVArh,EoQ,1
1,020fx67U32@1000,EiQ1 ___ 3_8_1,kVArh,EiQ1,1
1,020fx72U32@1000,EiQ2 ___ 3_8_2,kVArh,EiQ2,1
1,020fx77U32@1000,EeQ1 ___ 4_8_1,kVArh,EoQ1,1
1,020fx82U32@1000,EeQ2 ___ 4_8_2,kVArh,EoQ2,1
1,=h<hr/>
1,=h<h4>Date<h4/>
1,0212x11UUuu@1,Year,,year,0
1,0212x13uu@1,Month,,month,0
1,0212x14uu@1,Day,,day,0
1,0212x16uu@1,Hour,,hour,0
1,0212x17uu@1,Min,,min,0
1,0212x18uu@1,Sec,,sec,0
#
; =================================
; EVERY 1 s
; =================================
>S
uptime_hours=uptime/60
; Start publishing after 1 min to ensure receipt of counter values
if upsecs>65 {
smlj|=1
}
; If no wifi connection after 10 sec, blink red
if wifis==0 {
no_wifi_s+=1
}
if no_wifi_s>10 {
red_led_blink=2
}
; =================================
; EVERY 100 ms
; =================================
>F
if red_led_blink > 0 {
spin(red_led_pin 1)
red_led_blink -= 1
no_wifi_s = 0
} else {
spin(red_led_pin 0)
}
; =================================
; Publish to MQTT
; =================================
>J
; =================================
; Web UI
; =================================
>W
@<style>h4{margin-block-end: 0;color: cyan}td th{font-weight: normal;}tr th:first-child{text-align: left;}tr td:nth-child(2){text-align: right;color: lime;font-weight:normal;}table{font-family: Inter, sans-serif ;width:100\%}</style>
@<table><tbody>
<tr><th>L+G E450 (SIL)</th><td></td></tr>
<tr><th>Data Update Period</th><td>5 s</td></tr>
<tr><th>Counter Update Period</th><td>60 s</td></tr>
<tr><th>Meter-ID</th><td>%METER_ID%</td></tr>
<tr><th>Date \& Time</th><td>%tstamp%</td></tr>
<tr><th>Uptime</th><td> %2uptime_hours% h</td></tr>
</tbody></table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment