Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future Enhancement - MQTT #1

Closed
PhillyGilly opened this issue Oct 13, 2022 · 16 comments
Closed

Future Enhancement - MQTT #1

PhillyGilly opened this issue Oct 13, 2022 · 16 comments

Comments

@PhillyGilly
Copy link

Hello @RichardL64 this is a really neat project. I am going to install a Solis S6 inverter next week (whilst waiting ever longer delayed GivEnergy hybrid inverter) and have a crack at this. I have used the Arduino nano33 to monitor power in circuits via a Clamp Transformer so this looks like a good next project.
Which RS485 interface did you use? I can see HW-0519 on the circuit board but need another pointer.
I had trouble sourcing the Exceedconn plug but think I may have found a reliable UK source for those.
And to the point....my power meter publishes data via MQTT so that I can view/log in Home Assistant. Did you ever consider that? When I have made a bit of progress on the local version I may be able to create an MQTT capable version to feed-back if that helps?

@RichardL64
Copy link
Owner

Hi @PhillyGilly

I picked up this from Ebay UK - from a seller called Puretek.
They seem to be reasonably generic - the only gotcha being the silkscreen for the RS485 cables is marked back to front - so if it doesn’t work - swap the cables.

XY-017 3.3v 5v 12v RS485 TO TTL RS485 SP3485 RS-485 Breakout For Arduino RPi

https://www.ebay.co.uk/itm/274273632839

The Arduino seems more than cabable of relaying 1 second resolution across 10-12 attributes + even storing data locally to an SD (which I’ve not debugged as yet). Certainly plenty of oomph to integrate an MQTT library and post there.

I thought about home assistant - nothing wrong with it; but went this route for a few reasons:

  • The challenge - a little bit of coding
  • Arduino is slim - no O/S
  • Raspberry Pi is/was short on supply
  • Minimal software hardware stack - no cloud, less to break etc.

I’ve also found a thing called a Arduino Wemos D1 - which is a perfect client too this and can display simple red/amber/green lights + operate an external relay depending on solar availability.

I’m sure you could well do this with home assistant etc - I guess at the end of the day I preferred debugging a few hundred lines of code than configuration files :)

Regards;

@PhillyGilly
Copy link
Author

Hello @RichardL64. Thanks for the helpful reply.
I got the Puretek part thanks and am waiting on delivery of 50(!) sockets from China.
I like to do Fritzing sketches for all my Arduino projects and it it's any use here is one for this project (although I may have the TX to RX wrong bearing in mind your comment about the screen printing.)

ArduinoRS485_bb

My Solis inverter is a six month fix to non-availability of GivEnergy G2 kit, and it's there working away without either a dongle or meter/CT which I don't want to buy. So my only option to get data is to work locally with the RS485. As I've got HA up and running (RPi4 with SSD) with a lot of my energy consumption data it suits me best to get the inverter data in there too.

The coding approach I used for my Arduino energy meter was to use the MQTT pubsub.h then; 1. on initialisation publish a json file containing the HA auto-discovery data, and 2. periodically publish the json data to be read by HA. It looks like I can merge this approach into your code.

However before I get on with it, I am wondering about whether or not it will actually work without a meter/CT. So I think I'll probably knock up an exact copy of your project and If it doesn't produce the data I need, decide if I just use my Arduino MQTT energy or have fun adding the ADS115 adc as well as the MQTT. Happy days!

Cheers.

@RichardL64
Copy link
Owner

RichardL64 commented Oct 26, 2022 via email

@PhillyGilly
Copy link
Author

Hi Richard. I just got delivery from Alibaba of the plugs. When I tested the +5V on my inverter its dead. I'm assuming that's because it goes to sleep when there is no PV? Is that your experience? I'm not sure how I feel about my nano33 rebooting multiple times per day. Cheers. Phil

@RichardL64
Copy link
Owner

RichardL64 commented Nov 10, 2022 via email

@PhillyGilly
Copy link
Author

PhillyGilly commented Nov 17, 2022

