Last active
October 7, 2025 02:57
-
-
Save meee1/72d8a2da74637aae66dc3112f446963c to your computer and use it in GitHub Desktop.
shelly script to victron mqtt - using https://github.com/mr-manuel/venus-os_dbus-mqtt-grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; CONFIG FILE | |
| ; GitHub reporitory: https://github.com/mr-manuel/venus-os_dbus-mqtt-grid | |
| ; remove semicolon ; to enable desired setting | |
| [DEFAULT] | |
| ; Set logging level | |
| ; ERROR = shows errors only | |
| ; WARNING = shows ERROR and warnings | |
| ; INFO = shows WARNING and running functions | |
| ; DEBUG = shows INFO and data/values | |
| ; default: WARNING | |
| logging = WARNING | |
| ; Device name | |
| ; default: MQTT Grid | |
| device_name = MQTT Grid 40 | |
| ; Device type | |
| ; grid = Grid | |
| ; genset = Generator | |
| ; acload = AC Load (does not impact calculations, shows only under devices) | |
| device_type = grid | |
| ; Device VRM instance | |
| ; default: 100 | |
| device_instance = 40 | |
| ; Specify after how many seconds the driver should exit (disconnect), if no new MQTT message was received | |
| ; default: 60 | |
| ; value to disable timeout: 0 | |
| timeout = 10 | |
| ; used when no voltage is received | |
| voltage = 230 | |
| ; used when no frequency is received | |
| frequency = 50 | |
| ; power limit per phase, to filter out wrong values | |
| ; default: 23000 | |
| ; which are 100 A at 230 V | |
| power_threshold_per_phase = 23000 | |
| [MQTT] | |
| ; IP addess or FQDN from MQTT server | |
| ; "localhost" is allowed, can be used if mqtt server is enabled in venusOS | |
| broker_address = localhost | |
| ; Port of the MQTT server | |
| ; default plaintext: 1883 | |
| ; default TLS port: 8883 | |
| broker_port = 1883 | |
| ; Enables TLS | |
| ; 0 = Disabled | |
| ; 1 = Enabled | |
| ;tls_enabled = 1 | |
| ; Absolute path to the Certificate Authority certificate file that is to be treated as trusted by this client | |
| ;tls_path_to_ca = /data/keys/mosquitto.crt | |
| ; Disables verification of the server hostname in the server certificate | |
| ; 0 = Disabled | |
| ; 1 = Enabled | |
| ;tls_insecure = 1 | |
| ; Username used for connection | |
| ;username = myuser | |
| ; Password used for connection | |
| ;password = mypassword | |
| ; Topic where the grid data as JSON string is published | |
| ; minimum required JSON payload: {"grid": { "power": 0.0 } } | |
| topic = power/gridmeter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //https://github.com/mr-manuel/venus-os_dbus-mqtt-grid | |
| let CONFIG = { | |
| switchId: 0, | |
| MQTTPublishTopic: "shellypro3em-08f9e0e9cf04/events/rpc", | |
| }; | |
| let count =0; | |
| let power = 0; | |
| function timerCode() { | |
| let data = Shelly.getComponentStatus("em:0"); | |
| let data2 = Shelly.getComponentStatus("emdata:0"); | |
| let announceObj = { | |
| "src": "shellypro3em-08f9e0e9cf04", | |
| "dst": "shellypro3em-08f9e0e9cf04/events", | |
| "method": "NotifyStatus", | |
| params: { | |
| 'em:0': data, | |
| }, | |
| }; | |
| power = power * 0 + ((data.b_act_power+data.c_act_power) * 1.0); | |
| let mqtt = { | |
| "grid": { | |
| "power": power, | |
| "current": data.b_current +data.c_current , | |
| "energy_forward": data2.c_total_act_energy / 1000 + data2.b_total_act_energy / 1000, | |
| "energy_reverse": data2.c_total_act_ret_energy / 1000 + data2.c_total_act_ret_energy / 1000, | |
| "L1": { | |
| "power": data.b_act_power , | |
| 'voltage': data.b_voltage , | |
| 'current': data.b_current , | |
| 'power_factor': data.b_pf, | |
| 'frequency': data.b_freq, | |
| "energy_forward": data2.b_total_act_energy / 1000, | |
| "energy_reverse": data2.b_total_act_ret_energy / 1000, | |
| }, | |
| "L2": { | |
| "power": data.c_act_power , | |
| 'voltage': data.c_voltage , | |
| 'current': data.c_current , | |
| 'power_factor': data.c_pf, | |
| 'frequency': data.c_freq , | |
| "energy_forward": data2.c_total_act_energy / 1000, | |
| "energy_reverse": data2.c_total_act_ret_energy / 1000, | |
| }, | |
| "L3": { | |
| "power": 0 | |
| } | |
| } | |
| }; | |
| count++; | |
| if (count > 2) { | |
| //MQTT.publish(CONFIG.MQTTPublishTopic, JSON.stringify(announceObj), 0, false); | |
| count=0; | |
| } | |
| MQTT.publish("power/gridmeter", JSON.stringify(mqtt), 0, false); | |
| }; | |
| Timer.set( | |
| /* number of miliseconds */ 500, | |
| /* repeat? */ true, | |
| /* callback */ timerCode | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment