This is how to power the Victron Lynx distributor and how to read the fuses states with an esp32 d2 mini (just a few euros via AliExpress) and esphome:
#include "esphome.h"
// https://diysolarforum.com/threads/anyone-connected-a-lynx-distributor-directly-to-a-rpi-yet.30173/#post-1182368
// The red wire from the RJ10 is SCL, the green one is SDA.
// One needs pull up resistors on the bus.
// The Distributors are I2C slaves.
// The dip switch vary the I2C device address.
// A is 0x08, B is 0x09, C is 0x0a and D is 0x0b.
// When reading one of the connected Distributor I2C devices they return the fuse states encoded in a byte.
// Left fuse (in regular mounting position) is fuse 1.
// Then from left to right: fuse 1=0x10, fuse 2=0x20, fuse 3=0x40, fuse 4=0x80.
// An existing fuse is represented by 0. Any missing or blown fuse is represented by 1.
// So if all 4 fuses are existing and ok then the Distributor returns 0x00.
// If e.g. fuse 1 and 4 are missing, then it would return 0x60.
// If all fuses are missing it is 0xf0.
class LynxSensor : public PollingComponent {
private:
int _address;
public:
BinarySensor *fuse1 = new BinarySensor();
BinarySensor *fuse2 = new BinarySensor();
BinarySensor *fuse3 = new BinarySensor();
BinarySensor *fuse4 = new BinarySensor();
LynxSensor(int address) : PollingComponent(60 * 1000) {
_address = address;
}
void setup() override {
ESP_LOGI("lynx", "Setup");
Wire.begin();
}
void update() override {
byte count = Wire.requestFrom(_address, 1);
if (count == 1) {
byte data = Wire.read();
ESP_LOGI("lynx", "Read %x=%x", _address, data);
fuse1->publish_state((data & 0x10) != 0); // left
fuse2->publish_state((data & 0x20) != 0);
fuse3->publish_state((data & 0x40) != 0);
fuse4->publish_state((data & 0x80) != 0); // right
} else {
ESP_LOGE("lynx", "Read %x failed bytes=%d", _address, count);
}
}
};
LynxSensor *lynx_fuses;
Peak power usage seems to be < 200 mA. The esp32 can draw some power to scan for Wi-Fi networks, so better provide something like 1A.
I’m using this connected to the busbar of the distributor, bought via Amazon, but a decent USB power adapter will do too:
Yes, that’s possible by connecting the lynx distributors with each other (up to 4) using the included RJ10 cable and configuring different addresses with the dip switches. The source code needs to be changed for this as well, but that’s not too difficult.
Nice work!
Hope you won’t mind me for hijacking your topic, but here is another user that managed to do the same and also stored the read values into dbus, in order to have the Lynx distributor and its fuses statuses on Cerbo.
Maybe you exchange experiences.
A driver is needed to store the values to dbus. It is possible, but less trivial because it requires software to be installed on the Cerbo to register the distributor(s) as devices (batteries in fact). esphone could publish values via mqtt after the distributor has been registered.
Please see below for the source code to check four Lynx distributors.
I can test one only, but I see no reasons why it wouldn’t work for four.
The power usage might be a bit more, so take care of a proper adapter/converter.
Note that the DIP switches should be used to give each distributor its own address.
#include "esphome.h"
// https://diysolarforum.com/threads/anyone-connected-a-lynx-distributor-directly-to-a-rpi-yet.30173/#post-1182368
// The red wire from the RJ10 is SCL, the green one is SDA.
// One needs pull up resistors on the bus.
// The Distributors are I2C slaves.
// The dip switch vary the I2C device address.
// A is 0x08, B is 0x09, C is 0x0a and D is 0x0b.
// When reading one of the connected Distributor I2C devices they return the fuse states encoded in a byte.
// Left fuse (in regular mounting position) is fuse 1.
// Then from left to right: fuse 1=0x10, fuse 2=0x20, fuse 3=0x40, fuse 4=0x80.
// An existing fuse is represented by 0. Any missing or blown fuse is represented by 1.
// So if all 4 fuses are existing and ok then the Distributor returns 0x00.
// If e.g. fuse 1 and 4 are missing, then it would return 0x60.
// If all fuses are missing it is 0xf0.
class LynxSensor : public PollingComponent {
private:
int _address;
public:
BinarySensor *fuse1 = new BinarySensor();
BinarySensor *fuse2 = new BinarySensor();
BinarySensor *fuse3 = new BinarySensor();
BinarySensor *fuse4 = new BinarySensor();
LynxSensor(int address) : PollingComponent(60 * 1000) {
_address = address;
}
void setup() override {
ESP_LOGI("lynx", "Setup");
Wire.begin();
}
void update() override {
byte count = Wire.requestFrom(_address, 1);
if (count == 1) {
byte data = Wire.read();
ESP_LOGI("lynx", "Read %x=%x", _address, data);
fuse1->publish_state((data & 0x10) != 0); // left
fuse2->publish_state((data & 0x20) != 0);
fuse3->publish_state((data & 0x40) != 0);
fuse4->publish_state((data & 0x80) != 0); // right
} else {
ESP_LOGE("lynx", "Read %x failed bytes=%d", _address, count);
}
}
};
LynxSensor *lynx_fuses[4];
Indeed, but I’ve asked, if possible, for those components definitions.
For example, BinarySensor is a class somewhere, right?
Because later there is a function called from that class (publish_state)…
Thanks!
thank you both for now its the Home Assistant element im trying to move everything to that platform so all of my house is all in one and just have the specific app’s / interfaces if i need to drill down on issues @m66b@alexpescaru thanks