Hi @RichardL64 . I tested my inverter with a voltmeter across the pins (Blue: pin4 = 1.6v, Yellow: pin3 = 3.2v) and it definitely powers the RS485 down if the sun isn't shining so I'll probably keep the nano USB powered for the time being.
I also finally got delivery from China of the Exceedconn plugs and sockets. (I have put the remainder on sale on eBay http://ebay.co.uk/itm/195464332269 although I don't expect to make money on it, somebody else might want/need these parts).
Before attempting any serious coding, I got the example ModbusRTUClientKitchenSink sketch from the IDE, cut out all the calls apart from requestFrom, and compiled it to the nano. It runs and returns 1 to ModbusRTUClient.begin(9600), but the requestFrom fails with an error "Connection timeout" whatever register address used and for both combinations of AB inputs. I'm really scratching my head, but there's no point in going any further until I can get the underlying comms working. I have ordered a USB/RS485 plug to test the comms directly from my laptop. But meanwhile, any ideas however basic would be appreciated. TIA.

@RichardL64
Copy link
Owner

RichardL64 commented Nov 17, 2022 via email

@PhillyGilly
Copy link
Author

Agreed, the display is also off when not generating. I will re-check the 5V line tonight, but when I "commissioned" it, I worked in the evening to minimise DC risks. After it was all set up, I closed the MCB and turned on the AC isolator and nothing happened. I was convinced I'd made a mistake, but the next morning when I tried again it was working. I guess that Standard Stick is designed to power down and then power up?

@PhillyGilly
Copy link
Author

It's a configurable option in the Advanced settings. 24H Switch. Default is Disabled, but if you Enable it the inverter doesn't go to sleep.

@RichardL64
Copy link
Owner

RichardL64 commented Nov 17, 2022 via email

@PhillyGilly
Copy link
Author

Mixed result.....
image

It looks like enabling the inverter gets it to draw 60 W when the inverter isn't generating (that's the drop off in the raw purple line). It could be a bit less as my Arduino CT doesn't know about the power factor, but I can't match it exactly to the smart meter out put as both are on 10sec samples but not aligned.

So enabling the inverter overnight could use up to 1kWh which is the opposite of what I want to achieve.

I'll get the basic 485 working next week and then devise a strategy to deal with the inverter going to sleep...

@PhillyGilly
Copy link
Author

I had the rx-tx wires crossed. Here is my revised Fritzing sketch.
image
The example is running although I am having to offset the address by one, which I don't know if you are doing.

@RichardL64
Copy link
Owner

RichardL64 commented Nov 20, 2022 via email

@PhillyGilly
Copy link
Author

Hi @RichardL64, I thought I'd give you a quick update:

  1. Up and running!
    image
  2. In the end my code isn't that similar to yours, because:
    a) I'm not a very good coder, and b) the arduino just posts out the modbus data by mqtt as soon as it reads it, so there isn't any need to hold it locally. I just keep it in global variables.
  3. If your interested I can share it with you via Github. I haven't really tried to make the functions efficient as I don't need to, so I'm not going to hold it up as an example of how to do it.
  4. My inverter S6 uses different modbus addresses from your hybrid inverter. So if I want to know what is at address 3000, I have to interrogate address 2999. This is what I meant by offsetting the address.
  5. I solved the "inverter asleep at night" problem by working on the idea that if the modbus stopped communicating it meant the inverter had powered down. When that is detected "dynamic" values are set to 0 and "integrated" values are set to their last known value. That seems to placate my Home Assistant.
  6. As the arduino is in my loft next to the inverter which is five flights of stairs up from my office, so I use OTA and don't bother with any serial print for error traps. If I do want to know what's happening, I publish a mqtt message.
  7. I still need to work out how to write into the modbus time registers as I need to synchronise times so that "daily" values are for the same 24hrs. I have no idea how to take the time values as strings and convert the right bits into unsigned-16 but I'm sure that somebody somewhere has cracked it already.
    Cheers and thank you!

@RichardL64
Copy link
Owner

RichardL64 commented Nov 26, 2022 via email

@PhillyGilly
Copy link
Author

Here is my first attempt at a repository
https://github.com/PhillyGilly/SolarisS6ArduinoMqtt
I am going to have to work on formatting my reade.md and adding pictures.

OTA is part of #include <ArduinoOTA.h>
It's really simple and works well on the IDE v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants